From 151c422fa5aa90d0e9c5ea543bb8cc6494024999 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 7 Feb 2024 14:08:19 +0000 Subject: [PATCH] feat: show filter input type and operators based on formula output type --- .../smartsheet/toolbar/ColumnFilter.vue | 36 ++++++++----------- packages/nc-gui/composables/useViewFilters.ts | 33 +++++++++++++---- packages/nocodb-sdk/src/lib/UITypes.ts | 18 ++++++++++ packages/nocodb-sdk/src/lib/index.ts | 1 + 4 files changed, 60 insertions(+), 28 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue index e650749a30..a51fa49d68 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue @@ -76,6 +76,7 @@ const { isComparisonSubOpAllowed, loadBtLookupTypes, btLookupTypesMap, + types, } = useViewFilters( activeView, parentId?.value, @@ -114,8 +115,9 @@ const isFilterDraft = (filter: Filter, col: ColumnType) => { } if ( - comparisonOpList(col.uidt as UITypes, col?.meta?.date_format).find((compOp) => compOp.value === filter.comparison_op) - ?.ignoreVal + comparisonOpList(types.value[col.id] as UITypes, col?.meta?.date_format).find( + (compOp) => compOp.value === filter.comparison_op, + )?.ignoreVal ) { return false } @@ -143,7 +145,7 @@ const filterUpdateCondition = (filter: FilterType, i: number) => { // hence remove the previous value filter.value = null filter.comparison_sub_op = null - } else if (isDateType(col.uidt as UITypes)) { + } else if (isDateType(types.value[col.id] as UITypes)) { // for date / datetime, // the input type could be decimal or datepicker / datetime picker // hence remove the previous value @@ -173,17 +175,6 @@ const filterUpdateCondition = (filter: FilterType, i: number) => { }) } -const types = computed(() => { - if (!meta.value?.columns?.length) { - return {} - } - - return meta.value?.columns?.reduce((obj: any, col: any) => { - obj[col.id] = col.uidt - return obj - }, {}) -}) - watch( () => activeView.value?.id, (n, o) => { @@ -237,11 +228,11 @@ 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, col?.meta?.date_format).find((compOp) => + filter.comparison_op = comparisonOpList(types.value[col.id] as UITypes, col?.meta?.date_format).find((compOp) => isComparisonOpAllowed(filter, compOp), )?.value as FilterType['comparison_op'] - if (isDateType(col.uidt as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op!)) { + if (isDateType(types.value[col.id] as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op!)) { if (filter.comparison_op === 'isWithin') { filter.comparison_sub_op = 'pastNumberOfDays' } else { @@ -319,8 +310,9 @@ const showFilterInput = (filter: Filter) => { (op) => op.value === filter.comparison_sub_op, )?.ignoreVal } else { - return !comparisonOpList(col?.uidt as UITypes, col?.meta?.date_format).find((op) => op.value === filter.comparison_op) - ?.ignoreVal + return !comparisonOpList(types.value[col?.id] as UITypes, col?.meta?.date_format).find( + (op) => op.value === filter.comparison_op, + )?.ignoreVal } } @@ -462,7 +454,7 @@ function isDateType(uidt: UITypes) { @change="filterUpdateCondition(filter, i)" >