From 364caf0fdf32339004a6d56b4ac8fab7b16ff792 Mon Sep 17 00:00:00 2001 From: Siddhant Rai <47355538+siiddhantt@users.noreply.github.com> Date: Tue, 16 Jul 2024 13:54:35 +0530 Subject: [PATCH] fix: remove usage of probability field (#5877) - fixes #5735 --------- Co-authored-by: Marie Stoppa --- .../src/generated-metadata/graphql.ts | 1 - .../twenty-front/src/generated/graphql.tsx | 1 - ...atFieldMetadataItemsAsFilterDefinitions.ts | 5 ---- .../record-field/hooks/usePersistField.ts | 4 ++-- .../types/guards/assertFieldMetadata.ts | 24 +++++++++---------- .../constants/SettingsFieldTypeConfigs.ts | 5 ---- .../SettingsObjectNewFieldStep2.tsx | 2 +- .../__mocks__/object-metadata-item.mock.ts | 8 ------- .../services/type-mapper.service.ts | 3 --- .../utils/__tests__/components.utils.spec.ts | 3 --- .../open-api/utils/components.utils.ts | 1 - .../field-metadata/field-metadata.entity.ts | 1 - .../field-metadata-default-value.interface.ts | 1 - ...lidate-default-value-based-on-type.spec.ts | 12 ---------- .../validate-default-value-for-type.util.ts | 1 - .../factories/basic-column-action.factory.ts | 1 - ...field-metadata-type-to-column-type.util.ts | 1 - .../workspace-migration.factory.ts | 4 ---- 18 files changed, 14 insertions(+), 64 deletions(-) diff --git a/packages/twenty-front/src/generated-metadata/graphql.ts b/packages/twenty-front/src/generated-metadata/graphql.ts index 46ef29e77a..958328038e 100644 --- a/packages/twenty-front/src/generated-metadata/graphql.ts +++ b/packages/twenty-front/src/generated-metadata/graphql.ts @@ -333,7 +333,6 @@ export enum FieldMetadataType { Numeric = 'NUMERIC', Phone = 'PHONE', Position = 'POSITION', - Probability = 'PROBABILITY', Rating = 'RATING', RawJson = 'RAW_JSON', Relation = 'RELATION', diff --git a/packages/twenty-front/src/generated/graphql.tsx b/packages/twenty-front/src/generated/graphql.tsx index aef71e4d86..4b1a828b44 100644 --- a/packages/twenty-front/src/generated/graphql.tsx +++ b/packages/twenty-front/src/generated/graphql.tsx @@ -246,7 +246,6 @@ export enum FieldMetadataType { Numeric = 'NUMERIC', Phone = 'PHONE', Position = 'POSITION', - Probability = 'PROBABILITY', Rating = 'RATING', RawJson = 'RAW_JSON', Relation = 'RELATION', diff --git a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts index fe2581b8cd..318073af17 100644 --- a/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts +++ b/packages/twenty-front/src/modules/object-metadata/utils/formatFieldMetadataItemsAsFilterDefinitions.ts @@ -39,11 +39,6 @@ export const formatFieldMetadataItemsAsFilterDefinitions = ({ return acc; } - // Todo: remove once Rating fieldtype is implemented - if (field.name === 'probability') { - return acc; - } - return [...acc, formatFieldMetadataItemAsFilterDefinition({ field })]; }, [] as FilterDefinition[]); diff --git a/packages/twenty-front/src/modules/object-record/record-field/hooks/usePersistField.ts b/packages/twenty-front/src/modules/object-record/record-field/hooks/usePersistField.ts index c839b6053d..946b6046dc 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/hooks/usePersistField.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/hooks/usePersistField.ts @@ -82,7 +82,7 @@ export const usePersistField = () => { isFieldBoolean(fieldDefinition) && isFieldBooleanValue(valueToPersist); - const fieldIsProbability = + const fieldIsRating = isFieldRating(fieldDefinition) && isFieldRatingValue(valueToPersist); const fieldIsNumber = @@ -119,7 +119,7 @@ export const usePersistField = () => { fieldIsText || fieldIsBoolean || fieldIsEmail || - fieldIsProbability || + fieldIsRating || fieldIsNumber || fieldIsDateTime || fieldIsDate || diff --git a/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts b/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts index 9d1f878284..c82974a1a7 100644 --- a/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts +++ b/packages/twenty-front/src/modules/object-record/record-field/types/guards/assertFieldMetadata.ts @@ -51,19 +51,17 @@ type AssertFieldMetadataFunction = < ? FieldNumberMetadata : E extends 'PHONE' ? FieldPhoneMetadata - : E extends 'PROBABILITY' - ? FieldRatingMetadata - : E extends 'RELATION' - ? FieldRelationMetadata - : E extends 'TEXT' - ? FieldTextMetadata - : E extends 'UUID' - ? FieldUuidMetadata - : E extends 'ADDRESS' - ? FieldAddressMetadata - : E extends 'RAW_JSON' - ? FieldRawJsonMetadata - : never, + : E extends 'RELATION' + ? FieldRelationMetadata + : E extends 'TEXT' + ? FieldTextMetadata + : E extends 'UUID' + ? FieldUuidMetadata + : E extends 'ADDRESS' + ? FieldAddressMetadata + : E extends 'RAW_JSON' + ? FieldRawJsonMetadata + : never, >( fieldType: E, fieldTypeGuard: ( diff --git a/packages/twenty-front/src/modules/settings/data-model/constants/SettingsFieldTypeConfigs.ts b/packages/twenty-front/src/modules/settings/data-model/constants/SettingsFieldTypeConfigs.ts index 681062d937..cd2580d566 100644 --- a/packages/twenty-front/src/modules/settings/data-model/constants/SettingsFieldTypeConfigs.ts +++ b/packages/twenty-front/src/modules/settings/data-model/constants/SettingsFieldTypeConfigs.ts @@ -102,11 +102,6 @@ export const SETTINGS_FIELD_TYPE_CONFIGS = { Icon: IconPhone, defaultValue: '+1234-567-890', }, - [FieldMetadataType.Probability]: { - label: 'Rating', - Icon: IconTwentyStar, - defaultValue: '3', - }, [FieldMetadataType.Rating]: { label: 'Rating', Icon: IconTwentyStar, diff --git a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldStep2.tsx b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldStep2.tsx index 54f6910af9..a2dca70bea 100644 --- a/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldStep2.tsx +++ b/packages/twenty-front/src/pages/settings/data-model/SettingsObjectNewField/SettingsObjectNewFieldStep2.tsx @@ -161,7 +161,7 @@ export const SettingsObjectNewFieldStep2 = () => { // FieldMetadataType.FullName, FieldMetadataType.Link, FieldMetadataType.Numeric, - FieldMetadataType.Probability, + // FieldMetadataType.Probability, // FieldMetadataType.Uuid, // FieldMetadataType.Phone, ] as const diff --git a/packages/twenty-server/src/engine/api/__mocks__/object-metadata-item.mock.ts b/packages/twenty-server/src/engine/api/__mocks__/object-metadata-item.mock.ts index f4722d2ca5..d988d614a2 100644 --- a/packages/twenty-server/src/engine/api/__mocks__/object-metadata-item.mock.ts +++ b/packages/twenty-server/src/engine/api/__mocks__/object-metadata-item.mock.ts @@ -145,13 +145,6 @@ const fieldNumericMock = { defaultValue: null, }; -const fieldProbabilityMock = { - name: 'fieldProbability', - type: FieldMetadataType.PROBABILITY, - isNullable: true, - defaultValue: null, -}; - const fieldFullNameMock = { name: 'fieldFullName', type: FieldMetadataType.FULL_NAME, @@ -206,7 +199,6 @@ export const fields = [ fieldBooleanMock, fieldNumberMock, fieldNumericMock, - fieldProbabilityMock, fieldLinkMock, fieldLinksMock, fieldCurrencyMock, diff --git a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/services/type-mapper.service.ts b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/services/type-mapper.service.ts index cb04e53002..531939cf4c 100644 --- a/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/services/type-mapper.service.ts +++ b/packages/twenty-server/src/engine/api/graphql/workspace-schema-builder/services/type-mapper.service.ts @@ -73,7 +73,6 @@ export class TypeMapperService { ), ], [FieldMetadataType.NUMERIC, BigFloatScalarType], - [FieldMetadataType.PROBABILITY, GraphQLFloat], [FieldMetadataType.POSITION, PositionScalarType], [FieldMetadataType.RAW_JSON, RawJSONScalar], ]); @@ -109,7 +108,6 @@ export class TypeMapperService { ), ], [FieldMetadataType.NUMERIC, BigFloatFilterType], - [FieldMetadataType.PROBABILITY, FloatFilterType], [FieldMetadataType.POSITION, FloatFilterType], [FieldMetadataType.RAW_JSON, RawJsonFilterType], ]); @@ -130,7 +128,6 @@ export class TypeMapperService { [FieldMetadataType.BOOLEAN, OrderByDirectionType], [FieldMetadataType.NUMBER, OrderByDirectionType], [FieldMetadataType.NUMERIC, OrderByDirectionType], - [FieldMetadataType.PROBABILITY, OrderByDirectionType], [FieldMetadataType.RATING, OrderByDirectionType], [FieldMetadataType.SELECT, OrderByDirectionType], [FieldMetadataType.MULTI_SELECT, OrderByDirectionType], diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/components.utils.spec.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/components.utils.spec.ts index 8a953bc454..09d8643776 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/components.utils.spec.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/__tests__/components.utils.spec.ts @@ -55,9 +55,6 @@ describe('computeSchemaComponents', () => { fieldNumeric: { type: 'number', }, - fieldProbability: { - type: 'number', - }, fieldLink: { properties: { label: { type: 'string' }, diff --git a/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts b/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts index 3bdc3a9fad..6d65e82a26 100644 --- a/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts +++ b/packages/twenty-server/src/engine/core-modules/open-api/utils/components.utils.ts @@ -35,7 +35,6 @@ const getFieldProperties = (type: FieldMetadataType): Property => { case FieldMetadataType.NUMBER: return { type: 'integer' }; case FieldMetadataType.NUMERIC: - case FieldMetadataType.PROBABILITY: case FieldMetadataType.RATING: case FieldMetadataType.POSITION: return { type: 'number' }; diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.entity.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.entity.ts index 44cdf69d1d..5a80230f78 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.entity.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/field-metadata.entity.ts @@ -31,7 +31,6 @@ export enum FieldMetadataType { BOOLEAN = 'BOOLEAN', NUMBER = 'NUMBER', NUMERIC = 'NUMERIC', - PROBABILITY = 'PROBABILITY', LINK = 'LINK', LINKS = 'LINKS', CURRENCY = 'CURRENCY', diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface.ts index c78af0480a..f3e24005c7 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface.ts @@ -35,7 +35,6 @@ type FieldMetadataDefaultValueMapping = { [FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber; [FieldMetadataType.POSITION]: FieldMetadataDefaultValueNumber; [FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString; - [FieldMetadataType.PROBABILITY]: FieldMetadataDefaultValueNumber; [FieldMetadataType.LINK]: FieldMetadataDefaultValueLink; [FieldMetadataType.LINKS]: FieldMetadataDefaultValueLinks; [FieldMetadataType.CURRENCY]: FieldMetadataDefaultValueCurrency; diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/__tests__/validate-default-value-based-on-type.spec.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/__tests__/validate-default-value-based-on-type.spec.ts index 757303d4c1..3695a072ec 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/__tests__/validate-default-value-based-on-type.spec.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/__tests__/validate-default-value-based-on-type.spec.ts @@ -78,18 +78,6 @@ describe('validateDefaultValueForType', () => { ).toBe(false); }); - it('should validate number default value for PROBABILITY type', () => { - expect( - validateDefaultValueForType(FieldMetadataType.PROBABILITY, 0.5).isValid, - ).toBe(true); - }); - - it('should return false for invalid number default value for PROBABILITY type', () => { - expect( - validateDefaultValueForType(FieldMetadataType.PROBABILITY, '50%').isValid, - ).toBe(false); - }); - it('should validate boolean default value for BOOLEAN type', () => { expect( validateDefaultValueForType(FieldMetadataType.BOOLEAN, true).isValid, diff --git a/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/validate-default-value-for-type.util.ts b/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/validate-default-value-for-type.util.ts index bb7ec90f86..776c49db65 100644 --- a/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/validate-default-value-for-type.util.ts +++ b/packages/twenty-server/src/engine/metadata-modules/field-metadata/utils/validate-default-value-for-type.util.ts @@ -41,7 +41,6 @@ export const defaultValueValidatorsMap = { [FieldMetadataType.BOOLEAN]: [FieldMetadataDefaultValueBoolean], [FieldMetadataType.NUMBER]: [FieldMetadataDefaultValueNumber], [FieldMetadataType.NUMERIC]: [FieldMetadataDefaultValueString], - [FieldMetadataType.PROBABILITY]: [FieldMetadataDefaultValueNumber], [FieldMetadataType.LINK]: [FieldMetadataDefaultValueLink], [FieldMetadataType.CURRENCY]: [FieldMetadataDefaultValueCurrency], [FieldMetadataType.FULL_NAME]: [FieldMetadataDefaultValueFullName], diff --git a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/factories/basic-column-action.factory.ts b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/factories/basic-column-action.factory.ts index a22048718a..93e38a5966 100644 --- a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/factories/basic-column-action.factory.ts +++ b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/factories/basic-column-action.factory.ts @@ -25,7 +25,6 @@ export type BasicFieldMetadataType = | FieldMetadataType.EMAIL | FieldMetadataType.NUMERIC | FieldMetadataType.NUMBER - | FieldMetadataType.PROBABILITY | FieldMetadataType.BOOLEAN | FieldMetadataType.POSITION | FieldMetadataType.DATE_TIME diff --git a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/utils/field-metadata-type-to-column-type.util.ts b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/utils/field-metadata-type-to-column-type.util.ts index 62e6a7e3e1..5c4f64213b 100644 --- a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/utils/field-metadata-type-to-column-type.util.ts +++ b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/utils/field-metadata-type-to-column-type.util.ts @@ -22,7 +22,6 @@ export const fieldMetadataTypeToColumnType = ( case FieldMetadataType.NUMERIC: return 'numeric'; case FieldMetadataType.NUMBER: - case FieldMetadataType.PROBABILITY: case FieldMetadataType.POSITION: return 'float'; case FieldMetadataType.BOOLEAN: diff --git a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/workspace-migration.factory.ts b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/workspace-migration.factory.ts index 6a62f3b6b6..02dcfe59ac 100644 --- a/packages/twenty-server/src/engine/metadata-modules/workspace-migration/workspace-migration.factory.ts +++ b/packages/twenty-server/src/engine/metadata-modules/workspace-migration/workspace-migration.factory.ts @@ -72,10 +72,6 @@ export class WorkspaceMigrationFactory { [FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }], [FieldMetadataType.POSITION, { factory: this.basicColumnActionFactory }], [FieldMetadataType.RAW_JSON, { factory: this.basicColumnActionFactory }], - [ - FieldMetadataType.PROBABILITY, - { factory: this.basicColumnActionFactory }, - ], [FieldMetadataType.BOOLEAN, { factory: this.basicColumnActionFactory }], [FieldMetadataType.DATE_TIME, { factory: this.basicColumnActionFactory }], [FieldMetadataType.DATE, { factory: this.basicColumnActionFactory }],