diff --git a/packages/nc-gui-v2/components.d.ts b/packages/nc-gui-v2/components.d.ts index fabc254fa9..24c1af83d8 100644 --- a/packages/nc-gui-v2/components.d.ts +++ b/packages/nc-gui-v2/components.d.ts @@ -103,6 +103,7 @@ declare module '@vue/runtime-core' { MdiCheck: typeof import('~icons/mdi/check')['default'] MdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] MdiClose: typeof import('~icons/mdi/close')['default'] + MdiCloseBox: typeof import('~icons/mdi/close-box')['default'] MdiCloseCircle: typeof import('~icons/mdi/close-circle')['default'] MdiCloseThick: typeof import('~icons/mdi/close-thick')['default'] MdiCodeJson: typeof import('~icons/mdi/code-json')['default'] diff --git a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue index 09231feb10..a7e38d73f8 100644 --- a/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue +++ b/packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilter.vue @@ -2,31 +2,42 @@ import type { FilterType } from 'nocodb-sdk' import { UITypes } from 'nocodb-sdk' import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue' -import { useNuxtApp } from '#app' -import { inject, useViewFilters } from '#imports' -import { comparisonOpList } from '~/utils/filterUtils' -import { ActiveViewInj, MetaInj, ReloadViewDataHookInj } from '~/context' -import MdiDeleteIcon from '~icons/mdi/close-box' -import MdiAddIcon from '~icons/mdi/plus' -import type { Filter } from '~/lib/types' - -const { - nested = false, - parentId, - autoSave = true, - hookId = null, - modelValue, -} = defineProps<{ nested?: boolean; parentId?: string; autoSave: boolean; hookId?: string; modelValue?: Filter[] }>() +import { + ActiveViewInj, + MetaInj, + ReloadViewDataHookInj, + comparisonOpList, + computed, + inject, + ref, + useNuxtApp, + useViewFilters, + watch, +} from '#imports' +import type { Filter } from '~/lib' + +interface Props { + nested?: boolean + parentId?: string + autoSave: boolean + hookId?: string + modelValue?: Filter[] +} + +const { nested = false, parentId, autoSave = true, hookId = null, modelValue } = defineProps() const emit = defineEmits(['update:filtersLength']) -const meta = inject(MetaInj) +const logicalOps = [ + { value: 'and', text: 'AND' }, + { value: 'or', text: 'OR' }, +] -const activeView = inject(ActiveViewInj) +const meta = inject(MetaInj)! -const reloadDataHook = inject(ReloadViewDataHookInj) +const activeView = inject(ActiveViewInj)! -// todo: replace with inject or get from state +const reloadDataHook = inject(ReloadViewDataHookInj)! const { $e } = useNuxtApp() @@ -35,11 +46,13 @@ const { filters, deleteFilter, saveOrUpdate, loadFilters, addFilter, addFilterGr parentId, computed(() => autoSave), () => { - reloadDataHook?.trigger() + reloadDataHook.trigger() }, modelValue, ) +const nestedFilters = ref() + const filterUpdateCondition = (filter: FilterType, i: number) => { saveOrUpdate(filter, i) $e('a:filter:update', { @@ -63,12 +76,14 @@ const filterUpdateCondition = (filter: FilterType, i: number) => { // return true // }) -const columns = computed(() => meta?.value?.columns) +const columns = computed(() => meta.value?.columns) + const types = computed(() => { - if (!meta?.value?.columns?.length) { + if (!meta.value?.columns?.length) { return {} } - return meta?.value?.columns?.reduce((obj: any, col: any) => { + + return meta.value?.columns?.reduce((obj: any, col: any) => { switch (col.uidt) { case UITypes.Number: case UITypes.Decimal: @@ -83,22 +98,15 @@ const types = computed(() => { }) watch( - () => (activeView?.value as any)?.id, + () => activeView.value?.id, (n, o) => { if (n !== o) loadFilters(hookId as string) }, { immediate: true }, ) -const nestedFilters = ref() - -const logicalOps = [ - { value: 'and', text: 'AND' }, - { value: 'or', text: 'OR' }, -] - watch( - () => filters?.value?.length, + () => filters.value.length, (length) => { emit('update:filtersLength', length ?? 0) }, @@ -106,7 +114,10 @@ watch( const applyChanges = async (hookId?: string) => { await sync(hookId) - for (const nestedFilter of nestedFilters?.value || []) { + + if (!nestedFilters.value.length) return + + for (const nestedFilter of nestedFilters.value) { if (nestedFilter.parentId) { await nestedFilter.applyChanges(hookId, true) } @@ -128,7 +139,7 @@ defineExpose({