|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import type { FilterType, GalleryType, GridType, KanbanType } from 'nocodb-sdk' |
|
|
|
|
import type { FilterType, ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
|
import { useNuxtApp, useUIPermission } from '#imports' |
|
|
|
|
import { useMetas } from '~/composables/useMetas' |
|
|
|
|
|
|
|
|
|
export function useViewFilters( |
|
|
|
|
view: Ref<(GridType | KanbanType | GalleryType) & { id?: string }> | undefined, |
|
|
|
|
view: Ref<ViewType> | undefined, |
|
|
|
|
parentId?: string, |
|
|
|
|
autoApply?: ComputedRef<boolean>, |
|
|
|
|
reloadData?: () => void, |
|
|
|
@ -14,6 +15,7 @@ export function useViewFilters(
|
|
|
|
|
|
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
|
const { metas } = useMetas() |
|
|
|
|
|
|
|
|
|
const loadFilters = async () => { |
|
|
|
|
if (parentId) { |
|
|
|
@ -106,5 +108,21 @@ export function useViewFilters(
|
|
|
|
|
await saveOrUpdate(filters.value[index], index, true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** on column delete reload filters, identify by checking columns count */ |
|
|
|
|
watch( |
|
|
|
|
() => { |
|
|
|
|
if (!view?.value || !metas?.value?.[view?.value?.fk_model_id as string]) { |
|
|
|
|
return 0 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return metas?.value?.[view?.value?.fk_model_id as string]?.columns?.length || 0 |
|
|
|
|
}, |
|
|
|
|
async (nextColsLength, oldColsLength) => { |
|
|
|
|
if (nextColsLength < oldColsLength) { |
|
|
|
|
await loadFilters() |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup } |
|
|
|
|
} |
|
|
|
|