Browse Source

feat(nc-gui): add dateFormat to comparisonOpList & comparisonSubOpList

pull/6870/head
աɨռɢӄաօռɢ 1 year ago
parent
commit
2f7e5f575c
  1. 33
      packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue
  2. 413
      packages/nc-gui/utils/filterUtils.ts

33
packages/nc-gui/components/smartsheet/toolbar/ColumnFilter.vue

@ -107,12 +107,16 @@ const isFilterDraft = (filter: Filter, col: ColumnType) => {
if ( if (
filter.comparison_op && 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 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 return false
} }
@ -145,7 +149,7 @@ const filterUpdateCondition = (filter: FilterType, i: number) => {
// hence remove the previous value // hence remove the previous value
filter.value = null filter.value = null
if ( if (
!comparisonSubOpList(filter.comparison_op!) !comparisonSubOpList(filter.comparison_op!, col?.meta?.date_format)
.map((op) => op.value) .map((op) => op.value)
.includes(filter.comparison_sub_op!) .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 // since the existing one may not be supported for the new field
// e.g. `eq` operator is not supported in checkbox field // e.g. `eq` operator is not supported in checkbox field
// hence, get the first option of the supported operators of the new 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)) filter.comparison_op = comparisonOpList(col.uidt as UITypes, col?.meta?.date_format).find((compOp) =>
?.value as FilterType['comparison_op'] 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 ([UITypes.Date, UITypes.DateTime].includes(col.uidt as UITypes) && !['blank', 'notblank'].includes(filter.comparison_op!)) {
if (filter.comparison_op === 'isWithin') { if (filter.comparison_op === 'isWithin') {
@ -297,12 +302,16 @@ const addFilterGroup = async () => {
} }
const showFilterInput = (filter: Filter) => { const showFilterInput = (filter: Filter) => {
const col = getColumn(filter)
if (!filter.comparison_op) return false if (!filter.comparison_op) return false
if (filter.comparison_sub_op) { 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 { } 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" dropdown-class-name="nc-dropdown-filter-comp-op"
@change="filterUpdateCondition(filter, i)" @change="filterUpdateCondition(filter, i)"
> >
<template v-for="compOp of comparisonOpList(getColumn(filter)?.uidt)" :key="compOp.value"> <template
v-for="compOp of comparisonOpList(getColumn(filter)?.uidt, getColumn(filter)?.meta?.date_format)"
:key="compOp.value"
>
<a-select-option v-if="isComparisonOpAllowed(filter, compOp)" :value="compOp.value"> <a-select-option v-if="isComparisonOpAllowed(filter, compOp)" :value="compOp.value">
{{ compOp.text }} {{ compOp.text }}
</a-select-option> </a-select-option>
@ -450,7 +462,10 @@ onBeforeUnmount(() => {
dropdown-class-name="nc-dropdown-filter-comp-sub-op" dropdown-class-name="nc-dropdown-filter-comp-sub-op"
@change="filterUpdateCondition(filter, i)" @change="filterUpdateCondition(filter, i)"
> >
<template v-for="compSubOp of comparisonSubOpList(filter.comparison_op)" :key="compSubOp.value"> <template
v-for="compSubOp of comparisonSubOpList(filter.comparison_op, getColumn(filter)?.meta?.date_format)"
:key="compSubOp.value"
>
<a-select-option v-if="isComparisonSubOpAllowed(filter, compSubOp)" :value="compSubOp.value"> <a-select-option v-if="isComparisonSubOpAllowed(filter, compSubOp)" :value="compSubOp.value">
{{ compSubOp.text }} {{ compSubOp.text }}
</a-select-option> </a-select-option>

413
packages/nc-gui/utils/filterUtils.ts

@ -1,4 +1,4 @@
import { UITypes, isNumericCol, numericUITypes } from 'nocodb-sdk' import { UITypes, isDateMonthFormat, isNumericCol, numericUITypes } from 'nocodb-sdk'
const getEqText = (fieldUiType: UITypes) => { const getEqText = (fieldUiType: UITypes) => {
if (isNumericCol(fieldUiType) || fieldUiType === UITypes.Time) { if (isNumericCol(fieldUiType) || fieldUiType === UITypes.Time) {
@ -70,210 +70,215 @@ const getLteText = (fieldUiType: UITypes) => {
export const comparisonOpList = ( export const comparisonOpList = (
fieldUiType: UITypes, fieldUiType: UITypes,
dateFormat?: string,
): { ): {
text: string text: string
value: string value: string
ignoreVal: boolean ignoreVal: boolean
includedTypes?: UITypes[] includedTypes?: UITypes[]
excludedTypes?: UITypes[] excludedTypes?: UITypes[]
}[] => [ }[] => {
{ const isDateMonth = dateFormat && isDateMonthFormat(dateFormat)
text: 'is checked', return [
value: 'checked', {
ignoreVal: true, text: 'is checked',
includedTypes: [UITypes.Checkbox], value: 'checked',
}, ignoreVal: true,
{ includedTypes: [UITypes.Checkbox],
text: 'is not checked', },
value: 'notchecked', {
ignoreVal: true, text: 'is not checked',
includedTypes: [UITypes.Checkbox], value: 'notchecked',
}, ignoreVal: true,
{ includedTypes: [UITypes.Checkbox],
text: getEqText(fieldUiType), },
value: 'eq', {
ignoreVal: false, text: getEqText(fieldUiType),
excludedTypes: [UITypes.Checkbox, UITypes.MultiSelect, UITypes.Attachment], value: 'eq',
}, ignoreVal: false,
{ excludedTypes: [UITypes.Checkbox, UITypes.MultiSelect, UITypes.Attachment],
text: getNeqText(fieldUiType), },
value: 'neq', {
ignoreVal: false, text: getNeqText(fieldUiType),
excludedTypes: [UITypes.Checkbox, UITypes.MultiSelect, UITypes.Attachment], value: 'neq',
}, ignoreVal: false,
{ excludedTypes: [UITypes.Checkbox, UITypes.MultiSelect, UITypes.Attachment],
text: getLikeText(fieldUiType), },
value: 'like', {
ignoreVal: false, text: getLikeText(fieldUiType),
excludedTypes: [ value: 'like',
UITypes.Checkbox, ignoreVal: false,
UITypes.SingleSelect, excludedTypes: [
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Date, UITypes.MultiSelect,
UITypes.DateTime, UITypes.Collaborator,
UITypes.Time, UITypes.Date,
...numericUITypes, UITypes.DateTime,
], UITypes.Time,
}, ...numericUITypes,
{ ],
text: getNotLikeText(fieldUiType), },
value: 'nlike', {
ignoreVal: false, text: getNotLikeText(fieldUiType),
excludedTypes: [ value: 'nlike',
UITypes.Checkbox, ignoreVal: false,
UITypes.SingleSelect, excludedTypes: [
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Date, UITypes.MultiSelect,
UITypes.DateTime, UITypes.Collaborator,
UITypes.Time, UITypes.Date,
...numericUITypes, UITypes.DateTime,
], UITypes.Time,
}, ...numericUITypes,
{ ],
text: 'is empty', },
value: 'empty', {
ignoreVal: true, text: 'is empty',
excludedTypes: [ value: 'empty',
UITypes.Checkbox, ignoreVal: true,
UITypes.SingleSelect, excludedTypes: [
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Attachment, UITypes.MultiSelect,
UITypes.LinkToAnotherRecord, UITypes.Collaborator,
UITypes.Lookup, UITypes.Attachment,
UITypes.Date, UITypes.LinkToAnotherRecord,
UITypes.DateTime, UITypes.Lookup,
UITypes.Time, UITypes.Date,
...numericUITypes, UITypes.DateTime,
], UITypes.Time,
}, ...numericUITypes,
{ ],
text: 'is not empty', },
value: 'notempty', {
ignoreVal: true, text: 'is not empty',
excludedTypes: [ value: 'notempty',
UITypes.Checkbox, ignoreVal: true,
UITypes.SingleSelect, excludedTypes: [
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Attachment, UITypes.MultiSelect,
UITypes.LinkToAnotherRecord, UITypes.Collaborator,
UITypes.Lookup, UITypes.Attachment,
UITypes.Date, UITypes.LinkToAnotherRecord,
UITypes.DateTime, UITypes.Lookup,
UITypes.Time, UITypes.Date,
...numericUITypes, UITypes.DateTime,
], UITypes.Time,
}, ...numericUITypes,
{ ],
text: 'is null', },
value: 'null', {
ignoreVal: true, text: 'is null',
excludedTypes: [ value: 'null',
...numericUITypes, ignoreVal: true,
UITypes.Checkbox, excludedTypes: [
UITypes.SingleSelect, ...numericUITypes,
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Attachment, UITypes.MultiSelect,
UITypes.LinkToAnotherRecord, UITypes.Collaborator,
UITypes.Lookup, UITypes.Attachment,
UITypes.Date, UITypes.LinkToAnotherRecord,
UITypes.DateTime, UITypes.Lookup,
UITypes.Time, UITypes.Date,
], UITypes.DateTime,
}, UITypes.Time,
{ ],
text: 'is not null', },
value: 'notnull', {
ignoreVal: true, text: 'is not null',
excludedTypes: [ value: 'notnull',
...numericUITypes, ignoreVal: true,
UITypes.Checkbox, excludedTypes: [
UITypes.SingleSelect, ...numericUITypes,
UITypes.MultiSelect, UITypes.Checkbox,
UITypes.Collaborator, UITypes.SingleSelect,
UITypes.Attachment, UITypes.MultiSelect,
UITypes.LinkToAnotherRecord, UITypes.Collaborator,
UITypes.Lookup, UITypes.Attachment,
UITypes.Date, UITypes.LinkToAnotherRecord,
UITypes.DateTime, UITypes.Lookup,
UITypes.Time, UITypes.Date,
], UITypes.DateTime,
}, UITypes.Time,
{ ],
text: 'contains all of', },
value: 'allof', {
ignoreVal: false, text: 'contains all of',
includedTypes: [UITypes.MultiSelect], value: 'allof',
}, ignoreVal: false,
{ includedTypes: [UITypes.MultiSelect],
text: 'contains any of', },
value: 'anyof', {
ignoreVal: false, text: 'contains any of',
includedTypes: [UITypes.MultiSelect, UITypes.SingleSelect], value: 'anyof',
}, ignoreVal: false,
{ includedTypes: [UITypes.MultiSelect, UITypes.SingleSelect],
text: 'does not contain all of', },
value: 'nallof', {
ignoreVal: false, text: 'does not contain all of',
includedTypes: [UITypes.MultiSelect], value: 'nallof',
}, ignoreVal: false,
{ includedTypes: [UITypes.MultiSelect],
text: 'does not contain any of', },
value: 'nanyof', {
ignoreVal: false, text: 'does not contain any of',
includedTypes: [UITypes.MultiSelect, UITypes.SingleSelect], value: 'nanyof',
}, ignoreVal: false,
{ includedTypes: [UITypes.MultiSelect, UITypes.SingleSelect],
text: getGtText(fieldUiType), },
value: 'gt', {
ignoreVal: false, text: getGtText(fieldUiType),
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time], value: 'gt',
}, ignoreVal: false,
{ includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
text: getLtText(fieldUiType), },
value: 'lt', {
ignoreVal: false, text: getLtText(fieldUiType),
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time], value: 'lt',
}, ignoreVal: false,
{ includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
text: getGteText(fieldUiType), },
value: 'gte', {
ignoreVal: false, text: getGteText(fieldUiType),
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time], value: 'gte',
}, ignoreVal: false,
{ includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
text: getLteText(fieldUiType), },
value: 'lte', {
ignoreVal: false, text: getLteText(fieldUiType),
includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time], value: 'lte',
}, ignoreVal: false,
{ includedTypes: [...numericUITypes, UITypes.Date, UITypes.DateTime, UITypes.Time],
text: 'is within', },
value: 'isWithin', {
ignoreVal: true, text: 'is within',
includedTypes: [UITypes.Date, UITypes.DateTime], value: 'isWithin',
}, ignoreVal: true,
{ includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
text: 'is blank', },
value: 'blank', {
ignoreVal: true, text: 'is blank',
excludedTypes: [UITypes.Checkbox, UITypes.Links, UITypes.Rollup], value: 'blank',
}, ignoreVal: true,
{ excludedTypes: [UITypes.Checkbox, UITypes.Links, UITypes.Rollup],
text: 'is not blank', },
value: 'notblank', {
ignoreVal: true, text: 'is not blank',
excludedTypes: [UITypes.Checkbox, UITypes.Links, UITypes.Rollup], value: 'notblank',
}, ignoreVal: true,
] excludedTypes: [UITypes.Checkbox, UITypes.Links, UITypes.Rollup],
},
]
}
export const comparisonSubOpList = ( export const comparisonSubOpList = (
// TODO: type // TODO: type
comparison_op: string, comparison_op: string,
dateFormat?: string,
): { ): {
text: string text: string
value: string value: string
@ -281,6 +286,8 @@ export const comparisonSubOpList = (
includedTypes?: UITypes[] includedTypes?: UITypes[]
excludedTypes?: UITypes[] excludedTypes?: UITypes[]
}[] => { }[] => {
const isDateMonth = dateFormat && isDateMonthFormat(dateFormat)
if (comparison_op === 'isWithin') { if (comparison_op === 'isWithin') {
return [ return [
{ {
@ -338,31 +345,31 @@ export const comparisonSubOpList = (
text: 'today', text: 'today',
value: 'today', value: 'today',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'tomorrow', text: 'tomorrow',
value: 'tomorrow', value: 'tomorrow',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'yesterday', text: 'yesterday',
value: 'yesterday', value: 'yesterday',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'one week ago', text: 'one week ago',
value: 'oneWeekAgo', value: 'oneWeekAgo',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'one week from now', text: 'one week from now',
value: 'oneWeekFromNow', value: 'oneWeekFromNow',
ignoreVal: true, ignoreVal: true,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'one month ago', text: 'one month ago',
@ -380,16 +387,16 @@ export const comparisonSubOpList = (
text: 'number of days ago', text: 'number of days ago',
value: 'daysAgo', value: 'daysAgo',
ignoreVal: false, ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'number of days from now', text: 'number of days from now',
value: 'daysFromNow', value: 'daysFromNow',
ignoreVal: false, ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [...(isDateMonth ? [] : [UITypes.Date, UITypes.DateTime])],
}, },
{ {
text: 'exact date', text: isDateMonth ? 'exact month' : 'exact date',
value: 'exactDate', value: 'exactDate',
ignoreVal: false, ignoreVal: false,
includedTypes: [UITypes.Date, UITypes.DateTime], includedTypes: [UITypes.Date, UITypes.DateTime],

Loading…
Cancel
Save