@prefecthq/prefect-ui-library
Version:
This library is the Vue and Typescript component library for [Prefect 2](https://github.com/PrefectHQ/prefect) and [Prefect Cloud 2](https://www.prefect.io/cloud/). _The components and utilities in this project are not meant to be used independently_.
34 lines (27 loc) • 769 B
text/typescript
import { useLocalStorage } from '@prefecthq/vue-compositions'
import { Ref, computed } from 'vue'
import { LogSortValues, isLogSortValue } from '@/types'
import { getCacheKey } from '@/utilities/cache'
type UseLogsSort = {
sort: Ref<LogSortValues>,
}
const logsSortStorageKey = getCacheKey('prefect-ui-library-default-logs-sort')
export function useLogsSort(defaultValue: LogSortValues = 'TIMESTAMP_ASC'): UseLogsSort {
const { value: cache, set } = useLocalStorage<string>(logsSortStorageKey)
const sort = computed({
get() {
if (isLogSortValue(cache.value)) {
return cache.value
}
return defaultValue
},
set(value) {
if (isLogSortValue(value)) {
set(value)
}
},
})
return {
sort,
}
}