Skip to content

Commit

Permalink
fix(ktabledata): improve types
Browse files Browse the repository at this point in the history
  • Loading branch information
Justineo committed Dec 30, 2024
1 parent 071b3df commit f16a100
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/components/KTableData/KTableData.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,28 @@ const tablePaginationAttributes = computed((): TablePaginationAttributes => ({
offsetNextButtonDisabled: !nextOffset.value || !hasNextPage.value,
}))
function isTableColumnSlotName(slot: string): slot is TableColumnSlotName {
return slot.startsWith('column-')
}
function isTableColumnTooltipSlotName(slot: string): slot is TableColumnTooltipSlotName {
return slot.startsWith('tooltip-')
}
const getHeaderSlots = computed((): TableColumnSlotName[] => {
if (!slots) {
return []
}
return Object.keys(slots).filter((slot) => slot.startsWith('column-')) as TableColumnSlotName[]
return Object.keys(slots).filter(isTableColumnSlotName)
})
const getHeaderTooltipSlots = computed((): TableColumnTooltipSlotName[] => {
if (!slots) {
return []
}
return Object.keys(slots).filter((slot) => slot.startsWith('tooltip-')) as TableColumnTooltipSlotName[]
return Object.keys(slots).filter(isTableColumnTooltipSlotName)
})
const getCellSlots = computed((): string[] => {
Expand All @@ -311,7 +319,6 @@ const fetcherParams = computed(() => ({
const isInitialFetch = ref<boolean>(true)
const fetchData = async () => {
// @ts-ignore - fetcher is required and will always be defined
const res = await props.fetcher(fetcherParams.value)
isInitialFetch.value = false
Expand Down Expand Up @@ -397,7 +404,7 @@ const {
const { state, hasData } = useSwrvState(fetcherData, fetcherError, fetcherIsValidating)
const stateData = computed((): SwrvStateData => ({
hasData: hasData.value,
state: state.value as SwrvState,
state: state.value,
}))
const tableState = computed((): TableState => fetcherIsLoading.value ? 'loading' : fetcherError.value ? 'error' : 'success')
const { debouncedFn: debouncedRevalidate } = useDebounce(_revalidate, 500)
Expand Down
5 changes: 3 additions & 2 deletions src/composables/useUtilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { IConfig } from 'swrv'
import useSWRV from 'swrv'
import type { AxiosResponse, AxiosError } from 'axios'
import type { IKey, fetcherFn } from 'swrv/dist/types'
import type { SwrvState } from '@/types'

const swrvState = {
VALIDATING: 'VALIDATING',
Expand All @@ -13,7 +14,7 @@ const swrvState = {
SUCCESS_HAS_DATA: 'SUCCESS_HAS_DATA',
ERROR: 'ERROR',
STALE_IF_ERROR: 'STALE_IF_ERROR',
}
} as const satisfies Record<string, SwrvState>

export default function useUtilities() {
const useRequest = <Data = unknown, Error = { message: string }>(
Expand Down Expand Up @@ -155,7 +156,7 @@ export default function useUtilities() {
}

const useSwrvState = (response: Ref<any>, error: Ref<any>, isValidating: Ref<boolean>) => {
const state = ref(swrvState.PENDING)
const state = ref<SwrvState>(swrvState.PENDING)
const hasData = ref(false)

watchEffect(() => {
Expand Down

0 comments on commit f16a100

Please sign in to comment.