Add tab param to open a record side panel page on a specific tab (#22905)
## Context
`CommandOpenSidePanelPage` (and `openSidePanelPage` in the front
component SDK) could open a record in the side panel, but always landed
on the default tab. This adds an optional `tab` param to the
`ViewRecord` page params so an app command can open a record directly on
a specific tab.
## What changed
- **twenty-sdk**: `OpenSidePanelPageParams` `ViewRecord` variant accepts
an optional `tab` (a page layout tab id). Since
`CommandOpenSidePanelPage` props are `OpenSidePanelPageParams`, the
component picks it up automatically.
- **twenty-front**:
- New `setRecordPageActiveTabId` util resolves the record page layout
for the object (custom layout from the store, or the default layout id)
and presets `activeTabIdComponentState` on the tab list instance
(`${pageLayoutId}-tab-list-${recordId}`), which is shared by the side
panel and the full record page.
- `useOpenRecordInSidePanel` accepts `tab` and presets the active tab
before navigating; it also applies when the record is already open in
the side panel (tab switch only).
- `useFrontComponentExecutionContext` forwards `tab` to the side panel
open, and presets the tab when falling back to full-page navigation
(mobile, or objects that can't open in the side panel).
- **Docs**: mention the optional `tab` id in the
`CommandOpenSidePanelPage` description.
Unknown tab ids are harmless: `PageLayoutTabListEffect` falls back to
the layout's default tab when the preset id doesn't exist in the layout.
Dashboards are skipped since their layout id comes from record data, not
object metadata.
## Tests
- `useOpenRecordInSidePanel`: new test asserting the active tab atom is
preset on the correct tab list instance id.
- `useFrontComponentExecutionContext`: new tests for tab passthrough to
the side panel and tab preset on full-page fallback.
- `npx nx typecheck twenty-front`, `typecheck twenty-sdk`,
`lint:diff-with-main twenty-front`, `lint twenty-sdk` all green.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01VaWY1H9RZqgJkytqZakvZi)_
<!-- This is an auto-generated description by cubic. -->
<a
href="https://cubic.dev/pr/twentyhq/twenty/pull/22905?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->
This commit is contained in:
+63
@@ -27,6 +27,7 @@ const mockEnqueueWarningSnackBar = jest.fn();
|
||||
const mockCloseSidePanelMenu = jest.fn();
|
||||
const mockSetCommandMenuItemProgress = jest.fn();
|
||||
const mockCopyToClipboard = jest.fn();
|
||||
const mockSetRecordPageActiveTabId = jest.fn();
|
||||
|
||||
let mockCurrentUser: { id: string } | null = { id: 'user-123' };
|
||||
let mockIsMobile = false;
|
||||
@@ -130,6 +131,11 @@ jest.mock('~/hooks/useCopyToClipboard', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
jest.mock('@/page-layout/utils/setRecordPageActiveTabId', () => ({
|
||||
setRecordPageActiveTabId: (params: unknown) =>
|
||||
mockSetRecordPageActiveTabId(params),
|
||||
}));
|
||||
|
||||
const renderUseFrontComponentExecutionContext = (
|
||||
params: Omit<
|
||||
Parameters<typeof useFrontComponentExecutionContext>[0],
|
||||
@@ -397,6 +403,63 @@ describe('useFrontComponentExecutionContext', () => {
|
||||
expect(mockNavigateSidePanel).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should forward the tab to the side panel record page', async () => {
|
||||
const { result } = renderUseFrontComponentExecutionContext({
|
||||
frontComponentId: FRONT_COMPONENT_ID,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.frontComponentHostCommunicationApi.openSidePanelPage(
|
||||
{
|
||||
page: SidePanelPages.ViewRecord,
|
||||
recordId: 'lead-1',
|
||||
objectNameSingular: 'lead',
|
||||
tab: 'tab-emails',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
expect(mockOpenRecordInSidePanel).toHaveBeenCalledWith({
|
||||
recordId: 'lead-1',
|
||||
objectNameSingular: 'lead',
|
||||
tab: 'tab-emails',
|
||||
resetNavigationStack: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('should set the record page active tab when falling back to full-page navigation', async () => {
|
||||
mockIsMobile = true;
|
||||
|
||||
const { result } = renderUseFrontComponentExecutionContext({
|
||||
frontComponentId: FRONT_COMPONENT_ID,
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
await result.current.frontComponentHostCommunicationApi.openSidePanelPage(
|
||||
{
|
||||
page: SidePanelPages.ViewRecord,
|
||||
recordId: 'lead-1',
|
||||
objectNameSingular: 'lead',
|
||||
tab: 'tab-emails',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
expect(mockSetRecordPageActiveTabId).toHaveBeenCalledWith({
|
||||
recordId: 'lead-1',
|
||||
objectNameSingular: 'lead',
|
||||
tabId: 'tab-emails',
|
||||
store: expect.anything(),
|
||||
});
|
||||
expect(mockNavigateApp).toHaveBeenCalledWith(
|
||||
AppPath.RecordShowPage,
|
||||
{ objectNameSingular: 'lead', objectRecordId: 'lead-1' },
|
||||
undefined,
|
||||
undefined,
|
||||
);
|
||||
expect(mockOpenRecordInSidePanel).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should fall back to full-page navigation on mobile', async () => {
|
||||
mockIsMobile = true;
|
||||
|
||||
|
||||
+13
-1
@@ -28,6 +28,7 @@ import { useOpenFrontComponentInSidePanel } from '@/side-panel/hooks/useOpenFron
|
||||
import { useOpenRecordInSidePanel } from '@/side-panel/hooks/useOpenRecordInSidePanel';
|
||||
import { useOpenRichTextInSidePanel } from '@/side-panel/hooks/useOpenRichTextInSidePanel';
|
||||
import { useSidePanelMenu } from '@/side-panel/hooks/useSidePanelMenu';
|
||||
import { setRecordPageActiveTabId } from '@/page-layout/utils/setRecordPageActiveTabId';
|
||||
import { sidePanelSearchState } from '@/side-panel/states/sidePanelSearchState';
|
||||
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
|
||||
import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';
|
||||
@@ -129,9 +130,19 @@ export const useFrontComponentExecutionContext = ({
|
||||
const openSidePanelPage: FrontComponentHostCommunicationApi['openSidePanelPage'] =
|
||||
async (params) => {
|
||||
if (params.page === SidePanelPages.ViewRecord) {
|
||||
const { recordId, objectNameSingular, resetNavigationStack } = params;
|
||||
const { recordId, objectNameSingular, tab, resetNavigationStack } =
|
||||
params;
|
||||
|
||||
if (isMobile || !canOpenObjectInSidePanel(objectNameSingular)) {
|
||||
if (isDefined(tab)) {
|
||||
setRecordPageActiveTabId({
|
||||
recordId,
|
||||
objectNameSingular,
|
||||
tabId: tab,
|
||||
store,
|
||||
});
|
||||
}
|
||||
|
||||
await navigate(AppPath.RecordShowPage, {
|
||||
objectNameSingular,
|
||||
objectRecordId: recordId,
|
||||
@@ -143,6 +154,7 @@ export const useFrontComponentExecutionContext = ({
|
||||
openRecordInSidePanelInternal({
|
||||
recordId,
|
||||
objectNameSingular,
|
||||
tab,
|
||||
resetNavigationStack,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user