Skip to content

The open alternative to Salesforce, designed for AI.

Add sidebar command and tooltips (#24985)

Thomas des Francsf6d511953a18
diff --git a/packages/twenty-docs/getting-started/core-concepts/layout.mdx b/packages/twenty-docs/getting-started/core-concepts/layout.mdx
index 6e94ee69027..567374d5142 100644
--- a/packages/twenty-docs/getting-started/core-concepts/layout.mdx
+++ b/packages/twenty-docs/getting-started/core-concepts/layout.mdx
@@ -12,7 +12,9 @@ The center of the screen is where your records live — people, companies, oppor
<img src="/images/user-guide/home/main-layout.png" style={{width:'100%'}}/>
-## Navigation bar
+<span id="navigation-bar" />
+
+## Sidebar
The left sidebar gives you:
- **Workspace switcher** — switch between workspaces or create a new one (top dropdown)
@@ -24,6 +26,8 @@ The left sidebar gives you:
Drag items to reorder, create folders to group related objects, hide what you don't use.
+Use the collapse button at the top of the sidebar, or choose **Collapse sidebar** from the command menu (`Cmd+K` on Mac or `Ctrl+K` on Windows). When collapsed, use **Expand sidebar** to show it again.
+
<img src="/images/user-guide/home/navigation-bar.png" style={{width:'100%'}}/>
## Command menu
@@ -39,7 +43,7 @@ Press `Cmd+K` (Mac) or `Ctrl+K` (Windows) — or click the three dots in the top
## Search
-Accessible via the Command Menu, the top of the navigation bar, or by pressing `/`. Search works across all objects.
+Accessible via the Command Menu, the top of the sidebar, or by pressing `/`. Search works across all objects.
<img src="/images/user-guide/home/search-bar.png" style={{width:'100%'}}/>
@@ -66,8 +70,7 @@ Each view saves its own filters, sorting, and field visibility. Share views with
When you open a record, the detail page is built from configurable **tabs** and **widgets**. Add, remove, reorder, and resize widgets on a grid — fields, related records, emails, timeline, tasks, notes, files, charts, iframes, and more. Each object type has its own layout.
<Card title="Full Layout guide" icon="arrow-right" href="/user-guide/layout/overview">
- Navigation, views, record pages — detailed reference and how-tos.
+ Sidebar, views, record pages — detailed reference and how-tos.
</Card>
<VimeoEmbed videoId="1185511790" title="Layout" />
-
diff --git a/packages/twenty-docs/getting-started/quickstart.mdx b/packages/twenty-docs/getting-started/quickstart.mdx
index 8fa986a4e25..80dc77534da 100644
--- a/packages/twenty-docs/getting-started/quickstart.mdx
+++ b/packages/twenty-docs/getting-started/quickstart.mdx
@@ -57,7 +57,7 @@ Use the Command Menu (`Cmd+K` / `Ctrl+K`) to import People, Companies, Opportuni
<CardGroup cols={2}>
<Card title="Learn the layout" icon="table-columns" href="/getting-started/core-concepts/layout">
- Navigation, views, command menu, side panel.
+ Sidebar, views, command menu, side panel.
</Card>
<Card title="Build Workflows" icon="bolt" href="/user-guide/workflows/overview">
Automate your business processes.
diff --git a/packages/twenty-docs/user-guide/dashboards/capabilities/dashboards.mdx b/packages/twenty-docs/user-guide/dashboards/capabilities/dashboards.mdx
index d1c3105eb0c..c70ad8bf675 100644
--- a/packages/twenty-docs/user-guide/dashboards/capabilities/dashboards.mdx
+++ b/packages/twenty-docs/user-guide/dashboards/capabilities/dashboards.mdx
@@ -9,7 +9,7 @@ Dashboards in Twenty are organized in a hierarchy: **Dashboards → Tabs → Wid
## Creating a Dashboard
-1. Go to **Dashboards** in the navigation
+1. Go to **Dashboards** in the sidebar
2. Click **+ New Record**
<img src="/images/user-guide/dashboard/dashboard-create-new.png" alt="Create a new dashboard" />
@@ -82,4 +82,3 @@ Dashboards currently display data based on the timezone of the user viewing them
<Note>
**Coming soon**: Dashboard-level filters will allow you to apply filters across all widgets at once, making it faster to explore your data.
</Note>
-
diff --git a/packages/twenty-docs/user-guide/data-model/how-tos/data-model-faq.mdx b/packages/twenty-docs/user-guide/data-model/how-tos/data-model-faq.mdx
index 2b1a20ec031..ac83b4250ea 100644
--- a/packages/twenty-docs/user-guide/data-model/how-tos/data-model-faq.mdx
+++ b/packages/twenty-docs/user-guide/data-model/how-tos/data-model-faq.mdx
@@ -26,12 +26,12 @@ You can rename the label of standard objects (People, Companies, Opportunities),
Yes, you can change the icon for both standard and custom objects in **Settings → Data Model**.
</Accordion>
-<Accordion title="Can I reorder objects in the left navigation bar?">
-Not yet. Object ordering in the navigation is currently fixed, but this feature is planned for a future release.
+<Accordion title="Can I reorder objects in the sidebar?">
+Yes. With the **Layouts** permission, enter sidebar customization mode to drag and drop items in the **Workspace** section. This order is shared across the workspace. Items in **Favorites** are personal to each user and can be reordered without entering customization mode. See the [Sidebar guide](/user-guide/layout/capabilities/navigation).
</Accordion>
-<Accordion title="Can I hide objects from the left navigation bar?">
-All active objects appear in the navigation. You can deactivate objects you don't need under **Settings → Data Model**.
+<Accordion title="Can I hide objects from the sidebar?">
+You can hide objects you don't use from the sidebar without deleting them. You can show them again from **Settings → Data Model**. See the [Sidebar guide](/user-guide/layout/capabilities/navigation).
</Accordion>
</AccordionGroup>
diff --git a/packages/twenty-docs/user-guide/getting-started/how-tos/navigate-around-twenty.mdx b/packages/twenty-docs/user-guide/getting-started/how-tos/navigate-around-twenty.mdx
index 1eae6279497..60f9d50e106 100644
--- a/packages/twenty-docs/user-guide/getting-started/how-tos/navigate-around-twenty.mdx
+++ b/packages/twenty-docs/user-guide/getting-started/how-tos/navigate-around-twenty.mdx
@@ -10,7 +10,9 @@ You can **view, edit, or delete records** from there, as well as **create new vi
<img src="/images/user-guide/home/main-layout.png" style={{width:'100%'}}/>
-## The Navigation Bar
+<span id="the-navigation-bar" />
+
+## The Sidebar
On the left side, from the top to the bottom, you'll be able to:
- Switch between your **several workspaces** using the dropdown menu or create a new workspace
- Use the **search bar** (press `/` to focus on it instantly)
@@ -19,6 +21,8 @@ On the left side, from the top to the bottom, you'll be able to:
- Switch between different objects
- **Create automations** using workflows
+Use the collapse button at the top of the sidebar, or choose **Collapse sidebar** from the command menu. When collapsed, use **Expand sidebar** to show it again.
+
<img src="/images/user-guide/home/navigation-bar.png" style={{width:'100%'}}/>
## The Command Menu
@@ -36,7 +40,7 @@ From there, you can:
<img src="/images/user-guide/home/command-menu.png" style={{width:'100%'}}/>
## The Search Bar
-The search bar is accessible via the Command Menu, at the top of your navigation bar, or by pressing `/` to focus on it instantly. Search works across all objects.
+The search bar is accessible via the Command Menu, at the top of your sidebar, or by pressing `/` to focus on it instantly. Search works across all objects.
<img src="/images/user-guide/home/search-bar.png" style={{width:'100%'}}/>
@@ -75,4 +79,3 @@ Open your Settings from the top left to:
- **Open the Documentation** to browse the User Guide and developer docs
<Note>If you do not see all those sections under Settings, reach out to your workspace administrator — some sections have restricted access.</Note>
-
diff --git a/packages/twenty-docs/user-guide/introduction.mdx b/packages/twenty-docs/user-guide/introduction.mdx
index 2b0a954f714..bf8e6684388 100644
--- a/packages/twenty-docs/user-guide/introduction.mdx
+++ b/packages/twenty-docs/user-guide/introduction.mdx
@@ -33,7 +33,7 @@ import { CardTitle } from "/snippets/card-title.mdx"
<Card href="/user-guide/layout/overview" img="/images/user-guide/halftone/layout.png">
<CardTitle>Layout</CardTitle>
- Navigation, views, and record page customization.
+ Sidebar, views, and record page customization.
</Card>
<Card href="/user-guide/dashboards/overview" img="/images/user-guide/halftone/dashboards.png">
diff --git a/packages/twenty-docs/user-guide/layout/capabilities/navigation.mdx b/packages/twenty-docs/user-guide/layout/capabilities/navigation.mdx
index bdeea15a98f..b4803f56e82 100644
--- a/packages/twenty-docs/user-guide/layout/capabilities/navigation.mdx
+++ b/packages/twenty-docs/user-guide/layout/capabilities/navigation.mdx
@@ -1,13 +1,21 @@
---
-title: Navigation
+title: Sidebar
description: Customize the left sidebar to match how your team works.
---
The left sidebar is your primary way to move around Twenty. It's fully customizable — you can reorganize it to match your workflow without touching any settings page.
+## Collapsing and expanding the sidebar
+
+On desktop, click the collapse button at the top of the sidebar to make more room for your records. Hover over the button to see the **Collapse sidebar** tooltip. When collapsed, the button's tooltip changes to **Expand sidebar**.
+
+You can also open the command menu with `Cmd+K` (Mac) or `Ctrl+K` (Windows), search for **sidebar**, and choose **Collapse sidebar** or **Expand sidebar**. The command reflects the sidebar's current state and closes the command menu after you select it.
+
## Reordering items
-Drag and drop any item in the sidebar to change its position. The order is saved per user, so each team member can arrange their own sidebar.
+The order of items in the **Workspace** section is shared across the workspace. With the **Layouts** permission, hover over **Workspace** and click the wrench icon to enter sidebar customization mode. Drag and drop items to change their positions, then save your changes.
+
+Items in **Favorites** are personal to each user and can be reordered by dragging and dropping them without entering customization mode.
## Folders
@@ -35,4 +43,4 @@ Press `Cmd+K` (or `Ctrl+K`) to open the command menu — a quick-access search b
To customize the sidebar, hover over the "Workspace" section in the sidebar and click the wrench icon.
-<img src="/images/user-guide/layout/navigation-edit-icon.png" alt="Navigation edit icon" />
\ No newline at end of file
+<img src="/images/user-guide/layout/navigation-edit-icon.png" alt="Sidebar customization icon" />
diff --git a/packages/twenty-docs/user-guide/layout/overview.mdx b/packages/twenty-docs/user-guide/layout/overview.mdx
index 9796d1540f3..3335a44f7a8 100644
--- a/packages/twenty-docs/user-guide/layout/overview.mdx
+++ b/packages/twenty-docs/user-guide/layout/overview.mdx
@@ -5,7 +5,9 @@ description: Customize how you navigate, browse, and view records in Twenty.
Twenty's layout is customizable at three levels: how you navigate the app, how you browse lists of records, and what you see when you open an individual record.
-## Navigation
+<span id="navigation" />
+
+## Sidebar
The left sidebar is fully customizable. You can:
- **Reorder items** by dragging and dropping
@@ -13,8 +15,9 @@ The left sidebar is fully customizable. You can:
- **Hide objects** you don't use
- **Add custom links** to external tools
- **Pin favorites** for quick access to views, records, or searches
+- **Collapse or expand the sidebar** from its button or the command menu
-[Navigation reference →](/user-guide/layout/capabilities/navigation)
+[Sidebar reference →](/user-guide/layout/capabilities/navigation)
## Views
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.tsx
index 2258b154101..0c08f83d845 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
@@ -4,24 +4,54 @@ import { PINNED_COMMAND_MENU_ITEMS_GAP } from '@/command-menu-item/display/const
import { commandMenuPinnedInlineLayoutFamilyState } from '@/command-menu-item/display/states/commandMenuPinnedInlineLayoutFamilyState';
import { getVisibleCommandMenuItemCountForContainerWidth } from '@/command-menu-item/display/utils/getVisibleCommandMenuItemCountForContainerWidth';
import { groupCommandMenuItems } from '@/command-menu-item/utils/groupCommandMenuItems';
+import { CommandMenuItem } from '@/command-menu/components/CommandMenuItem';
+import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
+import { useNavigationDrawerTogglePresentation } from '@/navigation/hooks/useNavigationDrawerTogglePresentation';
+import { useToggleNavigationDrawer } from '@/navigation/hooks/useToggleNavigationDrawer';
import { SidePanelGroup } from '@/side-panel/components/SidePanelGroup';
import { SidePanelList } from '@/side-panel/components/SidePanelList';
+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 { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
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 { useContext, useMemo } from 'react';
import { CommandMenuItemAvailabilityType } from '~/generated-metadata/graphql';
+import { normalizeSearchText } from '~/utils/normalizeSearchText';
+
+const TOGGLE_NAVIGATION_DRAWER_COMMAND_ID = 'toggle-navigation-drawer';
export const SidePanelCommandMenuItemDisplayPage = () => {
const { t } = useLingui();
+ const isMobile = useIsMobile();
+ const isSettingsDrawer = useIsSettingsDrawer();
+ const { isNavigationDrawerExpanded, toggleNavigationDrawer } =
+ useToggleNavigationDrawer();
+ const { closeSidePanelMenu } = useSidePanelMenu();
const sidePanelSearch = useAtomStateValue(sidePanelSearchState);
- const { commandMenuItems, commandMenuContextApi } =
+ const { commandMenuItems, commandMenuContextApi, isInPreviewMode } =
useContext(CommandMenuContext);
+ const { label: navigationDrawerCommandLabel, Icon: NavigationDrawerIcon } =
+ useNavigationDrawerTogglePresentation(isNavigationDrawerExpanded);
+ const shouldDisplayNavigationDrawerCommand =
+ !isMobile &&
+ !isSettingsDrawer &&
+ !isInPreviewMode &&
+ normalizeSearchText(navigationDrawerCommandLabel).includes(
+ normalizeSearchText(sidePanelSearch.trim()),
+ );
+
+ const handleToggleNavigationDrawer = () => {
+ toggleNavigationDrawer();
+ closeSidePanelMenu();
+ };
+
// The command menu list surfaces whatever overflowed out of the page header.
const commandMenuPinnedInlineLayout = useAtomFamilyStateValue(
commandMenuPinnedInlineLayoutFamilyState,
@@ -95,7 +125,9 @@ export const SidePanelCommandMenuItemDisplayPage = () => {
);
const hasNoMatchingItems =
- !matchingPinnedItems.length && !matchingOtherItems.length;
+ !matchingPinnedItems.length &&
+ !matchingOtherItems.length &&
+ !shouldDisplayNavigationDrawerCommand;
const shouldDisplayFallbackItems =
hasNoMatchingItems && fallbackCommandMenuItems.length > 0;
@@ -104,10 +136,15 @@ export const SidePanelCommandMenuItemDisplayPage = () => {
isSearchActive && hasNoMatchingItems && !shouldDisplayFallbackItems;
const selectableItemIds = [
- ...matchingPinnedItems,
- ...matchingOtherItems,
- ...(shouldDisplayFallbackItems ? fallbackCommandMenuItems : []),
- ].map((item) => item.id);
+ ...matchingPinnedItems.map((item) => item.id),
+ ...matchingOtherItems.map((item) => item.id),
+ ...(shouldDisplayNavigationDrawerCommand
+ ? [TOGGLE_NAVIGATION_DRAWER_COMMAND_ID]
+ : []),
+ ...(shouldDisplayFallbackItems
+ ? fallbackCommandMenuItems.map((item) => item.id)
+ : []),
+ ];
return (
<SidePanelList
@@ -121,11 +158,25 @@ export const SidePanelCommandMenuItemDisplayPage = () => {
))}
</SidePanelGroup>
)}
- {matchingOtherItems.length > 0 && (
+ {(matchingOtherItems.length > 0 ||
+ shouldDisplayNavigationDrawerCommand) && (
<SidePanelGroup heading={t`Other`}>
{matchingOtherItems.map((item) => (
<CommandMenuItemRenderer item={item} key={item.id} />
))}
+ {shouldDisplayNavigationDrawerCommand && (
+ <SelectableListItem
+ itemId={TOGGLE_NAVIGATION_DRAWER_COMMAND_ID}
+ onEnter={handleToggleNavigationDrawer}
+ >
+ <CommandMenuItem
+ id={TOGGLE_NAVIGATION_DRAWER_COMMAND_ID}
+ label={navigationDrawerCommandLabel}
+ Icon={NavigationDrawerIcon}
+ onClick={handleToggleNavigationDrawer}
+ />
+ </SelectableListItem>
+ )}
</SidePanelGroup>
)}
{shouldDisplayFallbackItems && (
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.tsx
index 2c52b819a39..ed7e0d48c0c 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
@@ -5,16 +5,21 @@ import {
type StoryObj,
} from '@storybook/react-vite';
import { Provider as JotaiProvider } from 'jotai';
-import { expect, waitFor, within } from 'storybook/test';
+import { Context as ResponsiveContext } from 'react-responsive';
+import { MemoryRouter } from 'react-router-dom';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
import { CommandMenuContext } from '@/command-menu-item/contexts/CommandMenuContext';
import { EMPTY_COMMAND_MENU_CONTEXT_API } from '@/command-menu-item/constants/EmptyCommandMenuContextApi';
import { SidePanelCommandMenuItemDisplayPage } from '@/command-menu-item/display/components/SidePanelCommandMenuItemDisplayPage';
import { commandMenuPinnedInlineLayoutFamilyState } from '@/command-menu-item/display/states/commandMenuPinnedInlineLayoutFamilyState';
import { CommandMenuComponentInstanceContext } from '@/command-menu/states/contexts/CommandMenuComponentInstanceContext';
+import { isSidePanelOpenedState } from '@/side-panel/states/isSidePanelOpenedState';
import { sidePanelSearchState } from '@/side-panel/states/sidePanelSearchState';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
-import { RouterDecorator } from 'twenty-ui/testing';
import { ContextStoreDecorator } from '~/testing/decorators/ContextStoreDecorator';
import { ObjectMetadataItemsDecorator } from '~/testing/decorators/ObjectMetadataItemsDecorator';
import { SnackBarDecorator } from '~/testing/decorators/SnackBarDecorator';
@@ -81,17 +86,34 @@ const FALLBACK_ITEM = createCommandMenuItem({
type CreateDecoratorParams = {
commandMenuItems: CommandMenuItemFieldsFragment[];
sidePanelSearch: string;
- pinnedItemsContainerWidth: number;
+ pinnedItemsContainerWidth?: number;
+ isNavigationDrawerExpanded?: boolean;
+ isInPreviewMode?: boolean;
+ pathname?: string;
+ viewportWidth?: number;
};
const createDecorator =
({
commandMenuItems,
sidePanelSearch,
- pinnedItemsContainerWidth,
+ pinnedItemsContainerWidth = 1000,
+ isNavigationDrawerExpanded = true,
+ isInPreviewMode = false,
+ pathname = '/objects/companies',
+ viewportWidth = 1280,
}: CreateDecoratorParams): Decorator =>
(Story) => {
jotaiStore.set(sidePanelSearchState.atom, sidePanelSearch);
+ jotaiStore.set(isSidePanelOpenedState.atom, true);
+ jotaiStore.set(
+ isNavigationDrawerExpandedState.atom,
+ isNavigationDrawerExpanded,
+ );
+ jotaiStore.set(
+ navigationDrawerActiveTabState.atom,
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ );
jotaiStore.set(
commandMenuPinnedInlineLayoutFamilyState.atomFamily('page-header'),
{
@@ -104,21 +126,25 @@ const createDecorator =
return (
<JotaiProvider store={jotaiStore}>
- <CommandMenuComponentInstanceContext.Provider
- value={{ instanceId: 'story-command-menu' }}
- >
- <CommandMenuContext.Provider
- value={{
- displayType: 'listItem',
- containerType: CommandMenuItemContainerType.CommandMenuList,
- commandMenuItems,
- commandMenuContextApi: EMPTY_COMMAND_MENU_CONTEXT_API,
- isInPreviewMode: false,
- }}
- >
- <Story />
- </CommandMenuContext.Provider>
- </CommandMenuComponentInstanceContext.Provider>
+ <ResponsiveContext.Provider value={{ width: viewportWidth }}>
+ <MemoryRouter initialEntries={[pathname]}>
+ <CommandMenuComponentInstanceContext.Provider
+ value={{ instanceId: 'story-command-menu' }}
+ >
+ <CommandMenuContext.Provider
+ value={{
+ displayType: 'listItem',
+ containerType: CommandMenuItemContainerType.CommandMenuList,
+ commandMenuItems,
+ commandMenuContextApi: EMPTY_COMMAND_MENU_CONTEXT_API,
+ isInPreviewMode,
+ }}
+ >
+ <Story />
+ </CommandMenuContext.Provider>
+ </CommandMenuComponentInstanceContext.Provider>
+ </MemoryRouter>
+ </ResponsiveContext.Provider>
</JotaiProvider>
);
};
@@ -130,7 +156,6 @@ const meta: Meta<typeof SidePanelCommandMenuItemDisplayPage> = {
ContextStoreDecorator,
ObjectMetadataItemsDecorator,
SnackBarDecorator,
- RouterDecorator,
],
};
@@ -149,7 +174,7 @@ export const EmptySearchWithAllPinnedItemsInHeader: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- expect(await canvas.findByText('Search records')).toBeVisible();
+ expect(await canvas.findByText('Collapse sidebar')).toBeVisible();
await waitFor(() => {
expect(canvas.queryByText('No results found')).not.toBeInTheDocument();
});
@@ -168,7 +193,7 @@ export const WhitespaceOnlySearchWithAllPinnedItemsInHeader: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- expect(await canvas.findByText('Search records')).toBeVisible();
+ expect(await canvas.findByText('Collapse sidebar')).toBeVisible();
await waitFor(() => {
expect(canvas.queryByText('No results found')).not.toBeInTheDocument();
});
@@ -226,6 +251,8 @@ export const SearchWithoutMatchingItemsAndWithoutFallback: Story = {
const canvas = within(canvasElement);
expect(await canvas.findByText('No results found')).toBeVisible();
+ expect(canvas.queryByText('Collapse sidebar')).not.toBeInTheDocument();
+ expect(canvas.queryByText('Expand sidebar')).not.toBeInTheDocument();
},
};
@@ -246,3 +273,102 @@ export const SearchWithoutMatchingItemsAndWithFallback: Story = {
});
},
};
+
+export const CollapseSidebar: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM, FALLBACK_ITEM],
+ sidePanelSearch: 'COLLAPSE',
+ }),
+ ],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(canvas.queryByText('Search records')).not.toBeInTheDocument();
+ await userEvent.click(await canvas.findByText('Collapse sidebar'));
+
+ expect(jotaiStore.get(isNavigationDrawerExpandedState.atom)).toBe(false);
+ expect(jotaiStore.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ expect(jotaiStore.get(isSidePanelOpenedState.atom)).toBe(false);
+ },
+};
+
+export const ExpandSidebar: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM, FALLBACK_ITEM],
+ sidePanelSearch: 'expand',
+ isNavigationDrawerExpanded: false,
+ }),
+ ],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(canvas.queryByText('Collapse sidebar')).not.toBeInTheDocument();
+ await userEvent.click(await canvas.findByText('Expand sidebar'));
+
+ expect(jotaiStore.get(isNavigationDrawerExpandedState.atom)).toBe(true);
+ expect(jotaiStore.get(isSidePanelOpenedState.atom)).toBe(false);
+ },
+};
+
+export const SearchSidebar: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM, FALLBACK_ITEM],
+ sidePanelSearch: 'sidebar',
+ }),
+ ],
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ expect(await canvas.findByText('Collapse sidebar')).toBeVisible();
+ expect(canvas.queryByText('Search records')).not.toBeInTheDocument();
+ expect(canvas.queryByText('No results found')).not.toBeInTheDocument();
+ },
+};
+
+export const SearchSidebarWithCaseAndWhitespace: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM, FALLBACK_ITEM],
+ sidePanelSearch: ' SIDEBAR ',
+ }),
+ ],
+ play: SearchSidebar.play,
+};
+
+export const HiddenOnMobile: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM],
+ sidePanelSearch: 'sidebar',
+ viewportWidth: 375,
+ }),
+ ],
+ play: SearchWithoutMatchingItemsAndWithoutFallback.play,
+};
+
+export const HiddenInSettings: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM],
+ sidePanelSearch: 'sidebar',
+ pathname: '/settings/profile',
+ }),
+ ],
+ play: HiddenOnMobile.play,
+};
+
+export const HiddenInLayoutPreview: Story = {
+ decorators: [
+ createDecorator({
+ commandMenuItems: [OTHER_ITEM],
+ sidePanelSearch: 'sidebar',
+ isInPreviewMode: true,
+ }),
+ ],
+ play: HiddenOnMobile.play,
+};
diff --git a/packages/twenty-front/src/modules/navigation/hooks/__tests__/useToggleNavigationDrawer.test.tsx b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useToggleNavigationDrawer.test.tsx
new file mode 100644
index 00000000000..eea973c5408
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/__tests__/useToggleNavigationDrawer.test.tsx
@@ -0,0 +1,65 @@
+import { useToggleNavigationDrawer } from '@/navigation/hooks/useToggleNavigationDrawer';
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
+import { act, renderHook } from '@testing-library/react';
+import { createStore, Provider } from 'jotai';
+import { type ReactNode } from 'react';
+
+const renderToggleNavigationDrawer = (isExpanded: boolean) => {
+ const store = createStore();
+
+ store.set(isNavigationDrawerExpandedState.atom, isExpanded);
+ store.set(
+ navigationDrawerActiveTabState.atom,
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ );
+
+ const { result } = renderHook(() => useToggleNavigationDrawer(), {
+ wrapper: ({ children }: { children: ReactNode }) => (
+ <Provider store={store}>{children}</Provider>
+ ),
+ });
+
+ return { result, store };
+};
+
+describe('useToggleNavigationDrawer', () => {
+ beforeEach(() => {
+ localStorage.clear();
+ });
+
+ it('collapses the drawer and returns to the navigation menu', () => {
+ const { result, store } = renderToggleNavigationDrawer(true);
+
+ act(() => result.current.toggleNavigationDrawer());
+
+ expect(result.current.isNavigationDrawerExpanded).toBe(false);
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ });
+
+ it('expands the drawer without changing its active tab', () => {
+ const { result, store } = renderToggleNavigationDrawer(false);
+
+ act(() => result.current.toggleNavigationDrawer());
+
+ expect(result.current.isNavigationDrawerExpanded).toBe(true);
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.AI_CHAT_HISTORY,
+ );
+ });
+
+ it('can expand the drawer again after collapsing it', () => {
+ const { result, store } = renderToggleNavigationDrawer(true);
+
+ act(() => result.current.toggleNavigationDrawer());
+ act(() => result.current.toggleNavigationDrawer());
+
+ expect(result.current.isNavigationDrawerExpanded).toBe(true);
+ expect(store.get(navigationDrawerActiveTabState.atom)).toBe(
+ NAVIGATION_DRAWER_TABS.NAVIGATION_MENU,
+ );
+ });
+});
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerTogglePresentation.ts b/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerTogglePresentation.ts
new file mode 100644
index 00000000000..3f62373ba7c
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/useNavigationDrawerTogglePresentation.ts
@@ -0,0 +1,15 @@
+import { useLingui } from '@lingui/react/macro';
+import {
+ IconLayoutSidebarLeftCollapse,
+ IconLayoutSidebarRightCollapse,
+} from 'twenty-ui/icon';
+
+export const useNavigationDrawerTogglePresentation = (
+ isNavigationDrawerExpanded: boolean,
+) => {
+ const { t } = useLingui();
+
+ return isNavigationDrawerExpanded
+ ? { label: t`Collapse sidebar`, Icon: IconLayoutSidebarLeftCollapse }
+ : { label: t`Expand sidebar`, Icon: IconLayoutSidebarRightCollapse };
+};
diff --git a/packages/twenty-front/src/modules/navigation/hooks/useToggleNavigationDrawer.ts b/packages/twenty-front/src/modules/navigation/hooks/useToggleNavigationDrawer.ts
new file mode 100644
index 00000000000..c67cba4969e
--- /dev/null
+++ b/packages/twenty-front/src/modules/navigation/hooks/useToggleNavigationDrawer.ts
@@ -0,0 +1,22 @@
+import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
+import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
+import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
+import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
+
+export const useToggleNavigationDrawer = () => {
+ const [isNavigationDrawerExpanded, setIsNavigationDrawerExpanded] =
+ useAtomState(isNavigationDrawerExpandedState);
+ const setNavigationDrawerActiveTab = useSetAtomState(
+ navigationDrawerActiveTabState,
+ );
+
+ const toggleNavigationDrawer = () => {
+ if (isNavigationDrawerExpanded) {
+ setNavigationDrawerActiveTab(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU);
+ }
+ setIsNavigationDrawerExpanded((previousIsExpanded) => !previousIsExpanded);
+ };
+
+ return { isNavigationDrawerExpanded, toggleNavigationDrawer };
+};
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton.tsx
index 7b5e537a136..9120fa49460 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton.tsx
@@ -1,17 +1,11 @@
import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';
-import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
+import { useNavigationDrawerTogglePresentation } from '@/navigation/hooks/useNavigationDrawerTogglePresentation';
+import { useToggleNavigationDrawer } from '@/navigation/hooks/useToggleNavigationDrawer';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
-import { navigationDrawerActiveTabState } from '@/ui/navigation/states/navigationDrawerActiveTabState';
-import { NAVIGATION_DRAWER_TABS } from '@/ui/navigation/states/navigationDrawerTabs';
-import { useAtomState } from '@/ui/utilities/state/jotai/hooks/useAtomState';
-import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
-import { t } from '@lingui/core/macro';
import { styled } from '@linaria/react';
-import {
- IconLayoutSidebarLeftCollapse,
- IconLayoutSidebarRightCollapse,
-} from 'twenty-ui/icon';
+import { useId } from 'react';
import { LightIconButton } from 'twenty-ui/input';
+import { AppTooltip, TooltipDelay, TooltipPosition } from 'twenty-ui/surfaces';
import { themeCssVariables } from 'twenty-ui/theme-constants';
const StyledCollapseButton = styled.div`
@@ -35,39 +29,33 @@ export const NavigationDrawerCollapseButton = ({
}: NavigationDrawerCollapseButtonProps) => {
const isMobile = useIsMobile();
const isSettingsDrawer = useIsSettingsDrawer();
- const [isNavigationDrawerExpanded, setIsNavigationDrawerExpanded] =
- useAtomState(isNavigationDrawerExpandedState);
- const setNavigationDrawerActiveTab = useSetAtomState(
- navigationDrawerActiveTabState,
+ const { toggleNavigationDrawer } = useToggleNavigationDrawer();
+ const tooltipId = useId();
+ const { label, Icon } = useNavigationDrawerTogglePresentation(
+ direction === 'left',
);
- const handleClick = () => {
- if (isNavigationDrawerExpanded) {
- setNavigationDrawerActiveTab(NAVIGATION_DRAWER_TABS.NAVIGATION_MENU);
- }
- setIsNavigationDrawerExpanded((previousIsExpanded) => !previousIsExpanded);
- };
-
// The main navigation is a page on mobile, so there is no drawer to toggle.
if (isMobile && !isSettingsDrawer) {
return null;
}
return (
- <StyledCollapseButton className={className} onClick={handleClick}>
+ <StyledCollapseButton className={className} data-tooltip-id={tooltipId}>
<LightIconButton
- Icon={
- direction === 'left'
- ? IconLayoutSidebarLeftCollapse
- : IconLayoutSidebarRightCollapse
- }
+ Icon={Icon}
accent="secondary"
size="small"
- aria-label={
- direction === 'left'
- ? t`Collapse navigation panel`
- : t`Expand navigation panel`
- }
+ onClick={toggleNavigationDrawer}
+ aria-label={label}
+ />
+ <AppTooltip
+ anchorSelect={`[data-tooltip-id='${tooltipId}'] > button`}
+ content={label}
+ delay={TooltipDelay.longDelay}
+ place={TooltipPosition.Bottom}
+ offset={5}
+ noArrow
/>
</StyledCollapseButton>
);
diff --git a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawerCollapseButton.stories.tsx b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawerCollapseButton.stories.tsx
index 5f46a03fc3a..75a2ebb1b77 100644
--- a/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawerCollapseButton.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/navigation/navigation-drawer/components/__stories__/NavigationDrawerCollapseButton.stories.tsx
@@ -1,4 +1,5 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { expect, userEvent, waitFor, within } from 'storybook/test';
import { NavigationDrawerCollapseButton } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerCollapseButton';
import { ComponentDecorator, RouterDecorator } from 'twenty-ui/testing';
@@ -7,9 +8,28 @@ const meta: Meta<typeof NavigationDrawerCollapseButton> = {
title: 'UI/Navigation/NavigationDrawer/NavigationDrawerCollapseButton',
decorators: [ComponentDecorator, RouterDecorator],
component: NavigationDrawerCollapseButton,
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const label =
+ args.direction === 'right' ? 'Expand sidebar' : 'Collapse sidebar';
+
+ await userEvent.hover(canvas.getByRole('button', { name: label }));
+
+ const tooltip = await within(canvasElement.ownerDocument.body).findByRole(
+ 'tooltip',
+ { name: label },
+ { timeout: 2000 },
+ );
+
+ await waitFor(() => expect(tooltip).toBeVisible());
+ },
};
export default meta;
type Story = StoryObj<typeof NavigationDrawerCollapseButton>;
export const Default: Story = {};
+
+export const Expand: Story = {
+ args: { direction: 'right' },
+};