From 2f7e5f575c2e4161d92ec82a34474a3844b8ffb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D5=A1=C9=A8=D5=BC=C9=A2=D3=84=D5=A1=D6=85=D5=BC=C9=A2?= Date: Sun, 19 Nov 2023 00:18:51 +0800 Subject: [PATCH] feat(nc-gui): add dateFormat to comparisonOpList & comparisonSubOpList --- .../smartsheet/toolbar/ColumnFilter.vue | 33 +- packages/nc-gui/utils/filterUtils.ts | 413 +++++++++--------- 2 files changed, 234 insertions(+), 212 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue index 6d22c8dcf1..e72362e71f 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue @@ -107,12 +107,16 @@ const isFilterDraft = (filter: Filter, col: ColumnType) => { if ( filter.comparison_op && - comparisonSubOpList(filter.comparison_op).find((compOp) => compOp.value === filter.comparison_sub_op)?.ignoreVal + comparisonSubOpList(filter.comparison_op, col?.meta?.date_format).find((compOp) => compOp.value === filter.comparison_sub_op) + ?.ignoreVal ) { return false } - if (comparisonOpList(col.uidt as UITypes).find((compOp) => compOp.value === filter.comparison_op)?.ignoreVal) { + if ( + comparisonOpList(col.uidt as UITypes, col?.meta?.date_format).find((compOp) => compOp.value === filter.comparison_op) + ?.ignoreVal + ) { return false } @@ -145,7 +149,7 @@ const filterUpdateCondition = (filter: FilterType, i: number) => { // hence remove the previous value filter.value = null if ( - !comparisonSubOpList(filter.comparison_op!) + !comparisonSubOpList(filter.comparison_op!, col?.meta?.date_format) .map((op) => op.value) .includes(filter.comparison_sub_op!) ) { @@ -224,8 +228,9 @@ const selectFilterField = (filter: Filter, index: number) => { // 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(col.uidt as UITypes).find((compOp) => isComparisonOpAllowed(filter, compOp)) - ?.value as FilterType['comparison_op'] + filter.comparison_op = comparisonOpList(col.uidt as UITypes, col?.meta?.date_format).find((compOp) => + isComparisonOpAllowed(filter, compOp), + )?.value as FilterType['comparison_op'] if ([UITypes.Date, UITypes.DateTime].includes(col.uidt as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op!)) { if (filter.comparison_op === 'isWithin') { @@ -297,12 +302,16 @@ const addFilterGroup = async () => { } const showFilterInput = (filter: Filter) => { + const col = getColumn(filter) if (!filter.comparison_op) return false if (filter.comparison_sub_op) { - return !comparisonSubOpList(filter.comparison_op).find((op) => op.value === filter.comparison_sub_op)?.ignoreVal + return !comparisonSubOpList(filter.comparison_op, getColumn(filter)?.meta?.date_format).find( + (op) => op.value === filter.comparison_sub_op, + )?.ignoreVal } else { - return !comparisonOpList(getColumn(filter)?.uidt as UITypes).find((op) => op.value === filter.comparison_op)?.ignoreVal + return !comparisonOpList(col?.uidt as UITypes, col?.meta?.date_format).find((op) => op.value === filter.comparison_op) + ?.ignoreVal } } @@ -427,7 +436,10 @@ onBeforeUnmount(() => { dropdown-class-name="nc-dropdown-filter-comp-op" @change="filterUpdateCondition(filter, i)" > -