Skip to content

The open alternative to Salesforce, designed for AI.

Restore purpose-built side panel page state (#25167)

Félix Malfaitcdd35a0ccc8a
diff --git a/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useWorkspaceSurfaceScopedComponentInstanceId.test.ts b/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useWorkspaceSurfaceScopedComponentInstanceId.test.ts
new file mode 100644
index 00000000000..af81f493d35
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/layout/hooks/__tests__/useWorkspaceSurfaceScopedComponentInstanceId.test.ts
@@ -0,0 +1,53 @@
+import { getWorkspaceSurfaceScopedComponentInstanceId } from '@/ui/layout/hooks/useWorkspaceSurfaceScopedComponentInstanceId';
+
+describe('getWorkspaceSurfaceScopedComponentInstanceId', () => {
+ it('keeps main-surface component IDs unchanged', () => {
+ expect(
+ getWorkspaceSurfaceScopedComponentInstanceId({
+ componentInstanceId: 'table',
+ surfaceType: 'main',
+ surfaceInstanceId: 'main',
+ }),
+ ).toBe('table');
+ });
+
+ it('scopes reusable component IDs once per side-panel instance', () => {
+ const args = {
+ surfaceType: 'side-panel' as const,
+ surfaceInstanceId: 'panel-1',
+ };
+
+ expect(
+ getWorkspaceSurfaceScopedComponentInstanceId({
+ ...args,
+ componentInstanceId: 'table',
+ }),
+ ).toBe('table-panel-1');
+ expect(
+ getWorkspaceSurfaceScopedComponentInstanceId({
+ ...args,
+ componentInstanceId: 'table-panel-1',
+ }),
+ ).toBe('table-panel-1');
+ });
+
+ it('preserves a component ID that is already the side-panel instance ID', () => {
+ expect(
+ getWorkspaceSurfaceScopedComponentInstanceId({
+ componentInstanceId: 'panel-1',
+ surfaceType: 'side-panel',
+ surfaceInstanceId: 'panel-1',
+ }),
+ ).toBe('panel-1');
+ });
+
+ it('preserves a missing component ID', () => {
+ expect(
+ getWorkspaceSurfaceScopedComponentInstanceId({
+ componentInstanceId: '',
+ surfaceType: 'side-panel',
+ surfaceInstanceId: 'panel-1',
+ }),
+ ).toBe('');
+ });
+});
diff --git a/packages/twenty-front/src/modules/ui/layout/hooks/useWorkspaceSurfaceScopedComponentInstanceId.ts b/packages/twenty-front/src/modules/ui/layout/hooks/useWorkspaceSurfaceScopedComponentInstanceId.ts
index 8a6b6bdaf31..1ff761188e6 100644
--- a/packages/twenty-front/src/modules/ui/layout/hooks/useWorkspaceSurfaceScopedComponentInstanceId.ts
+++ b/packages/twenty-front/src/modules/ui/layout/hooks/useWorkspaceSurfaceScopedComponentInstanceId.ts
@@ -1,4 +1,5 @@
import { useWorkspaceSurface } from '@/ui/layout/hooks/useWorkspaceSurface';
+import { isNonEmptyString } from '@sniptt/guards';
import { useCallback } from 'react';
export const getWorkspaceSurfaceScopedComponentInstanceId = ({
@@ -12,7 +13,9 @@ export const getWorkspaceSurfaceScopedComponentInstanceId = ({
}) => {
if (
surfaceType !== 'side-panel' ||
- surfaceInstanceId.length === 0 ||
+ !isNonEmptyString(surfaceInstanceId) ||
+ !isNonEmptyString(componentInstanceId) ||
+ componentInstanceId === surfaceInstanceId ||
componentInstanceId.endsWith(`-${surfaceInstanceId}`)
) {
return componentInstanceId;