The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Group the command menu into sections (#26130)
Thomas des Francsfa47e892c313
diff --git a/packages/twenty-front/src/modules/command-menu-item/constants/AmbiguousEngineComponentKeys.ts b/packages/twenty-front/src/modules/command-menu-item/constants/AmbiguousEngineComponentKeys.tsnew file mode 100644index 00000000000..aa17620dae1--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/constants/AmbiguousEngineComponentKeys.ts@@ -0,0 +1,8 @@+import { EngineComponentKey } from '~/generated-metadata/graphql';++export const AMBIGUOUS_ENGINE_COMPONENT_KEYS = [+ EngineComponentKey.COMPOSE_EMAIL,+ EngineComponentKey.COMPOSE_CAMPAIGN,+ EngineComponentKey.FRONT_COMPONENT_RENDERER,+ EngineComponentKey.TRIGGER_WORKFLOW_VERSION,+] as const;diff --git a/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByAvailabilityType.ts b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByAvailabilityType.tsnew file mode 100644index 00000000000..096af123adb--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByAvailabilityType.ts@@ -0,0 +1,12 @@+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';+import { CommandMenuItemAvailabilityType } from '~/generated-metadata/graphql';++export const COMMAND_MENU_ITEM_SECTION_BY_AVAILABILITY_TYPE = {+ [CommandMenuItemAvailabilityType.RECORD_SELECTION]: 'SELECTION',+ [CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT]: 'THIS_VIEW',+ [CommandMenuItemAvailabilityType.FALLBACK]: 'FALLBACK',+ [CommandMenuItemAvailabilityType.GLOBAL]: 'WORKSPACE',+} as const satisfies Record<+ CommandMenuItemAvailabilityType,+ CommandMenuItemSection+>;diff --git a/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByEngineComponentKey.ts b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByEngineComponentKey.tsnew file mode 100644index 00000000000..5eece0708b4--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionByEngineComponentKey.ts@@ -0,0 +1,83 @@+import { type AMBIGUOUS_ENGINE_COMPONENT_KEYS } from '@/command-menu-item/constants/AmbiguousEngineComponentKeys';+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';+import { EngineComponentKey } from '~/generated-metadata/graphql';++export const COMMAND_MENU_ITEM_SECTION_BY_ENGINE_COMPONENT_KEY = {+ [EngineComponentKey.ADD_TO_FAVORITES]: 'SELECTION',+ [EngineComponentKey.REMOVE_FROM_FAVORITES]: 'SELECTION',+ [EngineComponentKey.DELETE_RECORDS]: 'SELECTION',+ [EngineComponentKey.RESTORE_RECORDS]: 'SELECTION',+ [EngineComponentKey.DESTROY_RECORDS]: 'SELECTION',+ [EngineComponentKey.EXPORT_RECORDS]: 'SELECTION',+ [EngineComponentKey.EXPORT_NOTE_TO_PDF]: 'SELECTION',+ [EngineComponentKey.UPDATE_MULTIPLE_RECORDS]: 'SELECTION',+ [EngineComponentKey.MERGE_MULTIPLE_RECORDS]: 'SELECTION',+ [EngineComponentKey.REPLY_TO_EMAIL_THREAD]: 'SELECTION',+ [EngineComponentKey.EDIT_DASHBOARD_LAYOUT]: 'SELECTION',+ [EngineComponentKey.SAVE_DASHBOARD_LAYOUT]: 'SELECTION',+ [EngineComponentKey.CANCEL_DASHBOARD_LAYOUT]: 'SELECTION',+ [EngineComponentKey.DUPLICATE_DASHBOARD]: 'SELECTION',+ [EngineComponentKey.DUPLICATE_MESSAGE_LIST]: 'SELECTION',+ [EngineComponentKey.DUPLICATE_MESSAGE_CAMPAIGN]: 'SELECTION',+ [EngineComponentKey.DUPLICATE_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.ACTIVATE_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.DEACTIVATE_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.DISCARD_DRAFT_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.TEST_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.ADD_NODE_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.TIDY_UP_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.SEE_ACTIVE_VERSION_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.SEE_RUNS_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.SEE_VERSIONS_WORKFLOW]: 'SELECTION',+ [EngineComponentKey.SEE_VERSION_WORKFLOW_RUN]: 'SELECTION',+ [EngineComponentKey.SEE_WORKFLOW_WORKFLOW_RUN]: 'SELECTION',+ [EngineComponentKey.STOP_WORKFLOW_RUN]: 'SELECTION',+ [EngineComponentKey.RETRY_WORKFLOW_RUN]: 'SELECTION',+ [EngineComponentKey.SEE_RUNS_WORKFLOW_VERSION]: 'SELECTION',+ [EngineComponentKey.SEE_WORKFLOW_WORKFLOW_VERSION]: 'SELECTION',+ [EngineComponentKey.SEE_VERSIONS_WORKFLOW_VERSION]: 'SELECTION',+ [EngineComponentKey.USE_AS_DRAFT_WORKFLOW_VERSION]: 'SELECTION',+ [EngineComponentKey.SEND_MESSAGE_CAMPAIGN]: 'SELECTION',+ [EngineComponentKey.SEND_MESSAGE_CAMPAIGN_TEST]: 'SELECTION',+ [EngineComponentKey.CANCEL_MESSAGE_CAMPAIGN]: 'SELECTION',+ [EngineComponentKey.EMAIL_BLOCK_SETTINGS]: 'SELECTION',+ [EngineComponentKey.DELETE_SINGLE_RECORD]: 'SELECTION',+ [EngineComponentKey.DELETE_MULTIPLE_RECORDS]: 'SELECTION',+ [EngineComponentKey.RESTORE_SINGLE_RECORD]: 'SELECTION',+ [EngineComponentKey.RESTORE_MULTIPLE_RECORDS]: 'SELECTION',+ [EngineComponentKey.DESTROY_SINGLE_RECORD]: 'SELECTION',+ [EngineComponentKey.DESTROY_MULTIPLE_RECORDS]: 'SELECTION',+ [EngineComponentKey.EXPORT_FROM_RECORD_INDEX]: 'SELECTION',+ [EngineComponentKey.EXPORT_FROM_RECORD_SHOW]: 'SELECTION',+ [EngineComponentKey.EXPORT_MULTIPLE_RECORDS]: 'SELECTION',++ [EngineComponentKey.CREATE_NEW_RECORD]: 'THIS_VIEW',+ [EngineComponentKey.CREATE_NEW_VIEW]: 'THIS_VIEW',+ [EngineComponentKey.IMPORT_RECORDS]: 'THIS_VIEW',+ [EngineComponentKey.EXPORT_VIEW]: 'THIS_VIEW',+ [EngineComponentKey.SEE_DELETED_RECORDS]: 'THIS_VIEW',+ [EngineComponentKey.HIDE_DELETED_RECORDS]: 'THIS_VIEW',+ [EngineComponentKey.EDIT_RECORD_PAGE_LAYOUT]: 'THIS_VIEW',++ [EngineComponentKey.ASK_AI]: 'ASK_AND_FIND',+ [EngineComponentKey.SEARCH_RECORDS]: 'ASK_AND_FIND',+ [EngineComponentKey.VIEW_PREVIOUS_AI_CHATS]: 'ASK_AND_FIND',++ [EngineComponentKey.NAVIGATION]: 'GO_TO',+ [EngineComponentKey.NAVIGATE_TO_NEXT_RECORD]: 'GO_TO',+ [EngineComponentKey.NAVIGATE_TO_PREVIOUS_RECORD]: 'GO_TO',+ [EngineComponentKey.GO_TO_PEOPLE]: 'GO_TO',+ [EngineComponentKey.GO_TO_COMPANIES]: 'GO_TO',+ [EngineComponentKey.GO_TO_DASHBOARDS]: 'GO_TO',+ [EngineComponentKey.GO_TO_OPPORTUNITIES]: 'GO_TO',+ [EngineComponentKey.GO_TO_SETTINGS]: 'GO_TO',+ [EngineComponentKey.GO_TO_TASKS]: 'GO_TO',+ [EngineComponentKey.GO_TO_NOTES]: 'GO_TO',+ [EngineComponentKey.GO_TO_WORKFLOWS]: 'GO_TO',+ [EngineComponentKey.GO_TO_RUNS]: 'GO_TO',++ [EngineComponentKey.SEARCH_RECORDS_FALLBACK]: 'FALLBACK',+} as const satisfies Record<+ Exclude<EngineComponentKey, (typeof AMBIGUOUS_ENGINE_COMPONENT_KEYS)[number]>,+ CommandMenuItemSection+>;diff --git a/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionsInDisplayOrder.ts b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionsInDisplayOrder.tsnew file mode 100644index 00000000000..1c47adafa25--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/constants/CommandMenuItemSectionsInDisplayOrder.ts@@ -0,0 +1,10 @@+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';++export const COMMAND_MENU_ITEM_SECTIONS_IN_DISPLAY_ORDER = [+ 'SELECTION',+ 'THIS_VIEW',+ 'ASK_AND_FIND',+ 'CREATE_RECORD',+ 'WORKSPACE',+ 'GO_TO',+] as const satisfies readonly CommandMenuItemSection[];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 10afa181ae8..dddcabafdc4 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@@ -11,6 +11,7 @@ import { doesCommandMenuItemMatchPageLayoutId } from '@/command-menu-item/utils/import { resolveCommandMenuItemPinning } from '@/command-menu-item/utils/resolveCommandMenuItemPinning';import { doesCommandMenuItemMatchPageType } from '@/command-menu-item/utils/doesCommandMenuItemMatchPageType';import { doesCommandMenuItemMatchSelectionState } from '@/command-menu-item/utils/doesCommandMenuItemMatchSelectionState';+import { getCommandMenuContextApiForContainerType } from '@/command-menu-item/utils/getCommandMenuContextApiForContainerType';import { mergeGlobalRecordCreationCommandMenuItems } from '@/command-menu-item/utils/mergeGlobalRecordCreationCommandMenuItems';import { useIsLayoutCustomizationAllowedOnCurrentPage } from '@/layout-customization/hooks/useIsLayoutCustomizationAllowedOnCurrentPage';import {@@ -56,6 +57,15 @@ export const CommandMenuContextProviderContent = ({? currentPageLayoutId: pageLayoutIdFromContext;+ const commandMenuContextApiForAvailability = useMemo(+ () =>+ getCommandMenuContextApiForContainerType({+ commandMenuContextApi,+ containerType,+ }),+ [commandMenuContextApi, containerType],+ );+const filteredCommandMenuItems = useMemo(() => {const currentObjectMetadataItemId =commandMenuContextApi.objectMetadataItem.id;@@ -81,11 +91,14 @@ export const CommandMenuContextProviderContent = ({.filter((item) =>evaluateConditionalAvailabilityExpression(item.conditionalAvailabilityExpression,- commandMenuContextApi,+ commandMenuContextApiForAvailability,),).map((item) =>- resolveCommandMenuItemPinning(item, commandMenuContextApi),+ resolveCommandMenuItemPinning(+ item,+ commandMenuContextApiForAvailability,+ ),);return mergeGlobalRecordCreationCommandMenuItems({@@ -95,6 +108,7 @@ export const CommandMenuContextProviderContent = ({});}, [commandMenuContextApi,+ commandMenuContextApiForAvailability,globalRecordCreationCommandMenuItems,shouldDisplayGlobalRecordCreationCommands,commandMenuItems,diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsxindex 5ebecbb2573..8d3e4ab9987 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage.tsx@@ -1,10 +1,11 @@+import { COMMAND_MENU_ITEM_SECTIONS_IN_DISPLAY_ORDER } from '@/command-menu-item/constants/CommandMenuItemSectionsInDisplayOrder';import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';import { CommandMenuItemRenderer } from '@/command-menu-item/display/components/CommandMenuItemRenderer';-import { PINNED_COMMAND_MENU_ITEMS_GAP } from '@/command-menu-item/display/constants/PinnedCommandMenuItemsGap';import { useCommandMenuAppActions } from '@/command-menu-item/display/hooks/useCommandMenuAppActions';-import { commandMenuPinnedInlineLayoutFamilyState } from '@/command-menu-item/display/states/commandMenuPinnedInlineLayoutFamilyState';-import { getVisibleCommandMenuItemCountForContainerWidth } from '@/command-menu-item/display/utils/getVisibleCommandMenuItemCountForContainerWidth';+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';import { groupCommandMenuItems } from '@/command-menu-item/utils/groupCommandMenuItems';+import { getCommandMenuItemObjectSectionHeading } from '@/command-menu-item/utils/getCommandMenuItemObjectSectionHeading';+import { groupCommandMenuItemsBySection } from '@/command-menu-item/utils/groupCommandMenuItemsBySection';import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';import { CoreObjectsCommands } from '@/object-core/commands/components/CoreObjectsCommands';import { useCoreObjectsCommands } from '@/object-core/commands/hooks/useCoreObjectsCommands';@@ -14,10 +15,9 @@ import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';import { useFilterCommandMenuItemsWithSidePanelSearch } from '@/side-panel/pages/root/hooks/useFilterCommandMenuItemsWithSidePanelSearch';import { sidePanelSearchState } from '@/side-panel/states/sidePanelSearchState';import { SelectableListItem } from '@/ui/layout/selectable-list/components/SelectableListItem';-import { useAtomFamilyStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomFamilyStateValue';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useLingui } from '@lingui/react/macro';-import { isNonEmptyString, isNumber } from '@sniptt/guards';+import { isNonEmptyString } from '@sniptt/guards';import { useContext, useMemo } from 'react';import { CommandMenuItemAvailabilityType } from '~/generated-metadata/graphql';@@ -32,12 +32,6 @@ export const SidePanelCommandMenuItemDisplayPage = () => {const { coreObjectsCommandIds } = useCoreObjectsCommands();- // The command menu list surfaces whatever overflowed out of the page header.- const commandMenuPinnedInlineLayout = useAtomFamilyStateValue(- commandMenuPinnedInlineLayoutFamilyState,- 'page-header',- );-const { filterCommandMenuItemsWithSidePanelSearch } =useFilterCommandMenuItemsWithSidePanelSearch({sidePanelSearch,@@ -65,45 +59,52 @@ export const SidePanelCommandMenuItemDisplayPage = () => {[nonPinnedCommandMenuItems],);- const pinnedCommandMenuItemKeysInDisplayOrder = pinnedCommandMenuItems.map(- (item) => item.id,- );-- const visiblePinnedCommandMenuItemCount =- getVisibleCommandMenuItemCountForContainerWidth({- commandMenuItemKeysInDisplayOrder:- pinnedCommandMenuItemKeysInDisplayOrder,- commandMenuItemWidthsByKey:- commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey,- commandMenuItemsContainerWidth:- commandMenuPinnedInlineLayout.containerWidth,- commandMenuItemsGapWidth: PINNED_COMMAND_MENU_ITEMS_GAP,- });-- const hasKnownPinnedInlineLayout =- commandMenuPinnedInlineLayout.containerWidth > 0 &&- pinnedCommandMenuItemKeysInDisplayOrder.every((itemKey) =>- isNumber(- commandMenuPinnedInlineLayout.commandMenuItemWidthsByKey[itemKey],- ),- );-- const pinnedOverflowCommandMenuItems = hasKnownPinnedInlineLayout- ? pinnedCommandMenuItems.slice(visiblePinnedCommandMenuItemCount)- : pinnedCommandMenuItems;-const isSearchActive = isNonEmptyString(sidePanelSearch.trim());- const pinnedItemsToFilter = isSearchActive- ? pinnedCommandMenuItems- : pinnedOverflowCommandMenuItems;-- const matchingPinnedItems =- filterCommandMenuItemsWithSidePanelSearch(pinnedItemsToFilter);+ const matchingPinnedItems = filterCommandMenuItemsWithSidePanelSearch(+ pinnedCommandMenuItems,+ );const matchingOtherItems = filterCommandMenuItemsWithSidePanelSearch(unpinnedCommandMenuItems,);+ const commandMenuItemsBySection =+ groupCommandMenuItemsBySection(matchingOtherItems);++ const getSectionHeading = (section: CommandMenuItemSection) => {+ switch (section) {+ case 'SELECTION':+ return t`Selection`;+ case 'THIS_VIEW':+ return getCommandMenuItemObjectSectionHeading({+ commandMenuContextApi,+ fallbackHeading: t`This object`,+ });+ case 'ASK_AND_FIND':+ return t`Ask & find`;+ case 'CREATE_RECORD':+ return t`Create record`;+ case 'WORKSPACE':+ return t`Workspace`;+ case 'GO_TO':+ return t`Go to`;+ case 'FALLBACK':+ return t`Fallback`;+ }+ };++ const getSectionExtraItemIds = (section: CommandMenuItemSection) => {+ if (section === 'THIS_VIEW') {+ return coreObjectsCommandIds;+ }++ if (section === 'WORKSPACE') {+ return appActions.map((item) => item.id);+ }++ return [];+ };+const hasNoMatchingItems =!matchingPinnedItems.length &&!matchingOtherItems.length &&@@ -118,9 +119,10 @@ export const SidePanelCommandMenuItemDisplayPage = () => {const selectableItemIds = [...matchingPinnedItems.map((item) => item.id),- ...matchingOtherItems.map((item) => item.id),- ...appActions.map((item) => item.id),- ...coreObjectsCommandIds,+ ...COMMAND_MENU_ITEM_SECTIONS_IN_DISPLAY_ORDER.flatMap((section) => [+ ...commandMenuItemsBySection[section].map((item) => item.id),+ ...getSectionExtraItemIds(section),+ ]),...(shouldDisplayFallbackItems? fallbackCommandMenuItems.map((item) => item.id): []),@@ -138,37 +140,47 @@ export const SidePanelCommandMenuItemDisplayPage = () => {))}</SidePanelGroup>)}- {(matchingOtherItems.length > 0 ||- appActions.length > 0 ||- coreObjectsCommandIds.length > 0) && (- <SidePanelGroup heading={t`Other`}>- {matchingOtherItems.map((item) => (- <CommandMenuItemRenderer item={item} key={item.id} />- ))}- {appActions.map((item) => {- const handleClick = () => {- item.onClick();- closeSidePanelMenu();- };-- return (- <SelectableListItem- key={item.id}- itemId={item.id}- onEnter={handleClick}- >- <CommandMenuItem- id={item.id}- label={item.label}- Icon={item.Icon}- onClick={handleClick}- />- </SelectableListItem>- );- })}- <CoreObjectsCommands />- </SidePanelGroup>- )}+ {COMMAND_MENU_ITEM_SECTIONS_IN_DISPLAY_ORDER.map((section) => {+ const sectionCommandMenuItems = commandMenuItemsBySection[section];++ if (+ sectionCommandMenuItems.length === 0 &&+ getSectionExtraItemIds(section).length === 0+ ) {+ return null;+ }++ return (+ <SidePanelGroup heading={getSectionHeading(section)} key={section}>+ {sectionCommandMenuItems.map((item) => (+ <CommandMenuItemRenderer item={item} key={item.id} />+ ))}+ {section === 'THIS_VIEW' && <CoreObjectsCommands />}+ {section === 'WORKSPACE' &&+ appActions.map((item) => {+ const handleClick = () => {+ item.onClick();+ closeSidePanelMenu();+ };++ return (+ <SelectableListItem+ key={item.id}+ itemId={item.id}+ onEnter={handleClick}+ >+ <CommandMenuItem+ id={item.id}+ label={item.label}+ Icon={item.Icon}+ onClick={handleClick}+ />+ </SelectableListItem>+ );+ })}+ </SidePanelGroup>+ );+ })}{shouldDisplayFallbackItems && (<SidePanelGroup heading={t`Fallback`}>{fallbackCommandMenuItems.map((item) => (diff --git a/packages/twenty-front/src/modules/command-menu-item/display/components/__stories__/SidePanelCommandMenuItemDisplayPage.stories.tsx b/packages/twenty-front/src/modules/command-menu-item/display/components/__stories__/SidePanelCommandMenuItemDisplayPage.stories.tsxindex 57b7b338409..66b12285b4b 100644--- a/packages/twenty-front/src/modules/command-menu-item/display/components/__stories__/SidePanelCommandMenuItemDisplayPage.stories.tsx+++ b/packages/twenty-front/src/modules/command-menu-item/display/components/__stories__/SidePanelCommandMenuItemDisplayPage.stories.tsx@@ -103,6 +103,13 @@ const PINNED_ITEMS = [];const OTHER_ITEM = createCommandMenuItem({+ id: 'story-import-records',+ label: 'Import records',+ icon: 'IconFileImport',+ engineComponentKey: EngineComponentKey.IMPORT_RECORDS,+});++const NAVIGATION_ITEM = createCommandMenuItem({id: 'story-go-to-people',label: 'Go to People',});@@ -234,7 +241,7 @@ export const EmptySearchWithAllPinnedItemsInHeader: Story = {await waitFor(() => {expect(canvas.queryByText('No results found')).not.toBeInTheDocument();});- expect(canvas.queryByText('Delete')).not.toBeInTheDocument();+ expect(await canvas.findByText('Delete')).toBeVisible();},};@@ -253,7 +260,7 @@ export const WhitespaceOnlySearchWithAllPinnedItemsInHeader: Story = {await waitFor(() => {expect(canvas.queryByText('No results found')).not.toBeInTheDocument();});- expect(canvas.queryByText('Delete')).not.toBeInTheDocument();+ expect(await canvas.findByText('Delete')).toBeVisible();},};@@ -269,7 +276,7 @@ export const EmptySearchWithOverflowingPinnedItems: Story = {const canvas = within(canvasElement);expect(await canvas.findByText('Delete')).toBeVisible();- expect(await canvas.findByText('Go to People')).toBeVisible();+ expect(await canvas.findByText('Import records')).toBeVisible();await waitFor(() => {expect(canvas.queryByText('No results found')).not.toBeInTheDocument();});@@ -330,6 +337,51 @@ export const SearchWithoutMatchingItemsAndWithFallback: Story = {},};+export const NavigationSitsLastAtRest: Story = {+ decorators: [+ createDecorator({+ commandMenuItems: [...PINNED_ITEMS, OTHER_ITEM, NAVIGATION_ITEM],+ sidePanelSearch: '',+ pinnedItemsContainerWidth: 1000,+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(await canvas.findByText('Import records')).toBeVisible();+ expect(await canvas.findByText('Go to People')).toBeVisible();++ const headings = canvas.getAllByText(+ /^(Pinned|This object|Workspace|Go to)$/,+ );++ expect(headings.map((heading) => heading.textContent)).toEqual([+ 'Pinned',+ 'This object',+ 'Workspace',+ 'Go to',+ ]);+ },+};++export const NavigationIsFoundBySearch: Story = {+ decorators: [+ createDecorator({+ commandMenuItems: [...PINNED_ITEMS, OTHER_ITEM, NAVIGATION_ITEM],+ sidePanelSearch: 'people',+ pinnedItemsContainerWidth: 1000,+ }),+ ],+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);++ expect(await canvas.findByText('Go to People')).toBeVisible();+ await waitFor(() => {+ expect(canvas.queryByText('No results found')).not.toBeInTheDocument();+ });+ },+};+export const CollapseSidebar: Story = {decorators: [createDecorator({diff --git a/packages/twenty-front/src/modules/command-menu-item/types/CommandMenuItemSection.ts b/packages/twenty-front/src/modules/command-menu-item/types/CommandMenuItemSection.tsnew file mode 100644index 00000000000..5c98cadcbe5--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/types/CommandMenuItemSection.ts@@ -0,0 +1,8 @@+export type CommandMenuItemSection =+ | 'SELECTION'+ | 'THIS_VIEW'+ | 'ASK_AND_FIND'+ | 'CREATE_RECORD'+ | 'WORKSPACE'+ | 'GO_TO'+ | 'FALLBACK';diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuContextApiForContainerType.test.ts b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuContextApiForContainerType.test.tsnew file mode 100644index 00000000000..b2aad0218ca--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuContextApiForContainerType.test.ts@@ -0,0 +1,33 @@+import { type CommandMenuContextApi } from 'twenty-shared/types';++import { CommandMenuItemContainerType } from '@/command-menu-item/types/CommandMenuItemContainerType';+import { getCommandMenuContextApiForContainerType } from '@/command-menu-item/utils/getCommandMenuContextApiForContainerType';++const COMMAND_MENU_CONTEXT_API = {+ isInSidePanel: true,+ numberOfSelectedRecords: 2,+} as unknown as CommandMenuContextApi;++describe('getCommandMenuContextApiForContainerType', () => {+ it('reports the command menu list as not being a panel-hosted page', () => {+ expect(+ getCommandMenuContextApiForContainerType({+ commandMenuContextApi: COMMAND_MENU_CONTEXT_API,+ containerType: CommandMenuItemContainerType.CommandMenuList,+ }),+ ).toEqual({ ...COMMAND_MENU_CONTEXT_API, isInSidePanel: false });+ });++ it.each([+ CommandMenuItemContainerType.IndexPageHeader,+ CommandMenuItemContainerType.ShowPageHeader,+ CommandMenuItemContainerType.SidePanelFooter,+ ])('leaves %s alone', (containerType) => {+ expect(+ getCommandMenuContextApiForContainerType({+ commandMenuContextApi: COMMAND_MENU_CONTEXT_API,+ containerType,+ }),+ ).toEqual(COMMAND_MENU_CONTEXT_API);+ });+});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuItemObjectSectionHeading.test.ts b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuItemObjectSectionHeading.test.tsnew file mode 100644index 00000000000..25f15fef11e--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/getCommandMenuItemObjectSectionHeading.test.ts@@ -0,0 +1,41 @@+import { type CommandMenuContextApi } from 'twenty-shared/types';++import { getCommandMenuItemObjectSectionHeading } from '@/command-menu-item/utils/getCommandMenuItemObjectSectionHeading';++const buildContextApi = (objectMetadataItem: Record<string, unknown>) =>+ ({ objectMetadataItem }) as unknown as CommandMenuContextApi;++describe('getCommandMenuItemObjectSectionHeading', () => {+ it('names the section after the object', () => {+ expect(+ getCommandMenuItemObjectSectionHeading({+ commandMenuContextApi: buildContextApi({ labelPlural: 'Companies' }),+ fallbackHeading: 'This object',+ }),+ ).toBe('Companies');+ });++ it('capitalizes a sentence-cased label', () => {+ expect(+ getCommandMenuItemObjectSectionHeading({+ commandMenuContextApi: buildContextApi({+ labelPlural: 'Survey results',+ }),+ fallbackHeading: 'This object',+ }),+ ).toBe('Survey results');+ });++ it.each([+ { name: 'no object in context', objectMetadataItem: {} },+ { name: 'an empty label', objectMetadataItem: { labelPlural: '' } },+ { name: 'a non-string label', objectMetadataItem: { labelPlural: 12 } },+ ])('falls back on $name', ({ objectMetadataItem }) => {+ expect(+ getCommandMenuItemObjectSectionHeading({+ commandMenuContextApi: buildContextApi(objectMetadataItem),+ fallbackHeading: 'This object',+ }),+ ).toBe('This object');+ });+});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/groupCommandMenuItemsBySection.test.ts b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/groupCommandMenuItemsBySection.test.tsnew file mode 100644index 00000000000..eaab4ea91dd--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/groupCommandMenuItemsBySection.test.ts@@ -0,0 +1,59 @@+import { type CommandMenuItemDefinition } from '@/command-menu-item/types/CommandMenuItemDefinition';+import { groupCommandMenuItemsBySection } from '@/command-menu-item/utils/groupCommandMenuItemsBySection';+import {+ CommandMenuItemAvailabilityType,+ EngineComponentKey,+} from '~/generated-metadata/graphql';++const buildCommandMenuItem = (+ id: string,+ engineComponentKey: EngineComponentKey,+ availabilityType: CommandMenuItemAvailabilityType,+) =>+ ({+ id,+ engineComponentKey,+ availabilityType,+ }) as unknown as CommandMenuItemDefinition;++describe('groupCommandMenuItemsBySection', () => {+ it('groups every section, empty ones included', () => {+ expect(Object.keys(groupCommandMenuItemsBySection([]))).toEqual([+ 'SELECTION',+ 'THIS_VIEW',+ 'ASK_AND_FIND',+ 'CREATE_RECORD',+ 'WORKSPACE',+ 'GO_TO',+ 'FALLBACK',+ ]);+ });++ it('keeps the incoming order within a section', () => {+ const commandMenuItemsBySection = groupCommandMenuItemsBySection([+ buildCommandMenuItem(+ 'import',+ EngineComponentKey.IMPORT_RECORDS,+ CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT,+ ),+ buildCommandMenuItem(+ 'search',+ EngineComponentKey.SEARCH_RECORDS,+ CommandMenuItemAvailabilityType.GLOBAL,+ ),+ buildCommandMenuItem(+ 'create-view',+ EngineComponentKey.CREATE_NEW_VIEW,+ CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT,+ ),+ ]);++ expect(commandMenuItemsBySection.THIS_VIEW.map((item) => item.id)).toEqual([+ 'import',+ 'create-view',+ ]);+ expect(+ commandMenuItemsBySection.ASK_AND_FIND.map((item) => item.id),+ ).toEqual(['search']);+ });+});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/resolveCommandMenuItemSection.test.ts b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/resolveCommandMenuItemSection.test.tsnew file mode 100644index 00000000000..aece1cee02c--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/__tests__/resolveCommandMenuItemSection.test.ts@@ -0,0 +1,99 @@+import { resolveCommandMenuItemSection } from '@/command-menu-item/utils/resolveCommandMenuItemSection';+import {+ CommandMenuItemAvailabilityType,+ EngineComponentKey,+} from '~/generated-metadata/graphql';++describe('resolveCommandMenuItemSection', () => {+ it('places a command from its engine key', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.MERGE_MULTIPLE_RECORDS,+ availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,+ }),+ ).toBe('SELECTION');+ });++ it('sends every navigation command to Go to, whatever it targets', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.NAVIGATION,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ }),+ ).toBe('GO_TO');+ });++ it('separates the two Compose Email commands by availability', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.COMPOSE_EMAIL,+ availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,+ }),+ ).toBe('SELECTION');++ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.COMPOSE_EMAIL,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ }),+ ).toBe('WORKSPACE');+ });++ it('separates the two Compose Campaign commands by availability', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.COMPOSE_CAMPAIGN,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT,+ }),+ ).toBe('THIS_VIEW');++ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.COMPOSE_CAMPAIGN,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ }),+ ).toBe('WORKSPACE');+ });++ it('lands an app command where its availability says', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.FRONT_COMPONENT_RENDERER,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ }),+ ).toBe('WORKSPACE');++ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.FRONT_COMPONENT_RENDERER,+ availabilityType: CommandMenuItemAvailabilityType.RECORD_SELECTION,+ }),+ ).toBe('SELECTION');+ });++ it('tells a per-object creation command from the view own create', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.CREATE_NEW_RECORD,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL_OBJECT_CONTEXT,+ }),+ ).toBe('THIS_VIEW');++ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.CREATE_NEW_RECORD,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ creationTargetObjectMetadataId: 'object-metadata-id',+ }),+ ).toBe('CREATE_RECORD');+ });++ it('still places a deprecated key from a workspace that has not migrated', () => {+ expect(+ resolveCommandMenuItemSection({+ engineComponentKey: EngineComponentKey.GO_TO_SETTINGS,+ availabilityType: CommandMenuItemAvailabilityType.GLOBAL,+ }),+ ).toBe('GO_TO');+ });+});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuContextApiForContainerType.ts b/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuContextApiForContainerType.tsnew file mode 100644index 00000000000..ba71fdaa8ee--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuContextApiForContainerType.ts@@ -0,0 +1,27 @@+import { type CommandMenuContextApi } from 'twenty-shared/types';++import { CommandMenuItemContainerType } from '@/command-menu-item/types/CommandMenuItemContainerType';++const isPageHostedInSidePanel = ({+ commandMenuContextApi,+ containerType,+}: {+ commandMenuContextApi: CommandMenuContextApi;+ containerType: CommandMenuItemContainerType;+}): boolean =>+ commandMenuContextApi.isInSidePanel &&+ containerType !== CommandMenuItemContainerType.CommandMenuList;++export const getCommandMenuContextApiForContainerType = ({+ commandMenuContextApi,+ containerType,+}: {+ commandMenuContextApi: CommandMenuContextApi;+ containerType: CommandMenuItemContainerType;+}): CommandMenuContextApi => ({+ ...commandMenuContextApi,+ isInSidePanel: isPageHostedInSidePanel({+ commandMenuContextApi,+ containerType,+ }),+});diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuItemObjectSectionHeading.ts b/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuItemObjectSectionHeading.tsnew file mode 100644index 00000000000..e725612b19f--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/getCommandMenuItemObjectSectionHeading.ts@@ -0,0 +1,17 @@+import { type CommandMenuContextApi } from 'twenty-shared/types';+import { capitalize, isNonEmptyString } from 'twenty-shared/utils';++export const getCommandMenuItemObjectSectionHeading = ({+ commandMenuContextApi,+ fallbackHeading,+}: {+ commandMenuContextApi: CommandMenuContextApi;+ fallbackHeading: string;+}): string => {+ const objectLabelPlural =+ commandMenuContextApi.objectMetadataItem.labelPlural;++ return isNonEmptyString(objectLabelPlural)+ ? capitalize(objectLabelPlural)+ : fallbackHeading;+};diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/groupCommandMenuItemsBySection.ts b/packages/twenty-front/src/modules/command-menu-item/utils/groupCommandMenuItemsBySection.tsnew file mode 100644index 00000000000..7c58697442d--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/groupCommandMenuItemsBySection.ts@@ -0,0 +1,28 @@+import { type CommandMenuItemDefinition } from '@/command-menu-item/types/CommandMenuItemDefinition';+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';+import { resolveCommandMenuItemSection } from '@/command-menu-item/utils/resolveCommandMenuItemSection';++export const groupCommandMenuItemsBySection = (+ commandMenuItems: CommandMenuItemDefinition[],+): Record<CommandMenuItemSection, CommandMenuItemDefinition[]> => {+ const commandMenuItemsBySection: Record<+ CommandMenuItemSection,+ CommandMenuItemDefinition[]+ > = {+ SELECTION: [],+ THIS_VIEW: [],+ ASK_AND_FIND: [],+ CREATE_RECORD: [],+ WORKSPACE: [],+ GO_TO: [],+ FALLBACK: [],+ };++ for (const commandMenuItem of commandMenuItems) {+ commandMenuItemsBySection[+ resolveCommandMenuItemSection(commandMenuItem)+ ].push(commandMenuItem);+ }++ return commandMenuItemsBySection;+};diff --git a/packages/twenty-front/src/modules/command-menu-item/utils/resolveCommandMenuItemSection.ts b/packages/twenty-front/src/modules/command-menu-item/utils/resolveCommandMenuItemSection.tsnew file mode 100644index 00000000000..cb63c7f5afb--- /dev/null+++ b/packages/twenty-front/src/modules/command-menu-item/utils/resolveCommandMenuItemSection.ts@@ -0,0 +1,36 @@+import { isDefined } from 'twenty-shared/utils';++import { COMMAND_MENU_ITEM_SECTION_BY_AVAILABILITY_TYPE } from '@/command-menu-item/constants/CommandMenuItemSectionByAvailabilityType';+import { COMMAND_MENU_ITEM_SECTION_BY_ENGINE_COMPONENT_KEY } from '@/command-menu-item/constants/CommandMenuItemSectionByEngineComponentKey';+import { type CommandMenuItemDefinition } from '@/command-menu-item/types/CommandMenuItemDefinition';+import { type CommandMenuItemSection } from '@/command-menu-item/types/CommandMenuItemSection';+import { type EngineComponentKey } from '~/generated-metadata/graphql';++const sectionByEngineComponentKey: Partial<+ Record<EngineComponentKey, CommandMenuItemSection>+> = COMMAND_MENU_ITEM_SECTION_BY_ENGINE_COMPONENT_KEY;++const isPerObjectCreationCommandMenuItem = (+ commandMenuItem: Pick<+ CommandMenuItemDefinition,+ 'creationTargetObjectMetadataId'+ >,+): boolean => isDefined(commandMenuItem.creationTargetObjectMetadataId);++export const resolveCommandMenuItemSection = (+ commandMenuItem: Pick<+ CommandMenuItemDefinition,+ 'engineComponentKey' | 'availabilityType' | 'creationTargetObjectMetadataId'+ >,+): CommandMenuItemSection => {+ if (isPerObjectCreationCommandMenuItem(commandMenuItem)) {+ return 'CREATE_RECORD';+ }++ return (+ sectionByEngineComponentKey[commandMenuItem.engineComponentKey] ??+ COMMAND_MENU_ITEM_SECTION_BY_AVAILABILITY_TYPE[+ commandMenuItem.availabilityType+ ]+ );+};diff --git a/packages/twenty-shared/src/utils/index.ts b/packages/twenty-shared/src/utils/index.tsindex 4fadc5f5655..14c4e8ab4bb 100644--- a/packages/twenty-shared/src/utils/index.ts+++ b/packages/twenty-shared/src/utils/index.ts@@ -282,6 +282,7 @@ export { trimAndRemoveDuplicatedWhitespacesFromObjectStringProperties } from './export { trimAndRemoveDuplicatedWhitespacesFromString } from './trim-and-remove-duplicated-whitespaces-from-string';export { typedObjectEntries } from './typed-object-entries';export { isMetadataGqlOperationSignature } from './typeguard/isMetadataGqlOperationSignature';+export { isNonEmptyString } from './typeguard/isNonEmptyString';export { isPlainObject } from './typeguard/isPlainObject';export { isRecordGqlOperationSignature } from './typeguard/isRecordGqlOperationSignature';export { throwIfNotDefined } from './typeguard/throwIfNotDefined';diff --git a/packages/twenty-shared/src/utils/typeguard/isNonEmptyString.ts b/packages/twenty-shared/src/utils/typeguard/isNonEmptyString.tsnew file mode 100644index 00000000000..1f17e60fa04--- /dev/null+++ b/packages/twenty-shared/src/utils/typeguard/isNonEmptyString.ts@@ -0,0 +1 @@+export { isNonEmptyString } from '@sniptt/guards';