Browse Source

feat(gui-v2): integrate hook logic in filter

pull/3129/head
Wing-Kam Wong 2 years ago
parent
commit
f7691e3584
  1. 17
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue
  2. 19
      packages/nc-gui-v2/composables/useViewFilters.ts

17
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue

@ -9,12 +9,19 @@ import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context'
import MdiDeleteIcon from '~icons/mdi/close-box'
import MdiAddIcon from '~icons/mdi/plus'
const { nested = false, parentId, autoSave = true } = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean }>()
const {
nested = false,
parentId,
autoSave = true,
hookId = null,
} = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean; hookId?: string }>()
const emit = defineEmits(['update:filtersLength'])
const meta = inject(MetaInj)
const activeView = inject(ActiveViewInj)
const reloadDataHook = inject(ReloadViewDataHookInj)
// todo: replace with inject or get from state
@ -76,7 +83,7 @@ const types = computed(() => {
watch(
() => (activeView?.value as any)?.id,
(n, o) => {
if (n !== o) loadFilters()
if (n !== o) loadFilters(hookId as string)
},
{ immediate: true },
)
@ -95,11 +102,11 @@ watch(
},
)
const applyChanges = async () => {
await sync()
const applyChanges = async (hookId?: string) => {
await sync(hookId)
for (const nestedFilter of nestedFilters?.value || []) {
if (nestedFilter.parentId) {
await nestedFilter.applyChanges(true)
await nestedFilter.applyChanges(hookId, true)
}
}
}

19
packages/nc-gui-v2/composables/useViewFilters.ts

@ -16,15 +16,23 @@ export function useViewFilters(
const { isUIAllowed } = useUIPermission()
const { metas } = useMetas()
const loadFilters = async () => {
const loadFilters = async (hookId?: string) => {
if (hookId) {
if (parentId) {
filters.value = await $api.dbTableFilter.childrenRead(parentId)
} else {
filters.value = (await $api.dbTableWebhookFilter.read(hookId as string)) as any
}
} else {
if (parentId) {
filters.value = await $api.dbTableFilter.childrenRead(parentId)
} else {
filters.value = await $api.dbTableFilter.read(view?.value?.id as string)
}
}
}
const sync = async (_nested = false) => {
const sync = async (hookId?: string, _nested = false) => {
for (const [i, filter] of Object.entries(filters.value)) {
if (filter.status === 'delete') {
await $api.dbTableFilter.delete(filter.id as string)
@ -34,12 +42,19 @@ export function useViewFilters(
fk_parent_id: parentId,
})
} else if (filter.status === 'create') {
if (hookId) {
filters.value[+i] = (await $api.dbTableWebhookFilter.create(hookId, {
...filter,
fk_parent_id: parentId,
})) as any
} else {
filters.value[+i] = (await $api.dbTableFilter.create(view?.value?.id as string, {
...filter,
fk_parent_id: parentId,
})) as any
}
}
}
reloadData?.()
}

Loading…
Cancel
Save