From 04bf697b2530dde48ef102405f178fc703978af3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tha=C3=AFs?= Date: Wed, 22 May 2024 18:06:32 +0200 Subject: [PATCH] feat: add feature flag to activate Links field creation (#5535) Related issue: #3607 --- .../modules/workspace/types/FeatureFlagKey.ts | 3 ++- .../SettingsObjectNewFieldStep2.tsx | 26 ++++++++++++------- .../src/testing/mock-data/users.ts | 6 +++++ .../typeorm-seeds/core/feature-flags.ts | 5 ++++ .../feature-flag/feature-flag.entity.ts | 1 + .../commands/add-standard-id.command.ts | 2 ++ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts b/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts index cb6262c2d008..ffbb483ca9b5 100644 --- a/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts +++ b/packages/twenty-front/src/modules/workspace/types/FeatureFlagKey.ts @@ -4,4 +4,5 @@ export type FeatureFlagKey = | 'IS_EVENT_OBJECT_ENABLED' | 'IS_AIRTABLE_INTEGRATION_ENABLED' | 'IS_POSTGRESQL_INTEGRATION_ENABLED' - | 'IS_STRIPE_INTEGRATION_ENABLED'; + | 'IS_STRIPE_INTEGRATION_ENABLED' + | 'IS_LINKS_FIELD_ENABLED'; 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 f148217c3162..dce0de098792 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 @@ -31,7 +31,9 @@ import { Section } from '@/ui/layout/section/components/Section'; import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb'; import { View } from '@/views/types/View'; import { ViewType } from '@/views/types/ViewType'; +import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; import { FieldMetadataType } from '~/generated-metadata/graphql'; +import { isDefined } from '~/utils/isDefined'; import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull'; type SettingsDataModelNewFieldFormValues = z.infer< @@ -109,6 +111,8 @@ export const SettingsObjectNewFieldStep2 = () => { const { createOneRelationMetadataItem: createOneRelationMetadata } = useCreateOneRelationMetadataItem(); + const isLinksFieldEnabled = useIsFeatureEnabled('IS_LINKS_FIELD_ENABLED'); + if (!activeObjectMetadataItem) return null; const canSave = @@ -263,16 +267,18 @@ export const SettingsObjectNewFieldStep2 = () => { } }; - const excludedFieldTypes: SettingsSupportedFieldType[] = [ - FieldMetadataType.Email, - FieldMetadataType.FullName, - FieldMetadataType.Link, - FieldMetadataType.Links, - FieldMetadataType.Numeric, - FieldMetadataType.Probability, - FieldMetadataType.Uuid, - FieldMetadataType.Phone, - ]; + const excludedFieldTypes: SettingsSupportedFieldType[] = ( + [ + FieldMetadataType.Email, + FieldMetadataType.FullName, + FieldMetadataType.Link, + isLinksFieldEnabled ? undefined : FieldMetadataType.Links, + FieldMetadataType.Numeric, + FieldMetadataType.Probability, + FieldMetadataType.Uuid, + FieldMetadataType.Phone, + ] as const + ).filter(isDefined); return ( // eslint-disable-next-line react/jsx-props-no-spreading diff --git a/packages/twenty-front/src/testing/mock-data/users.ts b/packages/twenty-front/src/testing/mock-data/users.ts index f3e1238f12fa..d9a3dd43de6d 100644 --- a/packages/twenty-front/src/testing/mock-data/users.ts +++ b/packages/twenty-front/src/testing/mock-data/users.ts @@ -50,6 +50,12 @@ export const mockDefaultWorkspace: Workspace = { value: true, workspaceId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6w', }, + { + id: '1492de61-5018-4368-8923-4f1eeaf988c7', + key: 'IS_LINKS_FIELD_ENABLED', + value: true, + workspaceId: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6w', + }, ], createdAt: '2023-04-26T10:23:42.33625+00:00', updatedAt: '2023-04-26T10:23:42.33625+00:00', diff --git a/packages/twenty-server/src/database/typeorm-seeds/core/feature-flags.ts b/packages/twenty-server/src/database/typeorm-seeds/core/feature-flags.ts index 7a14e511744f..b75c3d6514cd 100644 --- a/packages/twenty-server/src/database/typeorm-seeds/core/feature-flags.ts +++ b/packages/twenty-server/src/database/typeorm-seeds/core/feature-flags.ts @@ -45,6 +45,11 @@ export const seedFeatureFlags = async ( workspaceId: workspaceId, value: true, }, + { + key: FeatureFlagKeys.IsLinksFieldEnabled, + workspaceId: workspaceId, + value: true, + }, ]) .execute(); }; diff --git a/packages/twenty-server/src/engine/core-modules/feature-flag/feature-flag.entity.ts b/packages/twenty-server/src/engine/core-modules/feature-flag/feature-flag.entity.ts index 1e0fca487149..b4df67d205bb 100644 --- a/packages/twenty-server/src/engine/core-modules/feature-flag/feature-flag.entity.ts +++ b/packages/twenty-server/src/engine/core-modules/feature-flag/feature-flag.entity.ts @@ -22,6 +22,7 @@ export enum FeatureFlagKeys { IsPostgreSQLIntegrationEnabled = 'IS_POSTGRESQL_INTEGRATION_ENABLED', IsStripeIntegrationEnabled = 'IS_STRIPE_INTEGRATION_ENABLED', IsGmailSyncV2Enabled = 'IS_GMAIL_SYNC_V2_ENABLED', + IsLinksFieldEnabled = 'IS_LINKS_FIELD_ENABLED', } @Entity({ name: 'featureFlag', schema: 'core' }) diff --git a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts index 81a55686f35e..8a4043c14291 100644 --- a/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts +++ b/packages/twenty-server/src/engine/workspace-manager/workspace-sync-metadata/commands/add-standard-id.command.ts @@ -59,6 +59,7 @@ export class AddStandardIdCommand extends CommandRunner { IS_POSTGRESQL_INTEGRATION_ENABLED: true, IS_STRIPE_INTEGRATION_ENABLED: false, IS_GMAIL_SYNC_V2_ENABLED: true, + IS_LINKS_FIELD_ENABLED: true, }, ); const standardFieldMetadataCollection = this.standardFieldFactory.create( @@ -74,6 +75,7 @@ export class AddStandardIdCommand extends CommandRunner { IS_POSTGRESQL_INTEGRATION_ENABLED: true, IS_STRIPE_INTEGRATION_ENABLED: false, IS_GMAIL_SYNC_V2_ENABLED: true, + IS_LINKS_FIELD_ENABLED: true, }, );