diff --git a/packages/nc-gui/components/smartsheet/form/field-settings/visibility.vue b/packages/nc-gui/components/smartsheet/form/field-settings/visibility.vue index c162f83e93..b6e295224e 100644 --- a/packages/nc-gui/components/smartsheet/form/field-settings/visibility.vue +++ b/packages/nc-gui/components/smartsheet/form/field-settings/visibility.vue @@ -16,11 +16,11 @@ const visibilityError = computed(() => { const hasvisibilityError = computed(() => Object.keys(visibilityError.value).length) const visibilityFilters = computed(() => { - if (!allViewFilters.value[activeField.value?.fk_column_id]) { - allViewFilters.value[activeField.value!.fk_column_id] = [] + if (activeField.value?.fk_column_id && !allViewFilters.value[activeField.value.fk_column_id]) { + allViewFilters.value[activeField.value.fk_column_id] = [] } - return allViewFilters.value[activeField.value!.fk_column_id] + return allViewFilters.value[`${activeField.value?.fk_column_id}`] }) const isFirstField = computed(() => { @@ -29,7 +29,7 @@ const isFirstField = computed(() => { const filterOption = (column: ColumnType) => { // hide active field from filter option - const isNotActiveField = column.id !== activeField.value!.fk_column_id + const isNotActiveField = column.id !== activeField.value?.fk_column_id // show only form view visible columns and order is less than active field const orderIsLessThanActiveField = diff --git a/packages/nc-gui/composables/useFormViewStore.ts b/packages/nc-gui/composables/useFormViewStore.ts index 09bbf9c92e..81848c77f0 100644 --- a/packages/nc-gui/composables/useFormViewStore.ts +++ b/packages/nc-gui/composables/useFormViewStore.ts @@ -204,16 +204,19 @@ const [useProvideFormViewStore, useFormViewStore] = useInjectionState( const loadAllviewFilters = async () => { if (!viewMeta.value?.id) return + try { + const formViewFilters = (await $api.dbTableFilter.read(viewMeta.value.id, { includeAllFilters: true })).list || [] - const formViewFilters = (await $api.dbTableFilter.read(viewMeta.value.id, { includeAllFilters: true })).list || [] - - if (!formViewFilters.length) return + if (!formViewFilters.length) return - const formFilter = new FormFilters({ data: formViewFilters }) + const formFilter = new FormFilters({ data: formViewFilters }) - const allFilters = formFilter.getNestedGroupedFilters() + const allFilters = formFilter.getNestedGroupedFilters() - allViewFilters.value = { ...allFilters } + allViewFilters.value = { ...allFilters } + } catch (e: any) { + console.error('Error loading view filters:', e) + } } async function checkFieldVisibility() { diff --git a/packages/nc-gui/lib/form.ts b/packages/nc-gui/lib/form.ts index fe3fd2819a..ebce1cf72c 100644 --- a/packages/nc-gui/lib/form.ts +++ b/packages/nc-gui/lib/form.ts @@ -84,7 +84,7 @@ export class FormFilters { // Method to group filters by fk_parent_column_id getNestedGroupedFilters() { - const groupedFiltes = this.allViewFilters.reduce((acc, filter) => { + const groupedFilters = this.allViewFilters.reduce((acc, filter) => { const groupingKey = filter.fk_parent_column_id || 'ungrouped' if (!acc[groupingKey]) { @@ -96,7 +96,7 @@ export class FormFilters { return acc }, {} as typeof this.groupedFilters) - this.groupedFilters = groupedFiltes + this.groupedFilters = groupedFilters const nestedGroupedFilters = this.loadFilters() @@ -313,7 +313,7 @@ export class FormFilters { val = !!this.formState[field] break case 'number': - val = isNaN(parseFloat(this.formState[field])) ? this.formState[field] : +this.formState[field] + val = Number.isNaN(parseFloat(this.formState[field])) ? this.formState[field] : +this.formState[field] break } @@ -340,10 +340,10 @@ export class FormFilters { res = val != filter.value break case 'like': - res = this.toString(val).toLowerCase()?.indexOf(filter.value?.toLowerCase()) > -1 + res = this.toString(val).toLowerCase()?.includes(filter.value?.toLowerCase()) break case 'nlike': - res = this.toString(val).toLowerCase()?.indexOf(filter.value?.toLowerCase()) === -1 + res = !this.toString(val).toLowerCase()?.includes(filter.value?.toLowerCase()) break case 'empty': case 'blank': @@ -360,7 +360,7 @@ export class FormFilters { res = !val break case 'null': - res = res = val === null + res = val === null break case 'notnull': res = val !== null