Command Menu
Relevant source files
The following files were used as context for generating this wiki page:
- packages/twenty-front/src/modules/command-menu/components/CommandMenu.tsx
- packages/twenty-front/src/modules/command-menu/hooks/useCommandMenu.ts
- packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx
- packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx
- packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx
- packages/twenty-front/src/modules/command-menu/components/CommandMenuPageInfo.tsx
- packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx
- packages/twenty-front/src/modules/command-menu/components/CommandMenuWorkflowStepInfo.tsx
- packages/twenty-front/src/modules/command-menu/hooks/tests/useUpdateCommandMenuPageInfo.test.tsx
- packages/twenty-front/src/modules/advanced-text-editor/extensions/slash-command/tests/DefaultSlashCommands.test.ts
The Command Menu is a versatile and context-aware side panel that serves as a central hub for commands, navigation, and entity editing throughout the Twenty application. It is not a single-purpose command palette but rather a dynamic container that renders different "pages" based on the user's current context and actions. This allows for a cohesive user experience where complex operations like editing workflow steps, customizing page layouts, or viewing record details are handled within a consistent, animated side panel.
On non-mobile views, the Command Menu appears as a right-hand side panel that animates into view. Its content is determined by a routing system that maps a state-managed page key to a specific React component. This system supports a navigation stack, allowing users to move forward and backward through different pages within the menu.
Architecture and Core Components
The Command Menu's architecture is built around a main layout component, a router, a page configuration map, and several Recoil states for managing its visibility and content.
Sources: packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx, packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx, packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx
Component Hierarchy
The following diagram illustrates the primary component structure of the Command Menu system.
This diagram shows how CommandMenuPageLayout conditionally renders the side panel containing the CommandMenuRouter, which in turn selects and displays a specific page component.
Sources: packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx:10-107, packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx:19-25
CommandMenuPageLayout
This component wraps the main page content and integrates the Command Menu as a side panel. It is responsible for:
- Displaying the main page content alongside the side panel.
- Controlling the visibility and animation of the side panel based on the
isCommandMenuOpenedStateRecoil state. - The panel has a fixed width of
COMMAND_MENU_SIDE_PANEL_WIDTH(400px). - It uses
framer-motionto animate the panel's width and margin, creating a smooth slide-in/out effect. - It handles animation lifecycle events (
onAnimationStart,onAnimationComplete) to manage rendering and cleanup tasks, such as cleaning up state when the closing animation is finished.
Sources: packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx:28-107
CommandMenuRouter
The CommandMenuRouter is the core of the dynamic content system. It does not perform URL-based routing, but rather component routing based on application state.
- It reads the current page from
commandMenuPageState. - It uses a
MapcalledCOMMAND_MENU_PAGES_CONFIGto look up the React component corresponding to the current page enum. - It wraps the rendered page component in an
ActionMenuContextProviderto provide context for any action menus used within the command menu pages. - It also renders the
CommandMenuTopBar, which provides navigation controls and displays the current page title.
Sources: packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx:19-51
State Management (Recoil)
The Command Menu's behavior is primarily driven by a set of Recoil states:
| State | Description | Source File |
|---|---|---|
isCommandMenuOpenedState | A boolean that determines if the side panel is visible. | packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx:41 |
isCommandMenuClosingState | A boolean that indicates the panel is in the process of closing. | packages/twenty-front/src/modules/object-record/components/CommandMenuPageLayout.tsx:42 |
commandMenuPageState | Holds the current CommandMenuPages enum value, acting as the key for the CommandMenuRouter. | packages/twenty-front/src/modules/command-menu/components/CommandMenuRouter.tsx:20 |
commandMenuNavigationStackState | An array that represents the user's navigation history within the command menu, enabling back navigation. | packages/twenty-front/src/modules/command-menu/hooks/__tests__/useUpdateCommandMenuPageInfo.test.tsx:7 |
commandMenuPageInfoState | An object containing the title and Icon for the current page, displayed in the CommandMenuTopBar. | packages/twenty-front/src/modules/command-menu/hooks/__tests__/useUpdateCommandMenuPageInfo.test.tsx:8 |
Page Configuration
The COMMAND_MENU_PAGES_CONFIG constant is a Map that defines all possible pages that can be rendered within the Command Menu. This centralized configuration makes it easy to add or modify pages.
Sources: packages/twenty-front/src/modules/command-menu/constants/CommandMenuPagesConfig.tsx
Page Enum (CommandMenuPages) | Component Rendered | Purpose |
|---|---|---|
Root | CommandMenu | The default root view of the command menu. |
ViewRecord | CommandMenuRecordPage | Displays details of a specific record. |
MergeRecords | CommandMenuMergeRecordPage | UI for merging duplicate records. |
ViewEmailThread | CommandMenuMessageThreadPage | Displays an email thread. |
ViewCalendarEvent | CommandMenuCalendarEventPage | Displays a calendar event. |
EditRichText | CommandMenuEditRichTextPage | An editor for rich text fields. |
WorkflowTriggerSelectType | CommandMenuWorkflowSelectTriggerType | Allows selection of a trigger type for a workflow. |
WorkflowStepCreate | CommandMenuWorkflowCreateStep | UI for creating a new step in a workflow. |
WorkflowStepEdit | CommandMenuWorkflowEditStep | UI for editing an existing workflow step. |
WorkflowStepView | CommandMenuWorkflowViewStep | Read-only view of a workflow step. |
WorkflowRunStepView | CommandMenuWorkflowRunViewStep | View of a specific step in a historical workflow run. |
SearchRecords | CommandMenuSearchRecordsPage | A page for searching records. |
AskAI | CommandMenuAskAIPage | Interface for interacting with an AI assistant. |
ViewPreviousAIChats | CommandMenuAIChatThreadsPage | Displays history of AI chat conversations. |
PageLayoutWidgetTypeSelect | CommandMenuPageLayoutWidgetTypeSelect | Select a widget type for a custom page layout. |
PageLayoutGraphTypeSelect | CommandMenuPageLayoutChartSettings | Configure settings for a chart/graph widget. |
PageLayoutGraphFilter | CommandMenuPageLayoutGraphFilter | Configure filters for a graph widget. |
PageLayoutIframeSettings | CommandMenuPageLayoutIframeSettings | Configure settings for an iframe widget. |
PageLayoutTabSettings | CommandMenuPageLayoutTabSettings | Configure settings for a tab in a page layout. |
Context-Specific Information Display
A key feature of the Command Menu is its ability to display and edit context-specific information in its header. This is managed by the CommandMenuPageInfo component, which acts as a sub-router for different header types.
Sources: packages/twenty-front/src/modules/command-menu/components/CommandMenuPageInfo.tsx, packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx, packages/twenty-front/src/modules/command-menu/components/CommandMenuWorkflowStepInfo.tsx
CommandMenuPageInfo Logic
This diagram shows how CommandMenuPageInfo decides which specialized info component to render.
Inline Title Editing
Components like CommandMenuPageLayoutInfo and CommandMenuWorkflowStepInfo provide an advanced user experience by allowing the title of the context (e.g., a page layout tab or a workflow step) to be edited directly within the Command Menu header.
- They use a custom
TitleInputcomponent. - The title is fetched from the relevant state (e.g.,
draftPageLayoutor workflow version). - When a user edits the title, the changes are saved on blur, enter, or tab.
- The
useUpdateCommandMenuPageInfohook is called to update the title in theCommandMenuTopBarand navigation stack, ensuring UI consistency. - The underlying data is then updated via specific hooks like
updatePageLayoutTaborupdateWorkflowVersionStep.
The sequence diagram below illustrates the process of updating a workflow step's title from the Command Menu.
Sources: packages/twenty-front/src/modules/command-menu/components/CommandMenuWorkflowStepInfo.tsx:132-167, packages/twenty-front/src/modules/command-menu/components/CommandMenuPageLayoutInfo.tsx:75-103, packages/twenty-front/src/modules/command-menu/hooks/tests/useUpdateCommandMenuPageInfo.test.tsx:44-54
Slash Commands in Text Editor
While not part of the main side panel, the "slash command" feature within the AdvancedTextEditor is conceptually related. It provides an in-place command menu for formatting text content.
- Triggered by typing
/. - Presents a list of commands for creating elements like paragraphs, headings (H1, H2, H3), and lists.
- Each command has an
id,title,description,icon, andkeywordsfor searchability. - The
getOnSelectfunction for each command executes the corresponding Tiptap editor action (e.g.,setHeading({ level: 1 })).
Sources: packages/twenty-front/src/modules/advanced-text-editor/extensions/slash-command/tests/DefaultSlashCommands.test.ts, packages/twenty-front/src/modules/advanced-text-editor/extensions/slash-command/tests/SlashCommand.test.ts
Default Slash Commands
| ID | Title (i18n key) | Description (i18n key) | Action |
|---|---|---|---|
paragraph | text | Just start writing with plain text. | setParagraph() |
h1 | heading1 | Big section heading. | setHeading({ level: 1 }) |
h2 | heading2 | Medium section heading. | setHeading({ level: 2 }) |
h3 | heading3 | Small section heading. | setHeading({ level: 3 }) |
bulletList | bulletedList | Create a simple bulleted list. | toggleBulletList() |
orderedList | numberedList | Create a list with numbering. | toggleOrderedList() |
Summary
The Command Menu is a sophisticated and integral part of the Twenty CRM's user interface. It functions as a dynamic, context-sensitive side panel that centralizes a wide range of actions, from simple record viewing to complex configuration of workflows and page layouts. Its modular architecture, based on a state-driven router and a clear page configuration map, makes it extensible and maintainable. By providing a consistent location and interaction model for disparate features, the Command Menu significantly enhances the application's usability and creates a modern, fluid user experience.