From 7877c97d8d8bd9e7c67f1e2777ec086dccd04f1c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Wed, 22 Feb 2023 19:43:50 +0800 Subject: [PATCH] feat(nc-gui): add comparisonSubOpList --- .../smartsheet/toolbar/ColumnFilter.vue | 41 +++++++++++++++++-- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue index 095e816510..2d9495ea82 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue @@ -6,6 +6,7 @@ import { MetaInj, ReloadViewDataHookInj, comparisonOpList, + comparisonSubOpList, computed, inject, ref, @@ -54,6 +55,7 @@ const { sync, saveOrUpdateDebounced, isComparisonOpAllowed, + isComparisonSubOpAllowed, } = useViewFilters( activeView, parentId, @@ -75,9 +77,10 @@ const filterPrevComparisonOp = ref>({}) const filterUpdateCondition = (filter: FilterType, i: number) => { const col = getColumn(filter) + if (!col) return if ( col.uidt === UITypes.SingleSelect && - ['anyof', 'nanyof'].includes(filterPrevComparisonOp.value[filter.id]) && + ['anyof', 'nanyof'].includes(filterPrevComparisonOp.value[filter.id!]) && ['eq', 'neq'].includes(filter.comparison_op!) ) { // anyof and nanyof can allow multiple selections, @@ -93,6 +96,7 @@ const filterUpdateCondition = (filter: FilterType, i: number) => { $e('a:filter:update', { logical: filter.logical_op, comparison: filter.comparison_op, + comparison_sub_op: filter.comparison_sub_op, }) } @@ -109,7 +113,7 @@ const types = computed(() => { watch( () => activeView.value?.id, - (n: string, o: string) => { + (n, o) => { // if nested no need to reload since it will get reloaded from parent if (!nested && n !== o && (hookId || !webHook)) loadFilters(hookId as string) }, @@ -137,14 +141,21 @@ const applyChanges = async (hookId?: string, _nested = false) => { } const selectFilterField = (filter: Filter, index: number) => { + const col = getColumn(filter) + if (!col) return // when we change the field, // the corresponding default filter operator needs to be changed as well // since the existing one may not be supported for the new field // e.g. `eq` operator is not supported in checkbox field // hence, get the first option of the supported operators of the new field - filter.comparison_op = comparisonOpList(getColumn(filter)!.uidt as UITypes).filter((compOp) => + filter.comparison_op = comparisonOpList(col.uidt as UITypes).filter((compOp) => isComparisonOpAllowed(filter, compOp), )?.[0].value + + if ([UITypes.Date, UITypes.DateTime].includes(col.uidt as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op)) { + filter.comparison_sub_op = 'exact_date' + } + // reset filter value as well filter.value = '' saveOrUpdate(filter, index) @@ -260,6 +271,28 @@ defineExpose({ + + +