diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/isFilterOperandExpectingValue.test.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/isFilterOperandExpectingValue.test.ts new file mode 100644 index 000000000..62246c736 --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/__tests__/isFilterOperandExpectingValue.test.ts @@ -0,0 +1,30 @@ +import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; + +import { isFilterOperandExpectingValue } from '../isFilterOperandExpectingValue'; + +describe('isFilterOperandExpectingValue', () => { + const testCases = [ + { operand: ViewFilterOperand.Contains, expectedResult: true }, + { operand: ViewFilterOperand.DoesNotContain, expectedResult: true }, + { operand: ViewFilterOperand.GreaterThan, expectedResult: true }, + { operand: ViewFilterOperand.LessThan, expectedResult: true }, + { operand: ViewFilterOperand.Is, expectedResult: true }, + { operand: ViewFilterOperand.IsNot, expectedResult: true }, + { operand: ViewFilterOperand.IsRelative, expectedResult: true }, + { operand: ViewFilterOperand.IsBefore, expectedResult: true }, + { operand: ViewFilterOperand.IsAfter, expectedResult: true }, + + { operand: ViewFilterOperand.IsNotNull, expectedResult: false }, + { operand: ViewFilterOperand.IsEmpty, expectedResult: false }, + { operand: ViewFilterOperand.IsNotEmpty, expectedResult: false }, + { operand: ViewFilterOperand.IsInPast, expectedResult: false }, + { operand: ViewFilterOperand.IsInFuture, expectedResult: false }, + { operand: ViewFilterOperand.IsToday, expectedResult: false }, + ]; + + testCases.forEach(({ operand, expectedResult }) => { + it(`should return ${expectedResult} for ViewFilterOperand.${operand}`, () => { + expect(isFilterOperandExpectingValue(operand)).toBe(expectedResult); + }); + }); +}); diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/isFilterOperandExpectingValue.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/isFilterOperandExpectingValue.ts new file mode 100644 index 000000000..668742946 --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/utils/isFilterOperandExpectingValue.ts @@ -0,0 +1,24 @@ +import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; + +export const isFilterOperandExpectingValue = (operand: ViewFilterOperand) => { + switch (operand) { + case ViewFilterOperand.IsNotNull: + case ViewFilterOperand.IsEmpty: + case ViewFilterOperand.IsNotEmpty: + case ViewFilterOperand.IsInPast: + case ViewFilterOperand.IsInFuture: + case ViewFilterOperand.IsToday: + return false; + case ViewFilterOperand.IsNot: + case ViewFilterOperand.Contains: + case ViewFilterOperand.DoesNotContain: + case ViewFilterOperand.GreaterThan: + case ViewFilterOperand.LessThan: + case ViewFilterOperand.IsBefore: + case ViewFilterOperand.IsAfter: + case ViewFilterOperand.Is: + case ViewFilterOperand.IsRelative: + default: + return true; + } +}; diff --git a/packages/twenty-front/src/modules/views/components/EditableFilterChip.tsx b/packages/twenty-front/src/modules/views/components/EditableFilterChip.tsx index 99b6bd0c5..137422e5f 100644 --- a/packages/twenty-front/src/modules/views/components/EditableFilterChip.tsx +++ b/packages/twenty-front/src/modules/views/components/EditableFilterChip.tsx @@ -2,6 +2,7 @@ import { useFieldMetadataItemById } from '@/object-metadata/hooks/useFieldMetada import { getCompositeSubFieldLabel } from '@/object-record/object-filter-dropdown/utils/getCompositeSubFieldLabel'; import { getOperandLabelShort } from '@/object-record/object-filter-dropdown/utils/getOperandLabel'; import { isCompositeField } from '@/object-record/object-filter-dropdown/utils/isCompositeField'; +import { isFilterOperandExpectingValue } from '@/object-record/object-filter-dropdown/utils/isFilterOperandExpectingValue'; import { RecordFilter } from '@/object-record/record-filter/types/RecordFilter'; import { isValidSubFieldName } from '@/settings/data-model/utils/isValidSubFieldName'; import { SortOrFilterChip } from '@/views/components/SortOrFilterChip'; @@ -43,7 +44,11 @@ export const EditableFilterChip = ({ ? `${recordFilter.label} / ${subFieldLabel}` : recordFilter.label; - const labelKey = `${fieldNameLabel}${isNonEmptyString(recordFilter.value) ? operandLabelShort : ''}`; + const shouldDisplayOperandLabelShort = + isNonEmptyString(recordFilter.value) || + !isFilterOperandExpectingValue(recordFilter.operand); + + const labelKey = `${fieldNameLabel}${shouldDisplayOperandLabelShort ? operandLabelShort : ''}`; return (