|
|
|
@ -1,17 +1,6 @@
|
|
|
|
|
import type { ViewType } from 'nocodb-sdk' |
|
|
|
|
import type { ComputedRef, Ref } from 'vue' |
|
|
|
|
import { |
|
|
|
|
IsPublicInj, |
|
|
|
|
ReloadViewDataHookInj, |
|
|
|
|
computed, |
|
|
|
|
inject, |
|
|
|
|
ref, |
|
|
|
|
useMetas, |
|
|
|
|
useNuxtApp, |
|
|
|
|
useSharedView, |
|
|
|
|
useUIPermission, |
|
|
|
|
watch, |
|
|
|
|
} from '#imports' |
|
|
|
|
import { IsPublicInj, ReloadViewDataHookInj, computed, inject, ref, useMetas, useNuxtApp, useUIPermission, watch } from '#imports' |
|
|
|
|
import type { Filter } from '~/lib' |
|
|
|
|
|
|
|
|
|
export function useViewFilters( |
|
|
|
@ -19,13 +8,12 @@ export function useViewFilters(
|
|
|
|
|
parentId?: string, |
|
|
|
|
autoApply?: ComputedRef<boolean>, |
|
|
|
|
reloadData?: () => void, |
|
|
|
|
siblingFilters?: Filter[], |
|
|
|
|
currentFilters?: Filter[], |
|
|
|
|
isNestedRoot?: boolean, |
|
|
|
|
) { |
|
|
|
|
const { nestedFilters } = useSharedView() |
|
|
|
|
|
|
|
|
|
const reloadHook = inject(ReloadViewDataHookInj) |
|
|
|
|
|
|
|
|
|
const _filters = ref<Filter[]>([]) |
|
|
|
|
const { nestedFilters } = useSmartsheetStoreOrThrow() |
|
|
|
|
|
|
|
|
|
const isPublic = inject(IsPublicInj, ref(false)) |
|
|
|
|
|
|
|
|
@ -34,21 +22,23 @@ export function useViewFilters(
|
|
|
|
|
const { isUIAllowed } = useUIPermission() |
|
|
|
|
|
|
|
|
|
const { metas } = useMetas() |
|
|
|
|
const _filters = ref<Filter[]>([]) |
|
|
|
|
|
|
|
|
|
const nestedMode = computed(() => isPublic.value || !isUIAllowed('filterSync' || !isUIAllowed('filterChildrenRead'))) |
|
|
|
|
|
|
|
|
|
const filters = computed<Filter[]>({ |
|
|
|
|
get: () => (nestedMode.value ? currentFilters! : _filters.value), |
|
|
|
|
set: (value: Filter[]) => { |
|
|
|
|
if (nestedMode.value) { |
|
|
|
|
currentFilters = value |
|
|
|
|
if (isNestedRoot) nestedFilters.value = value |
|
|
|
|
|
|
|
|
|
const filters = computed({ |
|
|
|
|
get: () => (isPublic.value ? siblingFilters || nestedFilters.value : _filters.value) ?? [], |
|
|
|
|
set: (value) => { |
|
|
|
|
if (isPublic.value) { |
|
|
|
|
if (siblingFilters) { |
|
|
|
|
siblingFilters = value |
|
|
|
|
} else { |
|
|
|
|
nestedFilters.value = value |
|
|
|
|
} |
|
|
|
|
nestedFilters.value = [...nestedFilters.value] |
|
|
|
|
reloadHook?.trigger() |
|
|
|
|
} else { |
|
|
|
|
_filters.value = value |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_filters.value = value |
|
|
|
|
}, |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
@ -60,6 +50,9 @@ export function useViewFilters(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const loadFilters = async (hookId?: string) => { |
|
|
|
|
if (nestedMode.value) return |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (hookId) { |
|
|
|
|
if (parentId) { |
|
|
|
|
filters.value = await $api.dbTableFilter.childrenRead(parentId) |
|
|
|
@ -73,6 +66,9 @@ export function useViewFilters(
|
|
|
|
|
filters.value = await $api.dbTableFilter.read(view?.value?.id as string) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} catch (e) { |
|
|
|
|
console.log(e) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const sync = async (hookId?: string, _nested = false) => { |
|
|
|
@ -104,7 +100,7 @@ export function useViewFilters(
|
|
|
|
|
|
|
|
|
|
const deleteFilter = async (filter: Filter, i: number) => { |
|
|
|
|
// if shared or sync permission not allowed simply remove it from array
|
|
|
|
|
if (isPublic.value || !isUIAllowed('filterSync')) { |
|
|
|
|
if (nestedMode.value) { |
|
|
|
|
filters.value.splice(i, 1) |
|
|
|
|
|
|
|
|
|
reloadData?.() |
|
|
|
@ -129,17 +125,11 @@ export function useViewFilters(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveOrUpdate = async (filter: Filter, i: number, force = false) => { |
|
|
|
|
if (isPublic.value) { |
|
|
|
|
filters.value[i] = { ...filter } |
|
|
|
|
|
|
|
|
|
filters.value = [...filters.value] |
|
|
|
|
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (!view?.value) return |
|
|
|
|
|
|
|
|
|
if (!isUIAllowed('filterSync')) { |
|
|
|
|
// skip
|
|
|
|
|
if (nestedMode.value) { |
|
|
|
|
filters.value[i] = { ...filter } |
|
|
|
|
filters.value = [...filters.value] |
|
|
|
|
} else if (!autoApply?.value && !force) { |
|
|
|
|
filter.status = filter.id ? 'update' : 'create' |
|
|
|
|
} else if (filter.id) { |
|
|
|
@ -168,7 +158,7 @@ export function useViewFilters(
|
|
|
|
|
logical_op: 'and', |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (isPublic.value) placeHolderGroupFilter.children = [child] |
|
|
|
|
if (nestedMode.value) placeHolderGroupFilter.children = [child] |
|
|
|
|
|
|
|
|
|
filters.value.push(placeHolderGroupFilter) |
|
|
|
|
|
|
|
|
|