[View migration] Clean ViewFilterOperand (#14785)
In the BE we have stored filter operand as IS_EMPTY, IS_NOT_EMPTY, etc. For some reason in the FE we were manipulating IsEmpty, IsNotEmpty, etc. (maybe because they were used before in Views before they were moved to core) So we were converting the operands in the FE from IS to Is (convertViewFilterOperandFromCore) to read and manipulate viewFilters, and then back to BE version to send mutations etc., from Is to IS (convertViewFilterOperandToCore). The migration is now over, so we can remove and simplify that code. (In the 1-5:migrate-views-to-core command we still do the migration from Is format to IS format.)
This commit is contained in:
@@ -7,7 +7,7 @@ describe('areViewFiltersEqual', () => {
|
||||
__typename: 'ViewFilter',
|
||||
id: 'filter-1',
|
||||
fieldMetadataId: 'field-1',
|
||||
operand: ViewFilterOperand.Contains,
|
||||
operand: ViewFilterOperand.CONTAINS,
|
||||
value: 'test',
|
||||
displayValue: 'test',
|
||||
viewFilterGroupId: 'group-1',
|
||||
@@ -46,7 +46,7 @@ describe('areViewFiltersEqual', () => {
|
||||
const filterA = { ...baseFilter };
|
||||
const filterB = {
|
||||
...baseFilter,
|
||||
operand: ViewFilterOperand.DoesNotContain,
|
||||
operand: ViewFilterOperand.DOES_NOT_CONTAIN,
|
||||
};
|
||||
|
||||
expect(areViewFiltersEqual(filterA, filterB)).toBe(false);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ describe('getViewFiltersToCreate', () => {
|
||||
__typename: 'ViewFilter',
|
||||
id: 'filter-1',
|
||||
fieldMetadataId: 'field-1',
|
||||
operand: ViewFilterOperand.Contains,
|
||||
operand: ViewFilterOperand.CONTAINS,
|
||||
value: 'test',
|
||||
displayValue: 'test',
|
||||
viewFilterGroupId: 'group-1',
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ describe('getViewFiltersToDelete', () => {
|
||||
__typename: 'ViewFilter',
|
||||
id: 'filter-1',
|
||||
fieldMetadataId: 'field-1',
|
||||
operand: ViewFilterOperand.Contains,
|
||||
operand: ViewFilterOperand.CONTAINS,
|
||||
value: 'test',
|
||||
displayValue: 'test',
|
||||
viewFilterGroupId: 'group-1',
|
||||
|
||||
+2
-2
@@ -7,7 +7,7 @@ describe('getViewFiltersToUpdate', () => {
|
||||
__typename: 'ViewFilter',
|
||||
id: 'filter-1',
|
||||
fieldMetadataId: 'field-1',
|
||||
operand: ViewFilterOperand.Contains,
|
||||
operand: ViewFilterOperand.CONTAINS,
|
||||
value: 'test',
|
||||
displayValue: 'test',
|
||||
viewFilterGroupId: 'group-1',
|
||||
@@ -73,7 +73,7 @@ describe('getViewFiltersToUpdate', () => {
|
||||
const existingFilter = { ...baseFilter } satisfies ViewFilter;
|
||||
const filterWithNewOperand = {
|
||||
...baseFilter,
|
||||
operand: ViewFilterOperand.DoesNotContain,
|
||||
operand: ViewFilterOperand.DOES_NOT_CONTAIN,
|
||||
} satisfies ViewFilter;
|
||||
|
||||
const currentViewFilters: ViewFilter[] = [existingFilter];
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('mapViewFiltersToFilters', () => {
|
||||
fieldMetadataId: '05731f68-6e7a-4903-8374-c0b6a9063482',
|
||||
value: 'testValue',
|
||||
displayValue: 'Test Display Value',
|
||||
operand: ViewFilterOperand.Is,
|
||||
operand: ViewFilterOperand.IS,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('mapViewFiltersToFilters', () => {
|
||||
fieldMetadataId: '05731f68-6e7a-4903-8374-c0b6a9063482',
|
||||
value: 'testValue',
|
||||
displayValue: 'Test Display Value',
|
||||
operand: ViewFilterOperand.Is,
|
||||
operand: ViewFilterOperand.IS,
|
||||
label: baseFieldMetadataItem.label,
|
||||
type: FieldMetadataType.FULL_NAME,
|
||||
positionInRecordFilterGroup: undefined,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { type CompositeFieldSubFieldName } from '@/settings/data-model/types/Com
|
||||
import { type ViewFilter } from '@/views/types/ViewFilter';
|
||||
import { convertViewFilterValueToString } from 'twenty-shared/utils';
|
||||
import { type CoreViewFilter } from '~/generated/graphql';
|
||||
import { convertViewFilterOperandFromCore } from '../utils/convertViewFilterOperandFromCore';
|
||||
|
||||
export const convertCoreViewFilterToViewFilter = (
|
||||
coreViewFilter: Pick<
|
||||
@@ -20,7 +19,7 @@ export const convertCoreViewFilterToViewFilter = (
|
||||
__typename: 'ViewFilter',
|
||||
id: coreViewFilter.id,
|
||||
fieldMetadataId: coreViewFilter.fieldMetadataId,
|
||||
operand: convertViewFilterOperandFromCore(coreViewFilter.operand),
|
||||
operand: coreViewFilter.operand,
|
||||
value: convertViewFilterValueToString(coreViewFilter.value),
|
||||
displayValue: convertViewFilterValueToString(coreViewFilter.value),
|
||||
viewFilterGroupId: coreViewFilter.viewFilterGroupId,
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
import { ViewFilterOperand } from 'twenty-shared/types';
|
||||
import { ViewFilterOperand as CoreViewFilterOperand } from '~/generated/graphql';
|
||||
|
||||
const mappingFromCore: Record<CoreViewFilterOperand, ViewFilterOperand> = {
|
||||
[CoreViewFilterOperand.IS]: ViewFilterOperand.Is,
|
||||
[CoreViewFilterOperand.IS_NOT_NULL]: ViewFilterOperand.IsNotNull,
|
||||
[CoreViewFilterOperand.IS_NOT]: ViewFilterOperand.IsNot,
|
||||
[CoreViewFilterOperand.LESS_THAN_OR_EQUAL]: ViewFilterOperand.LessThanOrEqual,
|
||||
[CoreViewFilterOperand.GREATER_THAN_OR_EQUAL]:
|
||||
ViewFilterOperand.GreaterThanOrEqual,
|
||||
[CoreViewFilterOperand.IS_BEFORE]: ViewFilterOperand.IsBefore,
|
||||
[CoreViewFilterOperand.IS_AFTER]: ViewFilterOperand.IsAfter,
|
||||
[CoreViewFilterOperand.CONTAINS]: ViewFilterOperand.Contains,
|
||||
[CoreViewFilterOperand.DOES_NOT_CONTAIN]: ViewFilterOperand.DoesNotContain,
|
||||
[CoreViewFilterOperand.IS_EMPTY]: ViewFilterOperand.IsEmpty,
|
||||
[CoreViewFilterOperand.IS_NOT_EMPTY]: ViewFilterOperand.IsNotEmpty,
|
||||
[CoreViewFilterOperand.IS_RELATIVE]: ViewFilterOperand.IsRelative,
|
||||
[CoreViewFilterOperand.IS_IN_PAST]: ViewFilterOperand.IsInPast,
|
||||
[CoreViewFilterOperand.IS_IN_FUTURE]: ViewFilterOperand.IsInFuture,
|
||||
[CoreViewFilterOperand.IS_TODAY]: ViewFilterOperand.IsToday,
|
||||
[CoreViewFilterOperand.VECTOR_SEARCH]: ViewFilterOperand.VectorSearch,
|
||||
};
|
||||
|
||||
export const convertViewFilterOperandFromCore = (
|
||||
coreOperand: CoreViewFilterOperand,
|
||||
): ViewFilterOperand => mappingFromCore[coreOperand];
|
||||
@@ -1,28 +0,0 @@
|
||||
import { ViewFilterOperand } from 'twenty-shared/types';
|
||||
import { ViewFilterOperand as CoreViewFilterOperand } from '~/generated-metadata/graphql';
|
||||
|
||||
const operandMapping: Record<ViewFilterOperand, CoreViewFilterOperand> = {
|
||||
[ViewFilterOperand.Is]: CoreViewFilterOperand.IS,
|
||||
[ViewFilterOperand.IsNotNull]: CoreViewFilterOperand.IS_NOT_NULL,
|
||||
[ViewFilterOperand.IsNot]: CoreViewFilterOperand.IS_NOT,
|
||||
[ViewFilterOperand.LessThanOrEqual]: CoreViewFilterOperand.LESS_THAN_OR_EQUAL,
|
||||
[ViewFilterOperand.GreaterThanOrEqual]:
|
||||
CoreViewFilterOperand.GREATER_THAN_OR_EQUAL,
|
||||
[ViewFilterOperand.IsBefore]: CoreViewFilterOperand.IS_BEFORE,
|
||||
[ViewFilterOperand.IsAfter]: CoreViewFilterOperand.IS_AFTER,
|
||||
[ViewFilterOperand.Contains]: CoreViewFilterOperand.CONTAINS,
|
||||
[ViewFilterOperand.DoesNotContain]: CoreViewFilterOperand.DOES_NOT_CONTAIN,
|
||||
[ViewFilterOperand.IsEmpty]: CoreViewFilterOperand.IS_EMPTY,
|
||||
[ViewFilterOperand.IsNotEmpty]: CoreViewFilterOperand.IS_NOT_EMPTY,
|
||||
[ViewFilterOperand.IsRelative]: CoreViewFilterOperand.IS_RELATIVE,
|
||||
[ViewFilterOperand.IsInPast]: CoreViewFilterOperand.IS_IN_PAST,
|
||||
[ViewFilterOperand.IsInFuture]: CoreViewFilterOperand.IS_IN_FUTURE,
|
||||
[ViewFilterOperand.IsToday]: CoreViewFilterOperand.IS_TODAY,
|
||||
[ViewFilterOperand.VectorSearch]: CoreViewFilterOperand.VECTOR_SEARCH,
|
||||
};
|
||||
|
||||
export const convertViewFilterOperandToCore = (
|
||||
sharedOperand: ViewFilterOperand,
|
||||
): CoreViewFilterOperand => {
|
||||
return operandMapping[sharedOperand];
|
||||
};
|
||||
@@ -21,9 +21,9 @@ export const getRecordFilterLabelValue = ({
|
||||
|
||||
if (isDateOrDateTimeFilter) {
|
||||
switch (recordFilter.operand) {
|
||||
case RecordFilterOperand.IsToday:
|
||||
case RecordFilterOperand.IsInFuture:
|
||||
case RecordFilterOperand.IsInPast:
|
||||
case RecordFilterOperand.IS_TODAY:
|
||||
case RecordFilterOperand.IS_IN_FUTURE:
|
||||
case RecordFilterOperand.IS_IN_PAST:
|
||||
return operandLabelShort;
|
||||
default:
|
||||
return `${operandLabelShort} ${recordFilter.displayValue}`;
|
||||
|
||||
@@ -2,5 +2,5 @@ import { type RecordFilter } from '@/object-record/record-filter/types/RecordFil
|
||||
import { ViewFilterOperand } from 'twenty-shared/types';
|
||||
|
||||
export const isVectorSearchFilter = (filter: RecordFilter) => {
|
||||
return filter.operand === ViewFilterOperand.VectorSearch;
|
||||
return filter.operand === ViewFilterOperand.VECTOR_SEARCH;
|
||||
};
|
||||
|
||||
@@ -4,8 +4,6 @@ import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataIte
|
||||
|
||||
import { isSystemSearchVectorField } from '@/object-record/utils/isSystemSearchVectorField';
|
||||
import { type CompositeFieldSubFieldName } from '@/settings/data-model/types/CompositeFieldSubFieldName';
|
||||
import { convertViewFilterOperandFromCore } from '@/views/utils/convertViewFilterOperandFromCore';
|
||||
import { type ViewFilterOperand } from 'twenty-shared/types';
|
||||
import { getFilterTypeFromFieldType, isDefined } from 'twenty-shared/utils';
|
||||
import { type CoreViewFilter } from '~/generated/graphql';
|
||||
import { type ViewFilter } from '../types/ViewFilter';
|
||||
@@ -34,10 +32,7 @@ export const mapViewFiltersToFilters = (
|
||||
? 'Search'
|
||||
: availableFieldMetadataItem.label;
|
||||
|
||||
const operand =
|
||||
viewFilter.__typename === 'CoreViewFilter'
|
||||
? convertViewFilterOperandFromCore(viewFilter.operand)
|
||||
: (viewFilter.operand as ViewFilterOperand);
|
||||
const operand = viewFilter.operand;
|
||||
|
||||
return {
|
||||
id: viewFilter.id,
|
||||
|
||||
Reference in New Issue
Block a user