Skip to content

The open alternative to Salesforce, designed for AI.

Hide workflows from side panel search and favorites when the core index flag is on (#26323)

Thomas Trompette3c59749f7ec5
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildOptimisticNavigationMenuItem.test.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildOptimisticNavigationMenuItem.test.ts
index 167b918bdc2..8258f236b23 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildOptimisticNavigationMenuItem.test.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/buildOptimisticNavigationMenuItem.test.ts
@@ -14,8 +14,8 @@ describe('buildOptimisticNavigationMenuItem', () => {
expect(optimisticItem.pageLayoutId).toBe(
'0a0be2ee-2f5f-4a5a-b1e5-1b5c8e3a4f21',
);
- expect(filterAndSortNavigationMenuItems([optimisticItem], [], [])).toEqual([
- optimisticItem,
- ]);
+ expect(
+ filterAndSortNavigationMenuItems([optimisticItem], [], [], false),
+ ).toEqual([optimisticItem]);
});
});
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/filterAndSortNavigationMenuItems.test.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/filterAndSortNavigationMenuItems.test.ts
index 78b6ac052b7..0308fdf64b3 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/filterAndSortNavigationMenuItems.test.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/__tests__/filterAndSortNavigationMenuItems.test.ts
@@ -22,8 +22,68 @@ describe('filterAndSortNavigationMenuItems', () => {
key: ViewKey.INDEX,
};
+ const mockWorkflowObjectMetadataItem = {
+ id: 'workflow-metadata-id',
+ nameSingular: 'workflow',
+ namePlural: 'workflows',
+ labelPlural: 'Workflows',
+ icon: 'IconSettingsAutomation',
+ isActive: true,
+ } as EnrichedObjectMetadataItem;
+
+ const workflowRecordItem = {
+ id: 'workflow-favorite-id',
+ type: NavigationMenuItemType.RECORD,
+ position: 0,
+ targetRecordId: 'workflow-record-id',
+ targetObjectMetadataId: 'workflow-metadata-id',
+ targetRecordIdentifier: { id: 'workflow-record-id', name: 'My workflow' },
+ } as unknown as NavigationMenuItem;
+
+ it('hides workflow record items when the workflow core index page is enabled', () => {
+ expect(
+ filterAndSortNavigationMenuItems(
+ [workflowRecordItem],
+ [],
+ [mockWorkflowObjectMetadataItem],
+ true,
+ ),
+ ).toEqual([]);
+ });
+
+ it('keeps workflow record items when the workflow core index page is disabled', () => {
+ expect(
+ filterAndSortNavigationMenuItems(
+ [workflowRecordItem],
+ [],
+ [mockWorkflowObjectMetadataItem],
+ false,
+ ),
+ ).toEqual([workflowRecordItem]);
+ });
+
+ it('keeps other objects record items when the workflow core index page is enabled', () => {
+ const personRecordItem = {
+ id: 'person-favorite-id',
+ type: NavigationMenuItemType.RECORD,
+ position: 0,
+ targetRecordId: 'person-record-id',
+ targetObjectMetadataId: 'metadata-id',
+ targetRecordIdentifier: { id: 'person-record-id', name: 'Jane' },
+ } as unknown as NavigationMenuItem;
+
+ expect(
+ filterAndSortNavigationMenuItems(
+ [personRecordItem],
+ [],
+ [mockObjectMetadataItem],
+ true,
+ ),
+ ).toEqual([personRecordItem]);
+ });
+
it('should return empty array when navigationMenuItems is empty', () => {
- const result = filterAndSortNavigationMenuItems([], [], []);
+ const result = filterAndSortNavigationMenuItems([], [], [], false);
expect(result).toEqual([]);
});
@@ -39,6 +99,7 @@ describe('filterAndSortNavigationMenuItems', () => {
[navigationMenuItem],
[mockView],
[mockObjectMetadataItem],
+ false,
);
expect(result).toHaveLength(1);
@@ -57,6 +118,7 @@ describe('filterAndSortNavigationMenuItems', () => {
[navigationMenuItem],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
@@ -79,6 +141,7 @@ describe('filterAndSortNavigationMenuItems', () => {
[navigationMenuItem],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toHaveLength(1);
@@ -97,6 +160,7 @@ describe('filterAndSortNavigationMenuItems', () => {
[navigationMenuItem],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
@@ -119,6 +183,7 @@ describe('filterAndSortNavigationMenuItems', () => {
[navigationMenuItem],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
@@ -165,6 +230,7 @@ describe('filterAndSortNavigationMenuItems', () => {
navigationMenuItems,
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toHaveLength(3);
@@ -186,6 +252,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[],
[],
+ false,
);
expect(result).toHaveLength(1);
expect(result[0].id).toBe('link-1');
@@ -203,6 +270,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toHaveLength(1);
expect(result[0].id).toBe('obj-1');
@@ -220,6 +288,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[],
[mockObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
});
@@ -242,6 +311,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[],
[inactiveObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
});
@@ -271,6 +341,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[viewForInactiveObject],
[inactiveObjectMetadataItem],
+ false,
);
expect(result).toEqual([]);
});
@@ -287,6 +358,7 @@ describe('filterAndSortNavigationMenuItems', () => {
],
[],
[],
+ false,
);
expect(result).toHaveLength(1);
expect(result[0].id).toBe('folder-1');
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems.ts b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems.ts
index 92d89ea5bd1..21c630968fb 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems.ts
@@ -1,18 +1,35 @@
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
import { type View } from '@/views/types/View';
-import { NavigationMenuItemType } from 'twenty-shared/types';
+import {
+ CoreObjectNameSingular,
+ NavigationMenuItemType,
+} from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { type NavigationMenuItem } from '~/generated-metadata/graphql';
export const filterAndSortNavigationMenuItems = (
navigationMenuItems: NavigationMenuItem[],
views: Pick<View, 'id' | 'objectMetadataId' | 'key'>[],
- objectMetadataItems: Pick<EnrichedObjectMetadataItem, 'id' | 'isActive'>[],
+ objectMetadataItems: Pick<
+ EnrichedObjectMetadataItem,
+ 'id' | 'isActive' | 'nameSingular'
+ >[],
+ isWorkflowCoreIndexPageEnabled: boolean,
): NavigationMenuItem[] => {
const activeObjectMetadataItems = objectMetadataItems.filter(
(meta) => meta.isActive,
);
+ const hiddenRecordObjectMetadataIds = new Set(
+ isWorkflowCoreIndexPageEnabled
+ ? activeObjectMetadataItems
+ .filter(
+ (meta) => meta.nameSingular === CoreObjectNameSingular.Workflow,
+ )
+ .map((meta) => meta.id)
+ : [],
+ );
+
return navigationMenuItems
.filter((item) => {
if (item.type === NavigationMenuItemType.FOLDER) {
@@ -49,6 +66,7 @@ export const filterAndSortNavigationMenuItems = (
isDefined(item.targetRecordId) &&
isDefined(item.targetObjectMetadataId) &&
isDefined(item.targetRecordIdentifier) &&
+ !hiddenRecordObjectMetadataIds.has(item.targetObjectMetadataId) &&
activeObjectMetadataItems.some(
(meta) => meta.id === item.targetObjectMetadataId,
)
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/folder/hooks/useNavigationMenuItemsByFolder.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/folder/hooks/useNavigationMenuItemsByFolder.ts
index a1a013c36f4..b7bb821bf6d 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/folder/hooks/useNavigationMenuItemsByFolder.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/folder/hooks/useNavigationMenuItemsByFolder.ts
@@ -4,6 +4,7 @@ import { type NavigationMenuItem } from '~/generated-metadata/graphql';
import { filterAndSortNavigationMenuItems } from '@/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems';
import { isNavigationMenuItemFolder } from '@/navigation-menu-item/common/utils/isNavigationMenuItemFolder';
import { useNavigationObjectMetadataItems } from '@/navigation-menu-item/common/hooks/useNavigationObjectMetadataItems';
+import { useIsWorkflowCoreEnabled } from '@/workflow/hooks/useIsWorkflowCoreEnabled';
import { viewsSelector } from '@/views/states/selectors/viewsSelector';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
@@ -25,6 +26,7 @@ type NavigationMenuItemFolderEntry = Pick<
export const useNavigationMenuItemsByFolder = () => {
const views = useAtomStateValue(viewsSelector);
const objectMetadataItems = useNavigationObjectMetadataItems();
+ const isWorkflowCoreEnabled = useIsWorkflowCoreEnabled();
const { navigationMenuItems, workspaceNavigationMenuItems } =
useNavigationMenuItemsData();
@@ -87,6 +89,7 @@ export const useNavigationMenuItemsByFolder = () => {
itemsInFolder,
views,
objectMetadataItems,
+ isWorkflowCoreEnabled,
);
acc.push({
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useSortedNavigationMenuItems.ts b/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useSortedNavigationMenuItems.ts
index a10c795725f..79558665c47 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useSortedNavigationMenuItems.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/display/hooks/useSortedNavigationMenuItems.ts
@@ -2,6 +2,7 @@ import { useMemo } from 'react';
import { filterAndSortNavigationMenuItems } from '@/navigation-menu-item/common/utils/filterAndSortNavigationMenuItems';
import { useNavigationObjectMetadataItems } from '@/navigation-menu-item/common/hooks/useNavigationObjectMetadataItems';
+import { useIsWorkflowCoreEnabled } from '@/workflow/hooks/useIsWorkflowCoreEnabled';
import { viewsSelector } from '@/views/states/selectors/viewsSelector';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
@@ -12,22 +13,30 @@ export const useSortedNavigationMenuItems = () => {
useNavigationMenuItemsData();
const views = useAtomStateValue(viewsSelector);
const objectMetadataItems = useNavigationObjectMetadataItems();
+ const isWorkflowCoreEnabled = useIsWorkflowCoreEnabled();
const navigationMenuItemsSorted = useMemo(() => {
return filterAndSortNavigationMenuItems(
navigationMenuItems,
views,
objectMetadataItems,
+ isWorkflowCoreEnabled,
);
- }, [navigationMenuItems, views, objectMetadataItems]);
+ }, [navigationMenuItems, views, objectMetadataItems, isWorkflowCoreEnabled]);
const workspaceNavigationMenuItemsSorted = useMemo(() => {
return filterAndSortNavigationMenuItems(
workspaceNavigationMenuItems,
views,
objectMetadataItems,
+ isWorkflowCoreEnabled,
);
- }, [workspaceNavigationMenuItems, views, objectMetadataItems]);
+ }, [
+ workspaceNavigationMenuItems,
+ views,
+ objectMetadataItems,
+ isWorkflowCoreEnabled,
+ ]);
return {
navigationMenuItemsSorted,
diff --git a/packages/twenty-front/src/modules/navigation-menu-item/edit/hooks/useNavigationMenuItemSearchRecords.ts b/packages/twenty-front/src/modules/navigation-menu-item/edit/hooks/useNavigationMenuItemSearchRecords.ts
index a89390c1415..97e2e8e08e7 100644
--- a/packages/twenty-front/src/modules/navigation-menu-item/edit/hooks/useNavigationMenuItemSearchRecords.ts
+++ b/packages/twenty-front/src/modules/navigation-menu-item/edit/hooks/useNavigationMenuItemSearchRecords.ts
@@ -44,7 +44,7 @@ export const useNavigationMenuItemSearchRecords = ({
useObjectRecordSearchRecords({
objectNameSingulars: includedObjectNameSingulars,
searchInput: deferredSearchInput,
- skip,
+ skip: skip || includedObjectNameSingulars.length === 0,
limit: deferredSearchInput ? undefined : DEFAULT_RECORD_SUGGESTION_LIMIT,
});
diff --git a/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSearchableObjectNameSingulars.test.tsx b/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSearchableObjectNameSingulars.test.tsx
new file mode 100644
index 00000000000..bda7ffc9ba9
--- /dev/null
+++ b/packages/twenty-front/src/modules/side-panel/hooks/__tests__/useSearchableObjectNameSingulars.test.tsx
@@ -0,0 +1,71 @@
+import { renderHook } from '@testing-library/react';
+import { Provider as JotaiProvider } from 'jotai';
+import { type ReactNode } from 'react';
+
+import { useSearchableObjectNameSingulars } from '@/side-panel/hooks/useSearchableObjectNameSingulars';
+import { sidePanelShowHiddenObjectsState } from '@/side-panel/states/sidePanelShowHiddenObjectsState';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+
+let isWorkflowCoreEnabled = false;
+
+jest.mock('@/object-metadata/hooks/useReadableObjectMetadataItems', () => ({
+ useReadableObjectMetadataItems: () => ({
+ readableObjectMetadataItems: [
+ { nameSingular: 'company', isSearchable: true },
+ { nameSingular: 'workflow', isSearchable: true },
+ { nameSingular: 'person', isSearchable: true },
+ ],
+ }),
+}));
+
+jest.mock('@/workflow/hooks/useIsWorkflowCoreEnabled', () => ({
+ useIsWorkflowCoreEnabled: () => isWorkflowCoreEnabled,
+}));
+
+const Wrapper = ({ children }: { children: ReactNode }) => (
+ <JotaiProvider store={jotaiStore}>{children}</JotaiProvider>
+);
+
+const renderSearchableObjectNameSingulars = (
+ selectedObjectNameSingular?: string | null,
+) =>
+ renderHook(
+ () => useSearchableObjectNameSingulars({ selectedObjectNameSingular }),
+ { wrapper: Wrapper },
+ ).result.current;
+
+describe('useSearchableObjectNameSingulars', () => {
+ beforeEach(() => {
+ isWorkflowCoreEnabled = false;
+ jotaiStore.set(sidePanelShowHiddenObjectsState.atom, false);
+ });
+
+ it('excludes workflows when the workflow core index page is enabled', () => {
+ isWorkflowCoreEnabled = true;
+
+ expect(renderSearchableObjectNameSingulars()).toEqual([
+ 'company',
+ 'person',
+ ]);
+ });
+
+ it('keeps workflows when the workflow core index page is disabled', () => {
+ expect(renderSearchableObjectNameSingulars()).toEqual([
+ 'company',
+ 'workflow',
+ 'person',
+ ]);
+ });
+
+ it('searches nothing when workflows are explicitly selected under the flag', () => {
+ isWorkflowCoreEnabled = true;
+
+ expect(renderSearchableObjectNameSingulars('workflow')).toEqual([]);
+ });
+
+ it('keeps an explicitly selected object that is not a workflow', () => {
+ isWorkflowCoreEnabled = true;
+
+ expect(renderSearchableObjectNameSingulars('company')).toEqual(['company']);
+ });
+});
diff --git a/packages/twenty-front/src/modules/side-panel/hooks/useSearchableObjectNameSingulars.ts b/packages/twenty-front/src/modules/side-panel/hooks/useSearchableObjectNameSingulars.ts
index 827fd36e206..e902441f371 100644
--- a/packages/twenty-front/src/modules/side-panel/hooks/useSearchableObjectNameSingulars.ts
+++ b/packages/twenty-front/src/modules/side-panel/hooks/useSearchableObjectNameSingulars.ts
@@ -1,9 +1,11 @@
import { useMemo } from 'react';
+import { CoreObjectNameSingular } from 'twenty-shared/types';
import { isDefined } from 'twenty-shared/utils';
import { useReadableObjectMetadataItems } from '@/object-metadata/hooks/useReadableObjectMetadataItems';
import { sidePanelShowHiddenObjectsState } from '@/side-panel/states/sidePanelShowHiddenObjectsState';
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
+import { useIsWorkflowCoreEnabled } from '@/workflow/hooks/useIsWorkflowCoreEnabled';
type UseSearchableObjectNameSingularsParams = {
selectedObjectNameSingular?: string | null;
@@ -16,18 +18,27 @@ export const useSearchableObjectNameSingulars = ({
const sidePanelShowHiddenObjects = useAtomStateValue(
sidePanelShowHiddenObjectsState,
);
+ const isWorkflowCoreEnabled = useIsWorkflowCoreEnabled();
return useMemo(() => {
+ const isSearchableObjectNameSingular = (objectNameSingular: string) =>
+ !isWorkflowCoreEnabled ||
+ objectNameSingular !== CoreObjectNameSingular.Workflow;
+
if (isDefined(selectedObjectNameSingular)) {
- return [selectedObjectNameSingular];
+ return isSearchableObjectNameSingular(selectedObjectNameSingular)
+ ? [selectedObjectNameSingular]
+ : [];
}
return readableObjectMetadataItems
.filter((item) => sidePanelShowHiddenObjects || item.isSearchable)
- .map((item) => item.nameSingular);
+ .map((item) => item.nameSingular)
+ .filter(isSearchableObjectNameSingular);
}, [
readableObjectMetadataItems,
selectedObjectNameSingular,
sidePanelShowHiddenObjects,
+ isWorkflowCoreEnabled,
]);
};
diff --git a/packages/twenty-front/src/modules/side-panel/pages/search/hooks/useSidePanelSearchRecords.tsx b/packages/twenty-front/src/modules/side-panel/pages/search/hooks/useSidePanelSearchRecords.tsx
index 91520d01091..575079d147c 100644
--- a/packages/twenty-front/src/modules/side-panel/pages/search/hooks/useSidePanelSearchRecords.tsx
+++ b/packages/twenty-front/src/modules/side-panel/pages/search/hooks/useSidePanelSearchRecords.tsx
@@ -22,9 +22,12 @@ export const useSidePanelSearchRecords = () => {
selectedObjectNameSingular: sidePanelSearchObjectFilter,
});
+ const hasNoSearchableObject = includedObjectNameSingulars.length === 0;
+
const { loading, searchRecords, error } = useObjectRecordSearchRecords({
objectNameSingulars: includedObjectNameSingulars,
searchInput: deferredSidePanelSearch,
+ skip: hasNoSearchableObject,
});
const searchResultItems: SearchResultItem[] = useMemo(() => {
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.ts
index 81cb59fdda8..8ad4e3499f8 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
@@ -21,6 +21,7 @@ import { WorkspaceCacheModule } from 'src/engine/workspace-cache/workspace-cache
import { WorkspaceMigrationRunnerModule } from 'src/engine/workspace-manager/workspace-migration/workspace-migration-runner/workspace-migration-runner.module';
import { 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';
@Module({
imports: [
@@ -36,6 +37,7 @@ import { WorkspaceSchemaMigrationRunnerActionHandlersModule } from 'src/engine/w
WorkspaceSchemaMigrationRunnerActionHandlersModule,
],
providers: [
+ GateWorkflowFavoritesByCoreIndexFlagCommand,
MigrateAgentHistoryToWorkspaceCommand,
UnpinCreationCommandsOnRecordSelectionCommand,
RelinkWorkflowVersionsToCoreWorkflowsCommand,
@@ -48,6 +50,9 @@ import { WorkspaceSchemaMigrationRunnerActionHandlersModule } from 'src/engine/w
SetMessageTextDisplayedMaxRowsCommand,
PurgeSoftDeletedRowLevelPermissionPredicatesCommand,
],
- exports: [RelinkWorkflowVersionsToCoreWorkflowsCommand],
+ exports: [
+ GateWorkflowFavoritesByCoreIndexFlagCommand,
+ RelinkWorkflowVersionsToCoreWorkflowsCommand,
+ ],
})
export class V2_42_UpgradeVersionCommandModule {}
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1789981200000-gate-workflow-favorites-by-core-index-flag.command.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1789981200000-gate-workflow-favorites-by-core-index-flag.command.ts
new file mode 100644
index 00000000000..949f7bfff64
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/2-42-workspace-command-1789981200000-gate-workflow-favorites-by-core-index-flag.command.ts
@@ -0,0 +1,88 @@
+import { Command } from 'nest-commander';
+import { TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER } from 'twenty-shared/application';
+import { isDefined } 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 { buildGateWorkflowFavoriteCommandMenuItemUpdates } from 'src/database/commands/upgrade-version-command/2-42/utils/build-gate-workflow-favorite-command-menu-item-updates.util';
+import { RegisteredWorkspaceCommand } from 'src/engine/core-modules/upgrade/decorators/registered-workspace-command.decorator';
+import { STANDARD_COMMAND_MENU_ITEMS } from 'src/engine/workspace-manager/twenty-standard-application/constants/standard-command-menu-item.constant';
+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', 1789981200000)
+@Command({
+ name: 'upgrade:2-42:gate-workflow-favorites-by-core-index-flag',
+ description:
+ 'Hide the favorite actions on workflows when the workflow core index feature flag is enabled',
+})
+export class GateWorkflowFavoritesByCoreIndexFlagCommand extends ProvisionedWorkspaceCommandRunner {
+ constructor(
+ protected readonly workspaceIteratorService: WorkspaceIteratorService,
+ private readonly workspaceMigrationValidateBuildAndRunService: WorkspaceMigrationValidateBuildAndRunService,
+ private readonly workspaceCacheService: WorkspaceCacheService,
+ ) {
+ super(workspaceIteratorService);
+ }
+
+ override async runOnWorkspace({
+ workspaceId,
+ options,
+ }: RunOnWorkspaceArgs): Promise<void> {
+ const { flatCommandMenuItemMaps } =
+ await this.workspaceCacheService.getOrRecompute(workspaceId, [
+ 'flatCommandMenuItemMaps',
+ ]);
+
+ const commandMenuItemsToUpdate =
+ buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: Object.values(
+ flatCommandMenuItemMaps.byUniversalIdentifier,
+ ),
+ conditionalAvailabilityExpressionByUniversalIdentifier: {
+ [STANDARD_COMMAND_MENU_ITEMS.addToFavorites.universalIdentifier]:
+ STANDARD_COMMAND_MENU_ITEMS.addToFavorites
+ .conditionalAvailabilityExpression,
+ [STANDARD_COMMAND_MENU_ITEMS.removeFromFavorites.universalIdentifier]:
+ STANDARD_COMMAND_MENU_ITEMS.removeFromFavorites
+ .conditionalAvailabilityExpression,
+ },
+ now: new Date().toISOString(),
+ });
+
+ if (!isDefined(commandMenuItemsToUpdate[0])) {
+ return;
+ }
+
+ if (options.dryRun) {
+ this.logger.log(
+ `Would gate ${commandMenuItemsToUpdate.length} favorite command menu item(s) for workspace ${workspaceId}`,
+ );
+
+ return;
+ }
+
+ const validateAndBuildResult =
+ await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunLegacyWorkspaceMigration(
+ {
+ allFlatEntityOperationByMetadataName: {
+ commandMenuItem: {
+ flatEntityToCreate: [],
+ flatEntityToDelete: [],
+ flatEntityToUpdate: commandMenuItemsToUpdate,
+ },
+ },
+ workspaceId,
+ isSystemBuild: true,
+ applicationUniversalIdentifier:
+ TWENTY_STANDARD_APPLICATION_UNIVERSAL_IDENTIFIER,
+ },
+ );
+
+ 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-gate-workflow-favorite-command-menu-item-updates.util.spec.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/__tests__/build-gate-workflow-favorite-command-menu-item-updates.util.spec.ts
new file mode 100644
index 00000000000..f2d06eacb1c
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/__tests__/build-gate-workflow-favorite-command-menu-item-updates.util.spec.ts
@@ -0,0 +1,122 @@
+import { buildGateWorkflowFavoriteCommandMenuItemUpdates } from 'src/database/commands/upgrade-version-command/2-42/utils/build-gate-workflow-favorite-command-menu-item-updates.util';
+import { EngineComponentKey } from 'src/engine/metadata-modules/command-menu-item/enums/engine-component-key.enum';
+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
+
+const NOW = '2026-09-22T00:00:00.000Z';
+const ADD_UNIVERSAL_IDENTIFIER = 'add-universal-identifier';
+const REMOVE_UNIVERSAL_IDENTIFIER = 'remove-universal-identifier';
+const GATED_ADD_EXPRESSION = 'gated add expression';
+const GATED_REMOVE_EXPRESSION = 'gated remove expression';
+
+const EXPRESSION_BY_UNIVERSAL_IDENTIFIER = {
+ [ADD_UNIVERSAL_IDENTIFIER]: GATED_ADD_EXPRESSION,
+ [REMOVE_UNIVERSAL_IDENTIFIER]: GATED_REMOVE_EXPRESSION,
+};
+
+const buildFlatCommandMenuItem = (
+ overrides: Partial<FlatCommandMenuItem>,
+): FlatCommandMenuItem =>
+ ({
+ id: 'command-menu-item-id',
+ universalIdentifier: ADD_UNIVERSAL_IDENTIFIER,
+ engineComponentKey: EngineComponentKey.ADD_TO_FAVORITES,
+ conditionalAvailabilityExpression: 'legacy expression',
+ isPinned: true,
+ position: 7,
+ ...overrides,
+ }) as FlatCommandMenuItem;
+
+describe('buildGateWorkflowFavoriteCommandMenuItemUpdates', () => {
+ it('rewrites both standard favorite commands to the gated expressions', () => {
+ const updates = buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({ id: 'add' }),
+ buildFlatCommandMenuItem({
+ id: 'remove',
+ universalIdentifier: REMOVE_UNIVERSAL_IDENTIFIER,
+ engineComponentKey: EngineComponentKey.REMOVE_FROM_FAVORITES,
+ }),
+ ],
+ conditionalAvailabilityExpressionByUniversalIdentifier:
+ EXPRESSION_BY_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ });
+
+ expect(
+ updates.map(({ id, conditionalAvailabilityExpression }) => ({
+ id,
+ conditionalAvailabilityExpression,
+ })),
+ ).toEqual([
+ { id: 'add', conditionalAvailabilityExpression: GATED_ADD_EXPRESSION },
+ {
+ id: 'remove',
+ conditionalAvailabilityExpression: GATED_REMOVE_EXPRESSION,
+ },
+ ]);
+ });
+
+ it('leaves an application item reusing the favorite engine key untouched', () => {
+ expect(
+ buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({
+ universalIdentifier: 'application-universal-identifier',
+ conditionalAvailabilityExpression: 'application expression',
+ }),
+ ],
+ conditionalAvailabilityExpressionByUniversalIdentifier:
+ EXPRESSION_BY_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ }),
+ ).toEqual([]);
+ });
+
+ it('preserves every unrelated command menu item field', () => {
+ const [update] = buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: [buildFlatCommandMenuItem({})],
+ conditionalAvailabilityExpressionByUniversalIdentifier:
+ EXPRESSION_BY_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ });
+
+ expect(update).toMatchObject({
+ id: 'command-menu-item-id',
+ isPinned: true,
+ position: 7,
+ updatedAt: NOW,
+ });
+ });
+
+ it('leaves other command menu items untouched', () => {
+ expect(
+ buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({
+ universalIdentifier: 'navigation-universal-identifier',
+ engineComponentKey: EngineComponentKey.NAVIGATION,
+ }),
+ undefined,
+ ],
+ conditionalAvailabilityExpressionByUniversalIdentifier:
+ EXPRESSION_BY_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ }),
+ ).toEqual([]);
+ });
+
+ it('is idempotent once the gated expression is already stored', () => {
+ expect(
+ buildGateWorkflowFavoriteCommandMenuItemUpdates({
+ flatCommandMenuItems: [
+ buildFlatCommandMenuItem({
+ conditionalAvailabilityExpression: GATED_ADD_EXPRESSION,
+ }),
+ ],
+ conditionalAvailabilityExpressionByUniversalIdentifier:
+ EXPRESSION_BY_UNIVERSAL_IDENTIFIER,
+ now: NOW,
+ }),
+ ).toEqual([]);
+ });
+});
diff --git a/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-gate-workflow-favorite-command-menu-item-updates.util.ts b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-gate-workflow-favorite-command-menu-item-updates.util.ts
new file mode 100644
index 00000000000..f00f7e47327
--- /dev/null
+++ b/packages/twenty-server/src/database/commands/upgrade-version-command/2-42/utils/build-gate-workflow-favorite-command-menu-item-updates.util.ts
@@ -0,0 +1,42 @@
+import { isDefined } from 'twenty-shared/utils';
+
+import { type FlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item.type';
+
+export const buildGateWorkflowFavoriteCommandMenuItemUpdates = ({
+ flatCommandMenuItems,
+ conditionalAvailabilityExpressionByUniversalIdentifier,
+ now,
+}: {
+ flatCommandMenuItems: (FlatCommandMenuItem | undefined)[];
+ conditionalAvailabilityExpressionByUniversalIdentifier: Record<
+ string,
+ string
+ >;
+ now: string;
+}): FlatCommandMenuItem[] =>
+ flatCommandMenuItems.flatMap((flatCommandMenuItem) => {
+ if (!isDefined(flatCommandMenuItem)) {
+ return [];
+ }
+
+ const conditionalAvailabilityExpression =
+ conditionalAvailabilityExpressionByUniversalIdentifier[
+ flatCommandMenuItem.universalIdentifier
+ ];
+
+ if (
+ !isDefined(conditionalAvailabilityExpression) ||
+ flatCommandMenuItem.conditionalAvailabilityExpression ===
+ conditionalAvailabilityExpression
+ ) {
+ return [];
+ }
+
+ return [
+ {
+ ...flatCommandMenuItem,
+ conditionalAvailabilityExpression,
+ 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.ts
index 5a43162d519..340c0451e9a 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
@@ -149,7 +149,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {
shortLabel: null,
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
conditionalAvailabilityExpression:
- 'arrayLength(favoriteRecordIds) < numberOfSelectedRecords and noneDefined(selectedRecords, "deletedAt") and not hasAnySoftDeleteFilterOnView and objectMetadataItem.nameSingular != "messageCampaign"',
+ 'arrayLength(favoriteRecordIds) < numberOfSelectedRecords and noneDefined(selectedRecords, "deletedAt") and not hasAnySoftDeleteFilterOnView and objectMetadataItem.nameSingular != "messageCampaign" and not (featureFlags.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED and objectMetadataItem.nameSingular == "workflow")',
availabilityObjectMetadataUniversalIdentifier: null,
frontComponentUniversalIdentifier: null,
engineComponentKey: EngineComponentKey.ADD_TO_FAVORITES,
@@ -169,7 +169,7 @@ export const STANDARD_COMMAND_MENU_ITEMS = {
shortLabel: null,
availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,
conditionalAvailabilityExpression:
- 'arrayLength(favoriteRecordIds) == numberOfSelectedRecords and noneDefined(selectedRecords, "deletedAt") and not hasAnySoftDeleteFilterOnView and objectMetadataItem.nameSingular != "messageCampaign"',
+ 'arrayLength(favoriteRecordIds) == numberOfSelectedRecords and noneDefined(selectedRecords, "deletedAt") and not hasAnySoftDeleteFilterOnView and objectMetadataItem.nameSingular != "messageCampaign" and not (featureFlags.IS_WORKFLOW_CORE_INDEX_PAGE_ENABLED and objectMetadataItem.nameSingular == "workflow")',
availabilityObjectMetadataUniversalIdentifier: null,
frontComponentUniversalIdentifier: null,
engineComponentKey: EngineComponentKey.REMOVE_FROM_FAVORITES,