Skip to content

Commit

Permalink
fix: nested webhook filter related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavxc committed May 15, 2024
1 parent 6a7127d commit f65ac8d
Show file tree
Hide file tree
Showing 4 changed files with 259 additions and 236 deletions.
27 changes: 21 additions & 6 deletions packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Props {
webHook?: boolean
draftFilter?: Partial<FilterType>
}
const props = withDefaults(defineProps<Props>(), {
nestedLevel: 0,
autoSave: true,
Expand All @@ -21,13 +22,14 @@ const props = withDefaults(defineProps<Props>(), {
webHook: false,
})
const emit = defineEmits(['update:filtersLength', 'update:draftFilter'])
const emit = defineEmits(['update:filtersLength', 'update:draftFilter', 'update:modelValue'])
const excludedFilterColUidt = [UITypes.QrCode, UITypes.Barcode]
const draftFilter = useVModel(props, 'draftFilter', emit)
const modelValue = useVModel(props, 'modelValue', emit)
const { nestedLevel, parentId, autoSave, hookId, modelValue, showLoading, webHook } = toRefs(props)
const { nestedLevel, parentId, autoSave, hookId, showLoading, webHook } = toRefs(props)
const nested = computed(() => nestedLevel.value > 0)
Expand Down Expand Up @@ -66,7 +68,7 @@ const {
types,
} = useViewFilters(
activeView,
parentId?.value,
parentId,
computed(() => autoSave.value),
() => reloadDataHook.trigger({ shouldShowLoading: showLoading.value, offset: 0 }),
modelValue.value || nestedFilters.value,
Expand Down Expand Up @@ -204,8 +206,10 @@ const applyChanges = async (hookId?: string, nested = false, isConditionSupporte
if (!localNestedFilters.value?.length) return
await nextTick()
for (const nestedFilter of localNestedFilters.value) {
if (nestedFilter.parentId) {
if (nestedFilter.parentId?.value) {
await nestedFilter.applyChanges(hookId, true)
}
}
Expand Down Expand Up @@ -250,7 +254,7 @@ const updateFilterValue = (value: string, filter: Filter, index: number) => {
defineExpose({
applyChanges,
parentId: parentId?.value,
parentId,
})
const scrollToBottom = () => {
Expand Down Expand Up @@ -373,6 +377,17 @@ const onLogicalOpUpdate = async (filter: Filter, index: number) => {
}
await saveOrUpdate(filter, index)
}
// watch for changes in filters and update the modelValue
watch(
filters,
() => {
if (modelValue.value !== filters.value) modelValue.value = filters.value
},
{
immediate: true,
},
)
</script>

<template>
Expand Down Expand Up @@ -436,7 +451,7 @@ const onLogicalOpUpdate = async (filter: Filter, index: number) => {
</div>
<div class="flex border-1 rounded-lg p-2 w-full" :class="nestedLevel % 2 !== 0 ? 'bg-white' : 'bg-gray-100'">
<LazySmartsheetToolbarColumnFilter
v-if="filter.id || filter.children"
v-if="filter.id || filter.children || !autoSave"
:key="filter.id ?? i"
ref="localNestedFilters"
v-model="filter.children"
Expand Down
26 changes: 15 additions & 11 deletions packages/nc-gui/composables/useViewFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { UITypes, isSystemColumn } from 'nocodb-sdk'

export function useViewFilters(
view: Ref<ViewType | undefined>,
parentId?: string,
parentId: Ref<string | null>,
autoApply?: ComputedRef<boolean>,
reloadData?: () => void,
_currentFilters?: Filter[],
Expand Down Expand Up @@ -240,14 +240,14 @@ export function useViewFilters(

try {
if (isWebhook || hookId) {
if (parentId) {
filters.value = (await $api.dbTableFilter.childrenRead(parentId)).list as Filter[]
if (parentId.value) {
filters.value = (await $api.dbTableFilter.childrenRead(parentId.value)).list as Filter[]
} else if (hookId) {
filters.value = (await $api.dbTableWebhookFilter.read(hookId)).list as Filter[]
}
} else {
if (parentId) {
filters.value = (await $api.dbTableFilter.childrenRead(parentId)).list as Filter[]
if (parentId.value) {
filters.value = (await $api.dbTableFilter.childrenRead(parentId.value)).list as Filter[]
} else {
filters.value = (await $api.dbTableFilter.read(view.value!.id!)).list as Filter[]
if (loadAllFilters) {
Expand Down Expand Up @@ -275,21 +275,25 @@ export function useViewFilters(
} else if (filter.status === 'update') {
await $api.dbTableFilter.update(filter.id as string, {
...filter,
fk_parent_id: parentId,
fk_parent_id: parentId.value,
})
} else if (filter.status === 'create') {
// extract children value if found to restore
const children = filters.value[+i]?.children
if (hookId) {
filters.value[+i] = (await $api.dbTableWebhookFilter.create(hookId, {
...filter,
fk_parent_id: parentId,
fk_parent_id: parentId.value,
})) as unknown as FilterType
} else {
filters.value[+i] = await $api.dbTableFilter.create(view?.value?.id as string, {
...filter,
fk_parent_id: parentId,
fk_parent_id: parentId.value,
})
}

if (children) filters.value[+i].children = children

allFilters.value.push(filters.value[+i])
}
}
Expand Down Expand Up @@ -345,7 +349,7 @@ export function useViewFilters(
} else if (filter.id && filter.status !== 'create') {
await $api.dbTableFilter.update(filter.id, {
...filter,
fk_parent_id: parentId,
fk_parent_id: parentId.value,
})
$e('a:filter:update', {
logical: filter.logical_op,
Expand All @@ -354,7 +358,7 @@ export function useViewFilters(
} else {
filters.value[i] = await $api.dbTableFilter.create(view.value.id!, {
...filter,
fk_parent_id: parentId,
fk_parent_id: parentId.value,
})

allFilters.value.push(filters.value[+i])
Expand Down Expand Up @@ -482,7 +486,7 @@ export function useViewFilters(

const index = filters.value.length - 1

await saveOrUpdate(filters.value[index], index, true)
await saveOrUpdate(filters.value[index], index)

lastFilters.value = clone(filters.value)

Expand Down
Loading

0 comments on commit f65ac8d

Please sign in to comment.