The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
[Forms 1/5] Rename record creation from New to Create and keep it pinned (#26419)
Thomas des Francs6ccb99050125
diff --git a/packages/twenty-e2e-testing/tests/create-record.spec.ts b/packages/twenty-e2e-testing/tests/create-record.spec.tsindex cf472af5573..984883b1f5e 100644--- a/packages/twenty-e2e-testing/tests/create-record.spec.ts+++ b/packages/twenty-e2e-testing/tests/create-record.spec.ts@@ -56,7 +56,7 @@ const query = `query FindOnePerson($objectRecordId: UUID!) {test('Create and update record', async ({ page }) => {await page.goto('/objects/people');- await page.getByRole('button', { name: 'Create new Person' }).click();+ await page.getByRole('button', { name: 'Create Person' }).click();// Generate a random email for testingconst randomEmail = `testuser_${Math.random().toString(36).substring(2, 10)}@example.com`;diff --git a/packages/twenty-e2e-testing/tests/workflow-creation.spec.ts b/packages/twenty-e2e-testing/tests/workflow-creation.spec.tsindex 9b88250e403..e3d27450af2 100644--- a/packages/twenty-e2e-testing/tests/workflow-creation.spec.ts+++ b/packages/twenty-e2e-testing/tests/workflow-creation.spec.ts@@ -14,7 +14,7 @@ test('Create workflow', async ({ page }) => {await workflowsLink.click();const createWorkflowButton = page.getByRole('button', {- name: 'Create new workflow',+ name: 'Create Workflow',});const [createWorkflowResponse] = await Promise.all([diff --git a/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx b/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsxindex f563f22d131..ae97b9f64e3 100644--- a/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/contexts/CommandMenuContextProviderContent.tsx@@ -21,6 +21,7 @@ import {} from '@/page-layout/states/currentPageLayoutIdState';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useContext, useMemo } from 'react';+import { isString } from '@sniptt/guards';import {ContextStorePageType,CoreObjectNameSingular,@@ -144,6 +145,9 @@ export const CommandMenuContextProviderContent = ({return mergeGlobalRecordCreationCommandMenuItems({commandMenuItems: contextCommandMenuItems,+ contextObjectMetadataId: isString(currentObjectMetadataItemId)+ ? currentObjectMetadataItemId+ : undefined,globalRecordCreationCommandMenuItems,shouldDisplayGlobalRecordCreationCommands,});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.ts b/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.tsindex 2863ae161e6..6dbb16688d4 100644--- a/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.ts+++ b/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.ts@@ -1,14 +1,17 @@import { type CommandMenuItemDefinition } from '@/command-menu-item/types/CommandMenuItemDefinition';+import { isDefined } from 'twenty-shared/utils';import { EngineComponentKey } from '~/generated-metadata/graphql';export const mergeGlobalRecordCreationCommandMenuItems = ({commandMenuItems,globalRecordCreationCommandMenuItems,shouldDisplayGlobalRecordCreationCommands,+ contextObjectMetadataId,}: {commandMenuItems: CommandMenuItemDefinition[];globalRecordCreationCommandMenuItems: CommandMenuItemDefinition[];shouldDisplayGlobalRecordCreationCommands: boolean;+ contextObjectMetadataId?: string;}): CommandMenuItemDefinition[] => {const sortedCommandMenuItems = [...commandMenuItems].sort((firstItem, secondItem) => firstItem.position - secondItem.position,@@ -18,13 +21,33 @@ export const mergeGlobalRecordCreationCommandMenuItems = ({return sortedCommandMenuItems;}+ const hasCurrentObjectCreationCommand =+ isDefined(contextObjectMetadataId) &&+ globalRecordCreationCommandMenuItems.some(+ (item) => item.creationTargetObjectMetadataId === contextObjectMetadataId,+ );++ const isPinnedContextualCreationCommand = (item: CommandMenuItemDefinition) =>+ hasCurrentObjectCreationCommand &&+ item.engineComponentKey === EngineComponentKey.CREATE_NEW_RECORD &&+ item.isPinned;++ const hasPinnedContextualCreationCommand = sortedCommandMenuItems.some(+ isPinnedContextualCreationCommand,+ );+return [...sortedCommandMenuItems.filter((item) =>- item.engineComponentKey !== EngineComponentKey.CREATE_NEW_RECORD &&- item.engineComponentKey !== EngineComponentKey.NAVIGATION,+ isPinnedContextualCreationCommand(item) ||+ (item.engineComponentKey !== EngineComponentKey.CREATE_NEW_RECORD &&+ item.engineComponentKey !== EngineComponentKey.NAVIGATION),+ ),+ ...globalRecordCreationCommandMenuItems.filter(+ (item) =>+ !hasPinnedContextualCreationCommand ||+ item.creationTargetObjectMetadataId !== contextObjectMetadataId,),- ...globalRecordCreationCommandMenuItems,...sortedCommandMenuItems.filter((item) => item.engineComponentKey === EngineComponentKey.NAVIGATION,),diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.util.spec.ts b/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.util.spec.tsindex 62f4a8f6c2c..c8fcef3ec94 100644--- a/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.util.spec.ts+++ b/packages/twenty-front/src/modules/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems.util.spec.ts@@ -81,3 +81,115 @@ it('preserves object-scoped creation when a missing template disables replacemen}),).toEqual([objectScopedCreationCommand, pageCommand]);});++const pinnedCreationCommand = {+ ...legacyCreationCommand,+ isPinned: true,+ label: 'Create Company',+ shortLabel: 'Create',+ icon: 'IconPlus',+};+const companyCreationCommand = {+ ...globalRecordCreationCommandMenuItems[0],+ isPinned: false,+ label: 'Create Company',+ shortLabel: null,+ icon: 'IconBuildingSkyscraper',+};+const taskCreationCommand = {+ ...globalRecordCreationCommandMenuItems[1],+ isPinned: false,+ label: 'Create Task',+ shortLabel: null,+ icon: 'IconCheckbox',+};+const globalCreationCommands = [companyCreationCommand, taskCreationCommand];++const askAiCommand = {+ ...pageCommand,+ id: 'ask-ai',+ isPinned: true,+ position: 0,+};+const pinnedPageCommand = {+ ...pageCommand,+ id: 'pinned-page',+ isPinned: true,+ position: 5,+};++it('keeps pinned contextual creation at its position and removes its global duplicate', () => {+ const result = mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [pinnedPageCommand, pinnedCreationCommand, askAiCommand],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ contextObjectMetadataId: 'company',+ });++ expect(result).toEqual([+ askAiCommand,+ pinnedCreationCommand,+ pinnedPageCommand,+ taskCreationCommand,+ ]);+});++it('follows the configured order when contextual creation is moved below another pinned command', () => {+ const movedCreationCommand = { ...pinnedCreationCommand, position: 7 };++ expect(+ mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [movedCreationCommand, pinnedPageCommand],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ contextObjectMetadataId: 'company',+ }),+ ).toEqual([pinnedPageCommand, movedCreationCommand, taskCreationCommand]);+});++it('preserves the option to hide the contextual command short label', () => {+ const result = mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [{ ...pinnedCreationCommand, shortLabel: null }],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ contextObjectMetadataId: 'company',+ });++ expect(result[0]).toMatchObject({+ label: 'Create Company',+ shortLabel: null,+ icon: 'IconPlus',+ });+});++it('does not pin creation for an object without a global creation command', () => {+ expect(+ mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [pageCommand, pinnedCreationCommand],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ contextObjectMetadataId: 'person',+ }),+ ).toEqual([pageCommand, ...globalCreationCommands]);+});++it('keeps the current object in global creation when contextual creation is unpinned', () => {+ expect(+ mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [{ ...pinnedCreationCommand, isPinned: false }],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ contextObjectMetadataId: 'company',+ }),+ ).toEqual(globalCreationCommands);+});++it('does not pin creation outside an object context', () => {+ expect(+ mergeGlobalRecordCreationCommandMenuItems({+ commandMenuItems: [pageCommand, pinnedCreationCommand],+ globalRecordCreationCommandMenuItems: globalCreationCommands,+ shouldDisplayGlobalRecordCreationCommands: true,+ }),+ ).toEqual([pageCommand, ...globalCreationCommands]);+});diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordCreationFormProvider.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordCreationFormProvider.tsxindex b32b6ec033d..8c0e343fd1b 100644--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordCreationFormProvider.tsx+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordCreationFormProvider.tsx@@ -146,7 +146,7 @@ export const RecordCreationFormProvider = ({navigateSidePanelMenu({page: SidePanelPages.RecordCreationForm,- pageTitle: t`New ${objectMetadataItem.labelSingular}`,+ pageTitle: t`Create ${objectMetadataItem.labelSingular}`,pageIcon: IconPlus,pageId: requestId,});diff --git a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsxindex b0047984ba8..633446802bf 100644--- a/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx+++ b/packages/twenty-front/src/modules/side-panel/pages/record-creation-form/components/SidePanelRecordCreationFormPage.tsx@@ -1,3 +1,6 @@+import { ObjectMetadataIcon } from '@/object-metadata/components/ObjectMetadataIcon';+import { HeaderIdentifier } from '@/ui/layout/page/components/HeaderIdentifier';+import { PageCardHeader } from '@/ui/layout/page/components/PageCardHeader';import { SIDE_PANEL_FOCUS_ID } from '@/side-panel/constants/SidePanelFocusId';import { currentFocusIdSelector } from '@/ui/utilities/focus/states/currentFocusIdSelector';import { useHotkeysOnFocusedElement } from '@/ui/utilities/hotkey/hooks/useHotkeysOnFocusedElement';@@ -15,7 +18,7 @@ import { recordCreationFormRequestComponentState } from '@/side-panel/pages/recoimport { SidePanelFooter } from '@/ui/layout/side-panel/components/SidePanelFooter';import { useAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';-import { useState } from 'react';+import { useContext, useState } from 'react';import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';import { Key } from 'ts-key-enum';@@ -23,7 +26,7 @@ import { type JsonValue } from 'type-fest';import { isDefined } from 'twenty-shared/utils';import { IconPlus } from 'twenty-ui/icon';import { Button } from 'twenty-ui/primitives/input';-import { themeCssVariables } from 'twenty-ui/theme-constants';+import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants';import { getOsControlSymbol } from 'twenty-ui/utilities';const StyledContainer = styled.div`@@ -73,6 +76,7 @@ const SidePanelRecordCreationForm = ({});const { objectMetadataItems } = useObjectMetadataItems();+ const { theme } = useContext(ThemeContext);const { settleRecordCreationDraft } = useRecordCreationFormSettle();const { goBackFromSidePanel } = useSidePanelHistory();@@ -129,6 +133,20 @@ const SidePanelRecordCreationForm = ({return (<StyledContainer ref={containerRef}>+ <PageCardHeader+ title={+ <HeaderIdentifier+ icon={+ <ObjectMetadataIcon+ objectMetadataItem={objectMetadataItem}+ size={theme.icon.size.md}+ stroke={theme.icon.stroke.sm}+ />+ }+ title={t`Create ${objectMetadataItem.labelSingular}`}+ />+ }+ /><StyledContent><RecordFormFieldInputsobjectMetadataItem={objectMetadataItem}diff --git a/packages/twenty-front/src/testing/mock-data/generated/metadata/command-menu-items/mock-command-menu-items-data.ts b/packages/twenty-front/src/testing/mock-data/generated/metadata/command-menu-items/mock-command-menu-items-data.tsindex c34384269ff..6d6800dfe99 100644--- a/packages/twenty-front/src/testing/mock-data/generated/metadata/command-menu-items/mock-command-menu-items-data.ts+++ b/packages/twenty-front/src/testing/mock-data/generated/metadata/command-menu-items/mock-command-menu-items-data.ts@@ -68,9 +68,9 @@ export const mockedCommandMenuItems: CommandMenuItemFieldsFragment[] ="pageLayoutId": null,"isActive": true,"frontComponent": null,- "label": "Create new {objectLabelSingular}",+ "label": "Create {objectLabelSingular}","icon": "IconPlus",- "shortLabel": "New {objectLabelSingular}",+ "shortLabel": "Create","navigationTargetObjectMetadataId": null},{@@ -1536,9 +1536,9 @@ export const mockedCommandMenuItems: CommandMenuItemFieldsFragment[] ="pageLayoutId": null,"isActive": true,"frontComponent": null,- "label": "Create new Campaign",+ "label": "Create Campaign","icon": "IconPlus",- "shortLabel": "New Campaign",+ "shortLabel": "Create","navigationTargetObjectMetadataId": null},{diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-upgrade-version-command.module.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-upgrade-version-command.module.tsindex 27a80df78cd..5b02c72dc90 100644--- a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-upgrade-version-command.module.ts+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-upgrade-version-command.module.ts@@ -24,6 +24,7 @@ import { WorkspaceMigrationRunnerModule } from 'src/engine/workspace-manager/worimport { WorkspaceMigrationModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration.module';import { WorkspaceSchemaMigrationRunnerActionHandlersModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-runner/action-handlers/workspace-schema-migration-runner-action-handlers.module';import { GateWorkflowFavoritesByCoreIndexFlagCommand } from 'src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1789981200000-gate-workflow-favorites-by-core-index-flag.command';+import { UpdateRecordCreationCommandLabelsCommand } from 'src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1790115314731-update-record-creation-command-labels.command';@Module({imports: [@@ -40,6 +41,7 @@ import { GateWorkflowFavoritesByCoreIndexFlagCommand } from 'src/database/commanWorkspaceSchemaMigrationRunnerActionHandlersModule,],providers: [+ UpdateRecordCreationCommandLabelsCommand,GateWorkflowFavoritesByCoreIndexFlagCommand,MigrateAgentHistoryToWorkspaceCommand,UnpinCreationCommandsOnRecordSelectionCommand,diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1790115314731-update-record-creation-command-labels.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1790115314731-update-record-creation-command-labels.command.tsnew file mode 100644index 00000000000..762cc6e9605--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1790115314731-update-record-creation-command-labels.command.ts@@ -0,0 +1,77 @@+import { Command } from 'nest-commander';+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';+import { isNonEmptyArray } from 'twenty-shared/utils';++import { ProvisionedWorkspaceCommandRunner } from 'src/database/commands/command-runners/provisioned-workspace.command-runner';+import { WorkspaceIteratorService } from 'src/database/commands/command-runners/workspace-iterator.service';+import { type RunOnWorkspaceArgs } from 'src/database/commands/command-runners/workspace.command-runner';+import { buildRecordCreationCommandLabelUpdates } from 'src/database/commands/upgrade-version-command/2-42/utils/build-record-creation-command-label-updates.util';+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';+import { WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';+import { WorkspaceMigrationBuilderException } from 'src/engine/workspace-manager/workspace-migration/exceptions/workspace-migration-builder-exception';+import { WorkspaceMigrationValidateBuildAndRunService } from 'src/engine/workspace-manager/workspace-migration/services/workspace-migration-validate-build-and-run-service';++@RegisteredWorkspaceCommand('2.42.0', 1790115314731)+@Command({+ name: 'upgrade:2-42:update-record-creation-command-labels',+ description:+ 'Update the standard record creation command labels in existing workspaces',+})+export class UpdateRecordCreationCommandLabelsCommand extends ProvisionedWorkspaceCommandRunner {+ constructor(+ protected readonly workspaceIteratorService: WorkspaceIteratorService,+ private readonly workspaceCacheService: WorkspaceCacheService,+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,+ ) {+ super(workspaceIteratorService);+ }++ override async runOnWorkspace({+ workspaceId,+ options,+ }: RunOnWorkspaceArgs): Promise<void> {+ const { flatCommandMenuItemMaps } =+ await this.workspaceCacheService.getOrRecompute(workspaceId, [+ 'flatCommandMenuItemMaps',+ ]);++ const commandMenuItemsToUpdate = buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier:+ flatCommandMenuItemMaps.byUniversalIdentifier,+ now: new Date().toISOString(),+ });++ if (!isNonEmptyArray(commandMenuItemsToUpdate)) {+ return;+ }++ if (options.dryRun) {+ this.logger.log(+ `[DRY RUN] Workspace ${workspaceId}: record creation command labels would be updated`,+ );++ return;+ }++ const validateAndBuildResult =+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(+ {+ isSystemBuild: true,+ workspaceId,+ applicationUniversalIdentifier:+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,+ allFlatEntityOperationByMetadataName: {+ commandMenuItem: {+ flatEntityToCreate: [],+ flatEntityToDelete: [],+ flatEntityToUpdate: commandMenuItemsToUpdate,+ },+ },+ },+ );++ if (validateAndBuildResult.status === 'fail') {+ throw new WorkspaceMigrationBuilderException(validateAndBuildResult);+ }+ }+}diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/__tests__/build-record-creation-command-label-updates.util.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/__tests__/build-record-creation-command-label-updates.util.spec.tsnew file mode 100644index 00000000000..23d0130ecd1--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/__tests__/build-record-creation-command-label-updates.util.spec.ts@@ -0,0 +1,125 @@+import { buildRecordCreationCommandLabelUpdates } from 'src/database/commands/upgrade-version-command/2-42/utils/build-record-creation-command-label-updates.util';+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';+import { STANDARD_COMMAND_MENU_ITEMS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant';++const NOW = '2026-09-23T00:00:00.000Z';++const { universalIdentifier: CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER } =+ STANDARD_COMMAND_MENU_ITEMS.createNewRecord;++const { universalIdentifier: COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER } =+ STANDARD_COMMAND_MENU_ITEMS.composeCampaignPinned;++const FORMER_LABELS = {+ label: 'Create new {objectLabelSingular}',+ shortLabel: 'New {objectLabelSingular}',+};++const CURRENT_LABELS = {+ label: 'Create {objectLabelSingular}',+ shortLabel: 'Create',+};++const buildExistingItems = ({+ label,+ shortLabel,+}: {+ label: string;+ shortLabel: string | null;+}): Record<string, FlatCommandMenuItem> => ({+ [CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER]: {+ universalIdentifier: CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER,+ label,+ shortLabel,+ updatedAt: '2025-01-01T00:00:00.000Z',+ } as FlatCommandMenuItem,+});++describe('buildRecordCreationCommandLabelUpdates', () => {+ it('renames the former standard labels', () => {+ const updates = buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier:+ buildExistingItems(FORMER_LABELS),+ now: NOW,+ });++ expect(updates).toEqual([+ expect.objectContaining({ ...CURRENT_LABELS, updatedAt: NOW }),+ ]);+ });++ it('renames the former campaign creation labels', () => {+ const updates = buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier: {+ [COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER]: {+ universalIdentifier: COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER,+ label: 'Create new Campaign',+ shortLabel: 'New Campaign',+ updatedAt: '2025-01-01T00:00:00.000Z',+ } as FlatCommandMenuItem,+ },+ now: NOW,+ });++ expect(updates).toEqual([+ expect.objectContaining({+ label: 'Create Campaign',+ shortLabel: 'Create',+ updatedAt: NOW,+ }),+ ]);+ });++ it.each([null, 'Add'])(+ 'preserves a hidden or customized short label (%s)',+ (shortLabel) => {+ const updates = buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier: buildExistingItems({+ label: FORMER_LABELS.label,+ shortLabel,+ }),+ now: NOW,+ });++ expect(updates).toEqual([+ expect.objectContaining({ label: CURRENT_LABELS.label, shortLabel }),+ ]);+ },+ );++ it('preserves a customized label while renaming the former short label', () => {+ const updates = buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier: buildExistingItems({+ label: 'Add a customer',+ shortLabel: FORMER_LABELS.shortLabel,+ }),+ now: NOW,+ });++ expect(updates).toEqual([+ expect.objectContaining({+ label: 'Add a customer',+ shortLabel: CURRENT_LABELS.shortLabel,+ }),+ ]);+ });++ it('returns nothing when the labels are already current', () => {+ expect(+ buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier:+ buildExistingItems(CURRENT_LABELS),+ now: NOW,+ }),+ ).toEqual([]);+ });++ it('returns nothing when the standard command is absent', () => {+ expect(+ buildRecordCreationCommandLabelUpdates({+ flatCommandMenuItemByUniversalIdentifier: {},+ now: NOW,+ }),+ ).toEqual([]);+ });+});diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-record-creation-command-label-updates.util.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-record-creation-command-label-updates.util.tsnew file mode 100644index 00000000000..36925ebae0b--- /dev/null+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-record-creation-command-label-updates.util.ts@@ -0,0 +1,74 @@+import { isDefined } from 'twenty-shared/utils';++import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';+import { STANDARD_COMMAND_MENU_ITEMS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant';++const RECORD_CREATION_COMMAND_LABEL_RENAMES = [+ {+ universalIdentifier:+ STANDARD_COMMAND_MENU_ITEMS.createNewRecord.universalIdentifier,+ formerLabels: {+ label: 'Create new {objectLabelSingular}',+ shortLabel: 'New {objectLabelSingular}',+ },+ currentLabels: {+ label: 'Create {objectLabelSingular}',+ shortLabel: 'Create',+ },+ },+ {+ universalIdentifier:+ STANDARD_COMMAND_MENU_ITEMS.composeCampaignPinned.universalIdentifier,+ formerLabels: {+ label: 'Create new Campaign',+ shortLabel: 'New Campaign',+ },+ currentLabels: {+ label: 'Create Campaign',+ shortLabel: 'Create',+ },+ },+];++export const buildRecordCreationCommandLabelUpdates = ({+ flatCommandMenuItemByUniversalIdentifier,+ now,+}: {+ flatCommandMenuItemByUniversalIdentifier: Record<+ string,+ FlatCommandMenuItem | undefined+ >;+ now: string;+}): FlatCommandMenuItem[] =>+ RECORD_CREATION_COMMAND_LABEL_RENAMES.flatMap(+ ({ universalIdentifier, formerLabels, currentLabels }) => {+ const existingCommandMenuItem =+ flatCommandMenuItemByUniversalIdentifier[universalIdentifier];++ if (!isDefined(existingCommandMenuItem)) {+ return [];+ }++ const shouldUpdateLabel =+ existingCommandMenuItem.label === formerLabels.label;+ const shouldUpdateShortLabel =+ existingCommandMenuItem.shortLabel === formerLabels.shortLabel;++ if (!shouldUpdateLabel && !shouldUpdateShortLabel) {+ return [];+ }++ return [+ {+ ...existingCommandMenuItem,+ label: shouldUpdateLabel+ ? currentLabels.label+ : existingCommandMenuItem.label,+ shortLabel: shouldUpdateShortLabel+ ? currentLabels.shortLabel+ : existingCommandMenuItem.shortLabel,+ updatedAt: now,+ },+ ];+ },+ );diff --git a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.tsindex 340c0451e9a..7c125246b63 100644--- a/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts+++ b/packages/twenty-server/src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant.ts@@ -50,7 +50,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {universalIdentifier: '08d255bf-58cd-47a5-bd82-78c5c58592f1',label: i18nLabel(msg({- message: `Create new {objectLabelSingular}`,+ message: `Create {objectLabelSingular}`,context: 'commandMenuItem.label',}),),@@ -59,7 +59,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {position: 3,shortLabel: i18nLabel(msg({- message: `New {objectLabelSingular}`,+ message: `Create`,context: 'commandMenuItem.shortLabel',}),),@@ -945,13 +945,13 @@ export const STANDARD_COMMAND_MENU_ITEMS = {composeCampaignPinned: {universalIdentifier: '7ad6f0c7-ac02-4062-b5cf-1f36e1664bc8',label: i18nLabel(- msg({ message: `Create new Campaign`, context: 'commandMenuItem.label' }),+ msg({ message: `Create Campaign`, context: 'commandMenuItem.label' }),),icon: 'IconPlus',isPinned: true,position: 67,shortLabel: i18nLabel(- msg({ message: `New Campaign`, context: 'commandMenuItem.shortLabel' }),+ msg({ message: `Create`, context: 'commandMenuItem.shortLabel' }),),availabilityType: CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT,conditionalAvailabilityExpression:diff --git a/packages/twenty-server/test/integration/upgrade/suites/2-42-workspace-command-1790115314731-update-record-creation-command-labels.integration-spec.ts b/packages/twenty-server/test/integration/upgrade/suites/2-42-workspace-command-1790115314731-update-record-creation-command-labels.integration-spec.tsnew file mode 100644index 00000000000..6119e0e79fb--- /dev/null+++ b/packages/twenty-server/test/integration/upgrade/suites/2-42-workspace-command-1790115314731-update-record-creation-command-labels.integration-spec.ts@@ -0,0 +1,158 @@+import { getAppProviderByClassName } from 'test/integration/utils/get-app-provider-by-class-name.util';+import { getCoreRepository } from 'test/integration/utils/get-core-repository.util';++import { type UpdateRecordCreationCommandLabelsCommand } from 'src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1790115314731-update-record-creation-command-labels.command';+import { CommandMenuItemEntity } from 'src/engine/metadata-modules/command-menu-item/entities/command-menu-item.entity';+import { buildSystemAuthContext } from 'src/engine/twenty-orm/utils/build-system-auth-context.util';+import { WorkspaceOrmManager } from 'src/engine/twenty-orm/workspace-orm.manager';+import { type WorkspaceCacheService } from 'src/engine/workspace-cache/services/workspace-cache.service';+import { SEED_APPLE_WORKSPACE_ID } from 'src/engine/workspace-manager/dev-seeder/core/constants/seeder-workspaces.constant';+import { STANDARD_COMMAND_MENU_ITEMS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant';++const authContext = buildSystemAuthContext(SEED_APPLE_WORKSPACE_ID);++const { universalIdentifier: CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER } =+ STANDARD_COMMAND_MENU_ITEMS.createNewRecord;++const { universalIdentifier: COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER } =+ STANDARD_COMMAND_MENU_ITEMS.composeCampaignPinned;++const FORMER_LABELS = {+ label: 'Create new {objectLabelSingular}',+ shortLabel: 'New {objectLabelSingular}',+};++const CURRENT_LABELS = {+ label: 'Create {objectLabelSingular}',+ shortLabel: 'Create',+};++const FORMER_CAMPAIGN_LABELS = {+ label: 'Create new Campaign',+ shortLabel: 'New Campaign',+};++const CURRENT_CAMPAIGN_LABELS = {+ label: 'Create Campaign',+ shortLabel: 'Create',+};++type CommandMenuItemLabels = {+ label: string;+ shortLabel: string | null;+};++describe('2-42 workspace command 1790115314731 - UpdateRecordCreationCommandLabelsCommand (integration)', () => {+ let command: UpdateRecordCreationCommandLabelsCommand;+ let workspaceOrmManager: WorkspaceOrmManager;++ const runCommand = ({ dryRun = false }: { dryRun?: boolean } = {}) =>+ workspaceOrmManager.executeInWorkspaceContext(+ () =>+ command.runOnWorkspace({+ workspaceId: SEED_APPLE_WORKSPACE_ID,+ options: { dryRun },+ index: 0,+ total: 1,+ }),+ authContext,+ );++ const setLabels = async (+ labelsByUniversalIdentifier: Record<string, CommandMenuItemLabels>,+ ) => {+ for (const [universalIdentifier, labels] of Object.entries(+ labelsByUniversalIdentifier,+ )) {+ await getCoreRepository<CommandMenuItemEntity>(+ CommandMenuItemEntity,+ ).update(+ { universalIdentifier, workspaceId: SEED_APPLE_WORKSPACE_ID },+ labels,+ );+ }++ await getAppProviderByClassName<WorkspaceCacheService>(+ 'WorkspaceCacheService',+ ).invalidateAndRecompute(SEED_APPLE_WORKSPACE_ID, [+ 'flatCommandMenuItemMaps',+ ]);+ };++ const findLabels = async (universalIdentifier: string) => {+ const { label, shortLabel } =+ await getCoreRepository<CommandMenuItemEntity>(+ CommandMenuItemEntity,+ ).findOneOrFail({+ where: { universalIdentifier, workspaceId: SEED_APPLE_WORKSPACE_ID },+ });++ return { label, shortLabel };+ };++ beforeAll(() => {+ command =+ getAppProviderByClassName<UpdateRecordCreationCommandLabelsCommand>(+ 'UpdateRecordCreationCommandLabelsCommand',+ );+ workspaceOrmManager = getAppProviderByClassName<WorkspaceOrmManager>(+ 'WorkspaceOrmManager',+ );+ });++ afterAll(async () => {+ await setLabels({+ [CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER]: CURRENT_LABELS,+ [COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER]: CURRENT_CAMPAIGN_LABELS,+ });+ });++ it('keeps the former labels on a dry run', async () => {+ await setLabels({+ [CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER]: FORMER_LABELS,+ [COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER]: FORMER_CAMPAIGN_LABELS,+ });++ await runCommand({ dryRun: true });++ expect(await findLabels(CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER)).toEqual(+ FORMER_LABELS,+ );+ expect(await findLabels(COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER)).toEqual(+ FORMER_CAMPAIGN_LABELS,+ );+ });++ it('renames the former labels and is a no-op on a second run', async () => {+ await setLabels({+ [CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER]: FORMER_LABELS,+ [COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER]: FORMER_CAMPAIGN_LABELS,+ });++ await runCommand();+ await runCommand();++ expect(await findLabels(CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER)).toEqual(+ CURRENT_LABELS,+ );+ expect(await findLabels(COMPOSE_CAMPAIGN_UNIVERSAL_IDENTIFIER)).toEqual(+ CURRENT_CAMPAIGN_LABELS,+ );+ });++ it('keeps a customized short label', async () => {+ await setLabels({+ [CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER]: {+ label: FORMER_LABELS.label,+ shortLabel: 'Add',+ },+ });++ await runCommand();++ expect(await findLabels(CREATE_NEW_RECORD_UNIVERSAL_IDENTIFIER)).toEqual({+ label: CURRENT_LABELS.label,+ shortLabel: 'Add',+ });+ });+});