The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Unify vertical list widget layout (#24445)
Thomas des Francsd7dcc20b0340
diff --git a/packages/twenty-apps/examples/document-generator/src/page-layouts/template-record.page-layout.ts b/packages/twenty-apps/examples/document-generator/src/page-layouts/template-record.page-layout.tsindex 3e49a2f8542..8b95286f8a6 100644--- a/packages/twenty-apps/examples/document-generator/src/page-layouts/template-record.page-layout.ts+++ b/packages/twenty-apps/examples/document-generator/src/page-layouts/template-record.page-layout.ts@@ -60,7 +60,7 @@ export default definePageLayout({title: 'Timeline',position: 100,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: TIMELINE_PAGE_LAYOUT_WIDGET_UNIVERSAL_IDENTIFIER,diff --git a/packages/twenty-apps/internal/real-estate/src/page-layouts/opportunity.page-layout.ts b/packages/twenty-apps/internal/real-estate/src/page-layouts/opportunity.page-layout.tsindex 7ac3661c8bb..e3a079bbf27 100644--- a/packages/twenty-apps/internal/real-estate/src/page-layouts/opportunity.page-layout.ts+++ b/packages/twenty-apps/internal/real-estate/src/page-layouts/opportunity.page-layout.ts@@ -40,7 +40,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: 'b0a3c0b2-600c-418e-8b3f-49f8588bdcbd',diff --git a/packages/twenty-apps/internal/real-estate/src/page-layouts/showing.page-layout.ts b/packages/twenty-apps/internal/real-estate/src/page-layouts/showing.page-layout.tsindex d51b481aebc..65fac87f565 100644--- a/packages/twenty-apps/internal/real-estate/src/page-layouts/showing.page-layout.ts+++ b/packages/twenty-apps/internal/real-estate/src/page-layouts/showing.page-layout.ts@@ -1,7 +1,4 @@-import {- definePageLayout,- PageLayoutTabLayoutMode,-} from 'twenty-sdk/define';+import { definePageLayout, PageLayoutTabLayoutMode } from 'twenty-sdk/define';import { SHOWING_UNIVERSAL_IDENTIFIER } from '../objects/showing.object';import { SHOWING_RECORD_PAGE_FIELDS_VIEW_ID } from '../views/showing-record-page-fields.view';@@ -34,7 +31,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '75a5ebcf-0962-4eb5-810a-49a9da3b4e39',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/application/page-layouts/application.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/application/page-layouts/application.page-layout.tsindex e859c6befa4..d8613789e0d 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/application/page-layouts/application.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/application/page-layouts/application.page-layout.ts@@ -35,7 +35,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '3e9acb85-9445-40d5-9c65-57461df8483c',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/opportunity/page-layouts/opportunity.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/opportunity/page-layouts/opportunity.page-layout.tsindex bee7533d5fd..7ef9ba82403 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/opportunity/page-layouts/opportunity.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/opportunity/page-layouts/opportunity.page-layout.ts@@ -41,7 +41,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '98c9aac6-5a93-4725-84c7-15c5db445ea3',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-content.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-content.page-layout.tsindex 942354301eb..1cca7daa0e3 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-content.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-content.page-layout.ts@@ -32,7 +32,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '1d293bf5-f6d4-41c4-a6f6-db7955759f35',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-link.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-link.page-layout.tsindex 79c2bdc3ef9..3b7c9face66 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-link.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-link.page-layout.ts@@ -32,7 +32,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: 'b4f89755-01da-457a-b2a2-63deeba89dc2',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-service.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-service.page-layout.tsindex 6542f26ef10..a4bc2cb8933 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-service.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner-service.page-layout.ts@@ -32,7 +32,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '87ad1f2b-63f0-4f15-a098-e4bc911feb58',diff --git a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner.page-layout.ts b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner.page-layout.tsindex 27b94f5dbbd..e2b3eddb04a 100644--- a/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner.page-layout.ts+++ b/packages/twenty-apps/internal/twenty-partners/src/modules/partner/directory/page-layouts/partner.page-layout.ts@@ -35,7 +35,7 @@ export default definePageLayout({title: 'Timeline',position: 20,icon: 'IconTimelineEvent',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '38372f08-6b5b-4e87-aa0d-d515d72f5a5d',@@ -50,7 +50,7 @@ export default definePageLayout({title: 'Notes',position: 30,icon: 'IconNotes',- layoutMode: PageLayoutTabLayoutMode.CANVAS,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,widgets: [{universalIdentifier: '53e31a77-642e-49d4-824d-a5cad81b83a5',diff --git a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdxindex de2aa60cea2..8b8c863d7fa 100644--- a/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx+++ b/packages/twenty-docs/developers/extend/apps/layout/page-layouts.mdx@@ -53,7 +53,7 @@ export default definePageLayout({- `type` is one of `'RECORD_INDEX'`, `'RECORD_PAGE'`, `'DASHBOARD'` or `'STANDALONE_PAGE'`. Use `'RECORD_PAGE'` to customize the detail view of a specific object.- `objectUniversalIdentifier` specifies which object this layout applies to.-- Each `tab` defines a section of the page with a `title`, `position`, and `layoutMode`: `VERTICAL_LIST` for record pages and standalone pages, `GRID` for dashboards. In a `VERTICAL_LIST` tab, a single widget renders full-bleed and owns the whole tab; with several widgets they stack as cards. A `GRID` tab always lays its widgets out as cards on a 12-column grid, whatever their number, so pick `VERTICAL_LIST` when you want one widget to fill the page.+- Each `tab` defines a section of the page with a `title`, `position`, and `layoutMode`: `VERTICAL_LIST` for record pages and standalone pages, `GRID` for dashboards, and `CANVAS` for a single widget that should fill the tab viewport. A `VERTICAL_LIST` tab stacks widgets vertically. Built-in widgets that manage their own scrolling, such as timelines, files, notes, tasks, and workflows, fill one viewport; fields, front components, graphs, and other fit-content widgets render at their content or configured height. A `GRID` tab always lays its widgets out as cards on a 12-column grid. A `CANVAS` widget has no explicit position; if a canvas tab contains multiple widgets, they render at their content height instead of filling the viewport.- Set `layoutMode` explicitly. Omitting it gives you `VERTICAL_LIST` on a `STANDALONE_PAGE` and `GRID` everywhere else, which is rarely what you want on a record page.- Each `widget` inside a tab can render a [front component](/developers/extend/apps/layout/front-components), a relation list, or other built-in widget types.- A `FRONT_COMPONENT` widget can set `headerCommandMenuItemUniversalIdentifiers` to an ordered array of command menu item universal identifiers from the same app. These actions appear as icon buttons in the widget card header and keep their command-level availability and permission checks. Identifiers must be unique and must resolve when the app is installed.diff --git a/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useCancelLayoutCustomization.test.tsx b/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useCancelLayoutCustomization.test.tsxnew file mode 100644index 00000000000..0b238a7f7eb--- /dev/null+++ b/packages/twenty-front/src/modules/layout-customization/hooks/__tests__/useCancelLayoutCustomization.test.tsx@@ -0,0 +1,90 @@+import { useCancelLayoutCustomization } from '@/layout-customization/hooks/useCancelLayoutCustomization';+import { activeCustomizationPageLayoutIdsState } from '@/layout-customization/states/activeCustomizationPageLayoutIdsState';+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { pageLayoutPersistedComponentState } from '@/page-layout/states/pageLayoutPersistedComponentState';+import {+ makeTab,+ makeWidget,+} from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayout } from '@/page-layout/types/PageLayout';+import { act, renderHook } from '@testing-library/react';+import { createStore, Provider as JotaiProvider } from 'jotai';+import { type ReactNode } from 'react';+import { PageLayoutType, WidgetType } from '~/generated-metadata/graphql';++const mockExitLayoutCustomizationMode = jest.fn();++jest.mock(+ '@/layout-customization/hooks/useExitLayoutCustomizationMode',+ () => ({+ useExitLayoutCustomizationMode: () => ({+ exitLayoutCustomizationMode: mockExitLayoutCustomizationMode,+ }),+ }),+);++const PAGE_LAYOUT_ID = 'page-layout-id';++const getWrapper =+ (store = createStore()) =>+ ({ children }: { children: ReactNode }) => (+ <JotaiProvider store={store}>{children}</JotaiProvider>+ );++describe('useCancelLayoutCustomization', () => {+ beforeEach(() => {+ jest.clearAllMocks();+ });++ it('restores the persisted order in the draft', () => {+ const store = createStore();+ const timelineWidget = {+ ...makeWidget('timeline', 0),+ type: WidgetType.TIMELINE,+ };+ const fieldsWidget = makeWidget('fields', 1);+ const persistedPageLayout = {+ id: PAGE_LAYOUT_ID,+ name: 'Record Page',+ type: PageLayoutType.RECORD_PAGE,+ objectMetadataId: 'object-metadata-id',+ tabs: [makeTab('vertical-list-tab', [timelineWidget, fieldsWidget])],+ } as PageLayout;++ store.set(activeCustomizationPageLayoutIdsState.atom, [PAGE_LAYOUT_ID]);+ store.set(+ pageLayoutPersistedComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ persistedPageLayout,+ );++ const { result } = renderHook(() => useCancelLayoutCustomization(), {+ wrapper: getWrapper(store),+ });++ act(() => {+ result.current.cancel();+ });++ expect(+ store+ .get(+ pageLayoutPersistedComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ )+ ?.tabs[0].widgets.map((widget) => widget.id),+ ).toEqual(['timeline', 'fields']);+ expect(+ store+ .get(+ pageLayoutDraftComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ )+ .tabs[0].widgets.map((widget) => widget.id),+ ).toEqual(['timeline', 'fields']);+ expect(mockExitLayoutCustomizationMode).toHaveBeenCalledTimes(1);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutContent.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutContent.tsxindex 87e49fab6ea..991405a5df4 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutContent.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutContent.tsx@@ -1,7 +1,5 @@import { PageLayoutGridLayout } from '@/page-layout/components/PageLayoutGridLayout';-import { PageLayoutSoloViewer } from '@/page-layout/components/PageLayoutSoloViewer';-import { PageLayoutVerticalListEditor } from '@/page-layout/components/PageLayoutVerticalListEditor';-import { PageLayoutVerticalListViewer } from '@/page-layout/components/PageLayoutVerticalListViewer';+import { PageLayoutVerticalList } from '@/page-layout/components/PageLayoutVerticalList';import { usePageLayoutContentContext } from '@/page-layout/contexts/PageLayoutContentContext';import { useCurrentPageLayoutOrThrow } from '@/page-layout/hooks/useCurrentPageLayoutOrThrow';import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInEditMode';@@ -22,12 +20,10 @@ const StyledEmptyStandalonePageContainer = styled.div`export const PageLayoutContent = () => {const isPageLayoutInEditMode = useIsPageLayoutInEditMode();- const { tabId } = usePageLayoutContentContext();+ const { layoutMode, tabId } = usePageLayoutContentContext();const activeTab = usePageLayoutTabWithVisibleWidgetsOrThrow(tabId);- const { layoutMode, presentation } = usePageLayoutContentContext();-const { currentPageLayout } = useCurrentPageLayoutOrThrow();const isRecordPageLayout =@@ -51,20 +47,15 @@ export const PageLayoutContent = () => {return <PageLayoutGridLayout tabId={tabId} />;}- // Edit mode always shows the stack structure, whatever the view-mode- // presentation is: every tab is edited through the same vertical-list editor.- if (isPageLayoutInEditMode && isRecordPageLayout) {- return (- <PageLayoutVerticalListEditor- widgets={activeTab.widgets}- trailingElement={<RecordPageAddWidgetSection />}- />- );- }-- if (presentation === 'solo') {- return <PageLayoutSoloViewer widgets={activeTab.widgets} />;- }-- return <PageLayoutVerticalListViewer widgets={activeTab.widgets} />;+ const isVerticalListInEditMode = isPageLayoutInEditMode && isRecordPageLayout;++ return (+ <PageLayoutVerticalList+ isInEditMode={isVerticalListInEditMode}+ widgets={activeTab.widgets}+ trailingElement={+ isVerticalListInEditMode ? <RecordPageAddWidgetSection /> : undefined+ }+ />+ );};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutLeftPanel.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutLeftPanel.tsxindex 7902c3b2d83..a4b8704cccb 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutLeftPanel.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutLeftPanel.tsx@@ -1,8 +1,10 @@import { SummaryCard } from '@/object-record/record-show/components/SummaryCard';import { PageLayoutContent } from '@/page-layout/components/PageLayoutContent';+import { PageLayoutScrollResetEffect } from '@/page-layout/components/PageLayoutScrollResetEffect';import { PageLayoutContentProvider } from '@/page-layout/contexts/PageLayoutContentContext';import { useCurrentPageLayout } from '@/page-layout/hooks/useCurrentPageLayout';import { usePageLayoutTabWithVisibleWidgetsOrThrow } from '@/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow';+import { getScrollWrapperInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord';import { getTabLayoutMode } from '@/page-layout/utils/getTabLayoutMode';import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';import { useTargetRecord } from '@/ui/layout/contexts/useTargetRecord';@@ -12,7 +14,9 @@ import { PageLayoutType } from '~/generated-metadata/graphql';import { themeCssVariables } from 'twenty-ui/theme-constants';const StyledContainer = styled.div`- background: ${themeCssVariables.background.secondary};+ --record-card-background-color: ${themeCssVariables.background.secondary};++ background: var(--record-card-background-color);border-bottom-left-radius: 8px;border-right: 1px solid ${themeCssVariables.border.color.medium};border-top-left-radius: 8px;@@ -21,20 +25,36 @@ const StyledContainer = styled.div`grid-template-columns: minmax(0, 1fr);grid-template-rows: auto 1fr;height: 100%;++ .page-layout-scroll-wrapper {+ container-name: tab-viewport;+ container-type: size;+ }`;type PageLayoutLeftPanelProps = {+ pageLayoutId: string;pinnedLeftTabId: string;};export const PageLayoutLeftPanel = ({+ pageLayoutId,pinnedLeftTabId,}: PageLayoutLeftPanelProps) => {const { currentPageLayout } = useCurrentPageLayout();const targetRecordIdentifier = useTargetRecord();- const { isInSidePanel } = useLayoutRenderingContext();+ const { isInSidePanel, layoutType } = useLayoutRenderingContext();const pinnedTab = usePageLayoutTabWithVisibleWidgetsOrThrow(pinnedLeftTabId);+ const scrollWrapperInstanceId =+ getScrollWrapperInstanceIdFromPageLayoutAndRecord({+ pageLayoutId,+ layoutType,+ targetRecordIdentifier,+ isInSidePanel,+ scrollWrapperArea: 'left-panel',+ pageLayoutTabId: pinnedLeftTabId,+ });if (currentPageLayout?.type !== PageLayoutType.RECORD_PAGE) {return null;}@@ -46,14 +66,17 @@ export const PageLayoutLeftPanel = ({return (<StyledContainer>+ <PageLayoutScrollResetEffect+ pageLayoutTabId={pinnedLeftTabId}+ scrollWrapperInstanceId={scrollWrapperInstanceId}+ targetRecordId={targetRecordIdentifier.id}+ /><SummaryCardobjectNameSingular={targetRecordIdentifier.targetObjectNameSingular}objectRecordId={targetRecordIdentifier.id}isInSidePanel={isInSidePanel}/>- {/* The pinned left panel is always a column of cards, even with a single- widget: solo presentation is a main-tab-area concept. */}<PageLayoutContentProvidervalue={{tabId: pinnedLeftTabId,@@ -62,7 +85,8 @@ export const PageLayoutLeftPanel = ({}}><ScrollWrapper- componentInstanceId={`page-layout-left-panel-${pinnedLeftTabId}`}+ className="page-layout-scroll-wrapper"+ componentInstanceId={scrollWrapperInstanceId}defaultEnableXScroll={false}defaultEnableYScroll={true}>diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutRecordPageCustomizationSessionRegistrationEffect.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutRecordPageCustomizationSessionRegistrationEffect.tsxindex b3b650764c0..291009c7067 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutRecordPageCustomizationSessionRegistrationEffect.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutRecordPageCustomizationSessionRegistrationEffect.tsx@@ -1,6 +1,10 @@import { activeCustomizationPageLayoutIdsState } from '@/layout-customization/states/activeCustomizationPageLayoutIdsState';import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInEditMode';+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';import { pageLayoutPersistedComponentState } from '@/page-layout/states/pageLayoutPersistedComponentState';+import { normalizeVerticalListWidgetsInDraftPageLayout } from '@/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout';+import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomStateValue';import { useStore } from 'jotai';@@ -14,9 +18,13 @@ export const PageLayoutRecordPageCustomizationSessionRegistrationEffect =const isLayoutCustomizationModeEnabled = useAtomStateValue(isLayoutCustomizationModeEnabledState,);+ const isPageLayoutInEditMode = useIsPageLayoutInEditMode();const pageLayoutPersisted = useAtomComponentStateValue(pageLayoutPersistedComponentState,);+ const pageLayoutDraftState = useAtomComponentStateCallbackState(+ pageLayoutDraftComponentState,+ );useEffect(() => {if (!isLayoutCustomizationModeEnabled) {@@ -31,12 +39,25 @@ export const PageLayoutRecordPageCustomizationSessionRegistrationEffect =return;}+ if (isPageLayoutInEditMode) {+ store.set(+ pageLayoutDraftState,+ normalizeVerticalListWidgetsInDraftPageLayout,+ );+ }+store.set(activeCustomizationPageLayoutIdsState.atom, (activeIds) =>activeIds.includes(pageLayoutPersisted.id)? activeIds: [...activeIds, pageLayoutPersisted.id],);- }, [isLayoutCustomizationModeEnabled, pageLayoutPersisted, store]);+ }, [+ isLayoutCustomizationModeEnabled,+ isPageLayoutInEditMode,+ pageLayoutDraftState,+ pageLayoutPersisted,+ store,+ ]);return null;};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutScrollResetEffect.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutScrollResetEffect.tsxnew file mode 100644index 00000000000..74eb880e7b1--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutScrollResetEffect.tsx@@ -0,0 +1,29 @@+import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';+import { useEffect } from 'react';+import { isDefined } from 'twenty-shared/utils';++type PageLayoutScrollResetEffectProps = {+ pageLayoutTabId?: string | null;+ scrollWrapperInstanceId: string;+ targetRecordId?: string | null;+};++export const PageLayoutScrollResetEffect = ({+ pageLayoutTabId,+ scrollWrapperInstanceId,+ targetRecordId,+}: PageLayoutScrollResetEffectProps) => {+ const { getScrollWrapperElement } = useScrollWrapperHTMLElement(+ scrollWrapperInstanceId,+ );++ useEffect(() => {+ const { scrollWrapperElement } = getScrollWrapperElement();++ if (isDefined(scrollWrapperElement)) {+ scrollWrapperElement.scrollTop = 0;+ }+ }, [getScrollWrapperElement, pageLayoutTabId, targetRecordId]);++ return null;+};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutSoloViewer.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutSoloViewer.tsxdeleted file mode 100644index 084efd4e577..00000000000--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutSoloViewer.tsx+++ /dev/null@@ -1,29 +0,0 @@-import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';-import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';-import { styled } from '@linaria/react';-import { isDefined } from 'twenty-shared/utils';--const StyledSoloContainer = styled.div`- display: grid;- height: 100%;-`;--type PageLayoutSoloViewerProps = {- widgets: PageLayoutWidget[];-};--export const PageLayoutSoloViewer = ({- widgets,-}: PageLayoutSoloViewerProps) => {- const widget = widgets.at(0);-- if (!isDefined(widget)) {- return null;- }-- return (- <StyledSoloContainer>- <WidgetRenderer widget={widget} />- </StyledSoloContainer>- );-};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsxindex b89e47ef481..315b35e9173 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabList.tsx@@ -32,6 +32,7 @@ import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contextimport { pageLayoutTabSettingsOpenTabIdComponentState } from '@/page-layout/states/pageLayoutTabSettingsOpenTabIdComponentState';import { type PageLayoutAddTabStrategy } from '@/page-layout/types/PageLayoutAddTabStrategy';import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { type PageLayoutWidgetDndData } from '@/page-layout/types/PageLayoutWidgetDndData';import { shouldEnableTabEditingFeatures } from '@/page-layout/utils/shouldEnableTabEditingFeatures';import { useNavigatePageLayoutSidePanel } from '@/side-panel/pages/page-layout/hooks/useNavigatePageLayoutSidePanel';@@ -347,19 +348,19 @@ export const PageLayoutTabList = ({// Record pages accept widget drops on vertical-list tabs (dnd-kit drags);// dashboards accept them on grid tabs (react-grid-layout drags bridged by// pointer hit-testing).- const widgetDropTargetTabIds = new Set(+ const widgetDropTargetWidgetsByTabId = new Map<string, PageLayoutWidget[]>(pageLayoutType === PageLayoutType.RECORD_PAGE? tabs.filter((tab) => tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST,)- .map((tab) => tab.id)+ .map((tab) => [tab.id, tab.widgets] as const): pageLayoutType === PageLayoutType.DASHBOARD? tabs.filter((tab) => tab.layoutMode !== PageLayoutTabLayoutMode.VERTICAL_LIST,)- .map((tab) => tab.id)+ .map((tab) => [tab.id, tab.widgets] as const): [],);@@ -411,7 +412,7 @@ export const PageLayoutTabList = ({onChangeTab={onChangeTab}onSelectTab={handleSelectTab}canReorder={canReorderTabs}- widgetDropTargetTabIds={widgetDropTargetTabIds}+ widgetDropTargetWidgetsByTabId={widgetDropTargetWidgetsByTabId}firstHiddenTabId={hasHiddenTabs ? (hiddenTabs[0]?.id ?? null) : null}diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListReorderableTab.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListReorderableTab.tsxindex 00e0b37f46d..cfec9abb92f 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListReorderableTab.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListReorderableTab.tsx@@ -2,10 +2,12 @@ import { PageLayoutTabWidgetDropTarget } from '@/page-layout/components/dnd/Pageimport { PAGE_LAYOUT_TAB_DND_TYPE } from '@/page-layout/constants/PageLayoutTabDndType';import { pageLayoutTabSettingsOpenTabIdComponentState } from '@/page-layout/states/pageLayoutTabSettingsOpenTabIdComponentState';import { type PageLayoutTabDragData } from '@/page-layout/types/PageLayoutTabDragData';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';import { DragDropItemSortableCell } from '@/ui/utilities/drag-and-drop/components/DragDropItemSortableCell';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';import { styled } from '@linaria/react';+import { isDefined } from 'twenty-shared/utils';import { StyledTabContainer, TabContent } from 'twenty-ui/input';import { themeCssVariables } from 'twenty-ui/theme-constants';@@ -16,7 +18,7 @@ type PageLayoutTabListReorderableTabProps = {nextTabId: string | null;isActive: boolean;disabled?: boolean;- isWidgetDropTarget?: boolean;+ widgetDropTargetWidgets?: PageLayoutWidget[];onSelect: () => void;};@@ -34,7 +36,7 @@ export const PageLayoutTabListReorderableTab = ({nextTabId,isActive,disabled,- isWidgetDropTarget = false,+ widgetDropTargetWidgets,onSelect,}: PageLayoutTabListReorderableTabProps) => {const pageLayoutTabSettingsOpenTabId = useAtomComponentStateValue(@@ -82,12 +84,15 @@ export const PageLayoutTabListReorderableTab = ({</DragDropItemSortableCell>);- if (!isWidgetDropTarget) {+ if (!isDefined(widgetDropTargetWidgets)) {return draggableTab;}return (- <PageLayoutTabWidgetDropTarget tabId={tab.id}>+ <PageLayoutTabWidgetDropTarget+ tabId={tab.id}+ destinationWidgets={widgetDropTargetWidgets}+ >{draggableTab}</PageLayoutTabWidgetDropTarget>);diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsxindex 02dc8725928..be908246148 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabListVisibleTabs.tsx@@ -8,6 +8,7 @@ import { type SingleTabProps } from '@/ui/layout/tab-list/types/SingleTabProps';import { PAGE_LAYOUT_TAB_LIST_DROPPABLE_IDS } from '@/page-layout/components/PageLayoutTabListDroppableIds';import { PageLayoutTabListReorderableTab } from '@/page-layout/components/PageLayoutTabListReorderableTab';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { DragDropItemDropTarget } from '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget';type PageLayoutTabListVisibleTabsProps = {@@ -19,7 +20,7 @@ type PageLayoutTabListVisibleTabsProps = {onChangeTab?: (tabId: string) => void;onSelectTab: (tabId: string) => void;canReorder: boolean;- widgetDropTargetTabIds: Set<string>;+ widgetDropTargetWidgetsByTabId: Map<string, PageLayoutWidget[]>;firstHiddenTabId: string | null;isScrollable: boolean;};@@ -55,7 +56,7 @@ export const PageLayoutTabListVisibleTabs = ({onChangeTab,onSelectTab,canReorder,- widgetDropTargetTabIds,+ widgetDropTargetWidgetsByTabId,firstHiddenTabId,isScrollable,}: PageLayoutTabListVisibleTabsProps) => {@@ -86,7 +87,9 @@ export const PageLayoutTabListVisibleTabs = ({nextTabId={shownTabs[index + 1]?.id ?? firstHiddenTabId}isActive={tab.id === activeTabId}disabled={tab.disabled ?? loading}- isWidgetDropTarget={widgetDropTargetTabIds.has(tab.id)}+ widgetDropTargetWidgets={widgetDropTargetWidgetsByTabId.get(+ tab.id,+ )}onSelect={() => onSelectTab(tab.id)}/></StyledTabSlot>diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsxindex 08df17dad3b..3c5de103042 100644--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutTabsRenderer.tsx@@ -1,5 +1,6 @@import { PageLayoutWidgetDndProvider } from '@/page-layout/components/dnd/PageLayoutWidgetDndProvider';import { PageLayoutLeftPanel } from '@/page-layout/components/PageLayoutLeftPanel';+import { PageLayoutScrollResetEffect } from '@/page-layout/components/PageLayoutScrollResetEffect';import { PageLayoutTabList } from '@/page-layout/components/PageLayoutTabList';import { PageLayoutTabListEffect } from '@/page-layout/components/PageLayoutTabListEffect';import { PAGE_LAYOUT_LEFT_PANEL_CONTAINER_WIDTH } from '@/page-layout/constants/PageLayoutLeftPanelContainerWidth';@@ -8,7 +9,7 @@ import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInimport { usePageLayoutAddTabStrategy } from '@/page-layout/hooks/usePageLayoutAddTabStrategy';import { usePageLayoutRenderableTabs } from '@/page-layout/hooks/usePageLayoutRenderableTabs';import { PageLayoutMainContent } from '@/page-layout/PageLayoutMainContent';-import { getScrollWrapperInstanceIdFromPageLayoutId } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutId';+import { getScrollWrapperInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord';import { getTabListInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getTabListInstanceIdFromPageLayoutAndRecord';import { shouldEnableTabEditingFeatures } from '@/page-layout/utils/shouldEnableTabEditingFeatures';import { sortTabsByPosition } from '@/page-layout/utils/sortTabsByPosition';@@ -32,6 +33,23 @@ const StyledContainer = styled.div<{ hasPinnedTab: boolean }>`display: block;height: auto;width: 100%;++ .page-layout-scroll-wrapper {+ container-name: none !important;+ container-type: normal !important;+ }++ .page-layout-viewport-filling-widget-slot {+ --widget-height: auto !important;++ height: auto !important;+ min-height: 0 !important;+ overflow: visible !important;++ .widget-card-header {+ position: static !important;+ }+ }}`;@@ -54,6 +72,11 @@ const StyledScrollWrapperContainer = styled.div`flex: 1;min-height: 0;+ .page-layout-scroll-wrapper {+ container-name: tab-viewport;+ container-type: size;+ }+// The mobile navigation bar floats over the page, so the content reserves its// footprint to stay readable once scrolled to the end.@media (max-width: ${MOBILE_VIEWPORT}px) {@@ -83,6 +106,15 @@ export const PageLayoutTabsRenderer = () => {const activeTabId = useAtomComponentStateValue(activeTabIdComponentState);+ const scrollWrapperInstanceId =+ getScrollWrapperInstanceIdFromPageLayoutAndRecord({+ pageLayoutId: currentPageLayout.id,+ layoutType,+ targetRecordIdentifier,+ isInSidePanel,+ scrollWrapperArea: 'tab-content',+ });+const tabListInstanceId = getTabListInstanceIdFromPageLayoutAndRecord({pageLayoutId: currentPageLayout.id,layoutType,@@ -109,9 +141,17 @@ export const PageLayoutTabsRenderer = () => {return (<PageLayoutWidgetDndProvider>+ <PageLayoutScrollResetEffect+ pageLayoutTabId={activeTabId}+ scrollWrapperInstanceId={scrollWrapperInstanceId}+ targetRecordId={targetRecordIdentifier?.id}+ /><StyledContainer hasPinnedTab={isDefined(pinnedLeftTab)}>{isDefined(pinnedLeftTab) && (- <PageLayoutLeftPanel pinnedLeftTabId={pinnedLeftTab.id} />+ <PageLayoutLeftPanel+ pageLayoutId={currentPageLayout.id}+ pinnedLeftTabId={pinnedLeftTab.id}+ />)}<StyledTabsAndDashboardContainer>@@ -139,9 +179,7 @@ export const PageLayoutTabsRenderer = () => {<StyledScrollWrapperContainer><ScrollWrapperclassName="page-layout-scroll-wrapper"- componentInstanceId={getScrollWrapperInstanceIdFromPageLayoutId(- currentPageLayout.id,- )}+ componentInstanceId={scrollWrapperInstanceId}defaultEnableXScroll={false}>{isDefined(activeTabId) && activeTabExistsInRenderableTabs && (diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalList.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalList.tsxnew file mode 100644index 00000000000..4f5c17f0d2f--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalList.tsx@@ -0,0 +1,152 @@+import { PageLayoutVerticalListWidgetSlot } from '@/page-layout/components/PageLayoutVerticalListWidgetSlot';+import { usePageLayoutContentContext } from '@/page-layout/contexts/PageLayoutContentContext';+import { useIsSideColumnContext } from '@/page-layout/hooks/useIsSideColumnContext';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { type PageLayoutWidgetListDropData } from '@/page-layout/types/PageLayoutWidgetListDropData';+import { canVerticalListAcceptWidgetDrag } from '@/page-layout/utils/canVerticalListAcceptWidgetDrag';+import { getIsSingleWidgetTab } from '@/page-layout/utils/getIsSingleWidgetTab';+import { DragDropItemDropTarget } from '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget';+import { WorkflowDiagramAllowPageScrollContext } from '@/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext';+import { type Draggable } from '@dnd-kit/abstract';+import { pointerIntersection } from '@dnd-kit/collision';+import { useDroppable } from '@dnd-kit/react';+import { styled } from '@linaria/react';+import { type ReactNode, useCallback } from 'react';+import { themeCssVariables } from 'twenty-ui/theme-constants';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';++const StyledVerticalListContainer = styled.div<{+ isInEditMode: boolean;+ isSideColumnContext: boolean;+ shouldUseWhiteBackground: boolean;+}>`+ --record-card-background-color: ${({ shouldUseWhiteBackground }) =>+ shouldUseWhiteBackground+ ? themeCssVariables.background.primary+ : themeCssVariables.background.secondary};+ --viewport-filling-widget-editor-block-inset: ${({+ isInEditMode,+ isSideColumnContext,+ }) =>+ isInEditMode+ ? isSideColumnContext+ ? themeCssVariables.spacing[2]+ : themeCssVariables.spacing[4]+ : '0px'};+ --widget-card-content-overflow: visible;+ --widget-height: auto;+ --widget-scroll-overflow: visible;++ background: var(--record-card-background-color);+ display: flex;+ flex-direction: column;+ gap: ${({ isInEditMode }) =>+ isInEditMode ? themeCssVariables.spacing[4] : '0'};+ min-height: ${({ isInEditMode }) => (isInEditMode ? '0' : '100%')};+ padding: ${({ isInEditMode, isSideColumnContext }) =>+ isInEditMode+ ? isSideColumnContext+ ? themeCssVariables.spacing[1]+ : themeCssVariables.spacing[2]+ : '0'};+`;++const StyledDropTarget = styled.div`+ display: flex;+ flex: 1;+ flex-direction: column;+ gap: ${themeCssVariables.spacing[4]};+ min-height: ${themeCssVariables.spacing[6]};+ position: relative;+`;++type PageLayoutVerticalListProps = {+ isInEditMode: boolean;+ widgets: PageLayoutWidget[];+ trailingElement?: ReactNode;+};++export const PageLayoutVerticalList = ({+ isInEditMode,+ widgets,+ trailingElement,+}: PageLayoutVerticalListProps) => {+ const { layoutMode, tabId } = usePageLayoutContentContext();++ const { isInPinnedTab, isMobile, isSideColumnContext } =+ useIsSideColumnContext();++ const shouldUseSoloCanvasPresentation =+ layoutMode === PageLayoutTabLayoutMode.CANVAS &&+ getIsSingleWidgetTab({+ tab: {+ layoutMode,+ widgets,+ },+ }) &&+ !isInEditMode &&+ !isInPinnedTab;++ // A viewport-filling slot is exactly one viewport tall, so the list only+ // overflows when something else shares it. Widgets that capture the wheel+ // (workflow canvases) must keep it when there is no page scroll to reach.+ const hasPageScroll = isInEditMode || widgets.length > 1;++ const endDropData: PageLayoutWidgetListDropData = {+ type: 'widget-list',+ tabId,+ itemCount: widgets.length,+ };++ const canAcceptWidgetDrag = useCallback(+ (source: Draggable) =>+ canVerticalListAcceptWidgetDrag({+ destinationWidgets: widgets,+ source,+ }),+ [widgets],+ );++ const { ref: endDropZoneRef } = useDroppable({+ id: `page-layout-widget-list-${tabId}`,+ accept: canAcceptWidgetDrag,+ collisionDetector: pointerIntersection,+ data: endDropData,+ disabled: !isInEditMode,+ });++ return (+ <StyledVerticalListContainer+ isInEditMode={isInEditMode}+ isSideColumnContext={isSideColumnContext}+ shouldUseWhiteBackground={!isInPinnedTab || isMobile}+ >+ <WorkflowDiagramAllowPageScrollContext.Provider value={hasPageScroll}>+ {widgets.map((widget, index) => (+ <PageLayoutVerticalListWidgetSlot+ canAcceptWidgetDrag={canAcceptWidgetDrag}+ index={index}+ isInEditMode={isInEditMode}+ isSoloCanvasPresentation={shouldUseSoloCanvasPresentation}+ key={widget.id}+ layoutMode={layoutMode}+ shouldShowDivider={isSideColumnContext}+ tabId={tabId}+ widget={widget}+ />+ ))}+ {isInEditMode && (+ <StyledDropTarget ref={endDropZoneRef}>+ <DragDropItemDropTarget+ index={widgets.length}+ droppableId={tabId}+ orientation="horizontal"+ compact+ />+ {trailingElement}+ </StyledDropTarget>+ )}+ </WorkflowDiagramAllowPageScrollContext.Provider>+ </StyledVerticalListContainer>+ );+};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsxdeleted file mode 100644index 06b299240ee..00000000000--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListEditor.tsx+++ /dev/null@@ -1,137 +0,0 @@-import { getPageLayoutVerticalListViewerVariant } from '@/page-layout/components/utils/getPageLayoutVerticalListViewerVariant';-import { usePageLayoutContentContext } from '@/page-layout/contexts/PageLayoutContentContext';-import { type PageLayoutVerticalListViewerVariant } from '@/page-layout/types/PageLayoutVerticalListViewerVariant';-import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';-import { type PageLayoutWidgetDragData } from '@/page-layout/types/PageLayoutWidgetDragData';-import { type PageLayoutWidgetListDropData } from '@/page-layout/types/PageLayoutWidgetListDropData';-import { PAGE_LAYOUT_WIDGET_DND_TYPE } from '@/page-layout/constants/PageLayoutWidgetDndType';-import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';-import { useIsInPinnedTab } from '@/page-layout/widgets/hooks/useIsInPinnedTab';-import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';-import { DragDropItemDropTarget } from '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget';-import { DragDropItemSortableCell } from '@/ui/utilities/drag-and-drop/components/DragDropItemSortableCell';-import { pointerIntersection } from '@dnd-kit/collision';-import { useDroppable } from '@dnd-kit/react';-import { styled } from '@linaria/react';-import { type ReactNode } from 'react';-import { themeCssVariables } from 'twenty-ui/theme-constants';-import { useIsMobile } from 'twenty-ui/utilities';--const StyledVerticalListContainer = styled.div<{- variant: PageLayoutVerticalListViewerVariant;- shouldUseWhiteBackground: boolean;-}>`- --widget-card-content-overflow: visible;- --widget-height: auto;- --widget-scroll-overflow: visible;-- background: ${({ shouldUseWhiteBackground }) =>- shouldUseWhiteBackground- ? themeCssVariables.background.primary- : themeCssVariables.background.secondary};- display: flex;- flex-direction: column;- gap: ${themeCssVariables.spacing[4]};- padding: ${({ variant }) =>- variant === 'side-column'- ? themeCssVariables.spacing[1]- : themeCssVariables.spacing[2]};-`;--const StyledDropTarget = styled.div`- display: flex;- flex: 1;- flex-direction: column;- gap: ${themeCssVariables.spacing[4]};- min-height: ${themeCssVariables.spacing[6]};- position: relative;-`;--const StyledWidgetSlot = styled.div`- display: flex;- flex-direction: column;-`;--type PageLayoutVerticalListEditorProps = {- widgets: PageLayoutWidget[];- trailingElement?: ReactNode;-};--export const PageLayoutVerticalListEditor = ({- widgets,- trailingElement,-}: PageLayoutVerticalListEditorProps) => {- const { tabId } = usePageLayoutContentContext();-- const { isInSidePanel } = useLayoutRenderingContext();- const isMobile = useIsMobile();- const { isInPinnedTab } = useIsInPinnedTab();-- const variant = getPageLayoutVerticalListViewerVariant({- isInPinnedTab,- isMobile,- isInSidePanel,- });-- const endDropData: PageLayoutWidgetListDropData = {- type: 'widget-list',- tabId,- itemCount: widgets.length,- };-- const { ref: endDropZoneRef } = useDroppable({- id: `page-layout-widget-list-${tabId}`,- accept: PAGE_LAYOUT_WIDGET_DND_TYPE,- collisionDetector: pointerIntersection,- data: endDropData,- });-- return (- <StyledVerticalListContainer- variant={variant}- shouldUseWhiteBackground={!isInPinnedTab || isMobile}- >- {widgets.map((widget, index) => {- const widgetDragData: PageLayoutWidgetDragData = {- type: 'widget',- widgetId: widget.id,- tabId,- index,- };-- return (- <StyledWidgetSlot key={widget.id}>- <DragDropItemDropTarget- index={index}- droppableId={tabId}- orientation="horizontal"- compact- />- <DragDropItemSortableCell- id={widget.id}- index={index}- group={tabId}- data={widgetDragData}- type={PAGE_LAYOUT_WIDGET_DND_TYPE}- accept={PAGE_LAYOUT_WIDGET_DND_TYPE}- hasTransition={false}- highlightWhileDragging={true}- orientation="horizontal"- >- <WidgetRenderer widget={widget} />- </DragDropItemSortableCell>- </StyledWidgetSlot>- );- })}- <StyledDropTarget ref={endDropZoneRef}>- <DragDropItemDropTarget- index={widgets.length}- droppableId={tabId}- orientation="horizontal"- compact- />- {trailingElement}- </StyledDropTarget>- </StyledVerticalListContainer>- );-};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsxdeleted file mode 100644index 3f896867050..00000000000--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListViewer.tsx+++ /dev/null@@ -1,73 +0,0 @@-import { styled } from '@linaria/react';-import { useIsMobile } from 'twenty-ui/utilities';--import { getPageLayoutVerticalListViewerVariant } from '@/page-layout/components/utils/getPageLayoutVerticalListViewerVariant';-import { type PageLayoutVerticalListViewerVariant } from '@/page-layout/types/PageLayoutVerticalListViewerVariant';-import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';-import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';-import { useIsInPinnedTab } from '@/page-layout/widgets/hooks/useIsInPinnedTab';-import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';-import { themeCssVariables } from 'twenty-ui/theme-constants';--const StyledVerticalListContainer = styled.div<{- variant: PageLayoutVerticalListViewerVariant;- shouldUseWhiteBackground: boolean;-}>`- --widget-card-content-overflow: visible;- --widget-height: auto;- --widget-scroll-overflow: visible;-- background: ${({ shouldUseWhiteBackground }) =>- shouldUseWhiteBackground- ? themeCssVariables.background.primary- : themeCssVariables.background.secondary};- display: flex;- flex-direction: column;- gap: ${({ variant }) =>- variant === 'side-column' ? 0 : themeCssVariables.spacing[2]};- padding: ${({ variant }) =>- variant === 'side-column' ? 0 : themeCssVariables.spacing[2]};-`;--const StyledWidgetSlot = styled.div<{ shouldShowDivider: boolean }>`- &:not(:last-child) {- border-bottom: ${({ shouldShowDivider }) =>- shouldShowDivider- ? `1px solid ${themeCssVariables.border.color.light}`- : 'none'};- }-`;--type PageLayoutVerticalListViewerProps = {- widgets: PageLayoutWidget[];-};--export const PageLayoutVerticalListViewer = ({- widgets,-}: PageLayoutVerticalListViewerProps) => {- const { isInSidePanel } = useLayoutRenderingContext();- const isMobile = useIsMobile();- const { isInPinnedTab } = useIsInPinnedTab();-- const variant = getPageLayoutVerticalListViewerVariant({- isInPinnedTab,- isMobile,- isInSidePanel,- });-- return (- <StyledVerticalListContainer- variant={variant}- shouldUseWhiteBackground={!isInPinnedTab || isMobile}- >- {widgets.map((widget) => (- <StyledWidgetSlot- key={widget.id}- shouldShowDivider={variant === 'side-column'}- >- <WidgetRenderer widget={widget} />- </StyledWidgetSlot>- ))}- </StyledVerticalListContainer>- );-};diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListWidgetSlot.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListWidgetSlot.tsxnew file mode 100644index 00000000000..4c860d15d3d--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutVerticalListWidgetSlot.tsx@@ -0,0 +1,118 @@+import { PAGE_LAYOUT_WIDGET_DND_TYPE } from '@/page-layout/constants/PageLayoutWidgetDndType';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { type PageLayoutWidgetDragData } from '@/page-layout/types/PageLayoutWidgetDragData';+import { WidgetRenderer } from '@/page-layout/widgets/components/WidgetRenderer';+import { isViewportFillingWidgetType } from '@/page-layout/widgets/utils/isViewportFillingWidgetType';+import { DragDropItemDropTarget } from '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget';+import { DragDropItemSortableCell } from '@/ui/utilities/drag-and-drop/components/DragDropItemSortableCell';+import { type Draggable } from '@dnd-kit/abstract';+import { styled } from '@linaria/react';+import { themeCssVariables } from 'twenty-ui/theme-constants';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';++const StyledWidgetSlot = styled.div<{+ isInEditMode: boolean;+ shouldShowDivider: boolean;+}>`+ display: flex;+ flex: 0 0 auto;+ flex-direction: column;+ min-height: 0;+ min-width: 0;++ @container tab-viewport (min-height: 0px) {+ &.page-layout-viewport-filling-widget-slot {+ --widget-height: 100%;+ --widget-scroll-overflow: auto;++ height: calc(100cqh - var(--viewport-filling-widget-editor-block-inset));+ overflow: clip;++ .widget {+ overflow: clip;+ }++ .widget-card-header {+ background: var(--record-card-background-color);+ position: sticky;+ top: 0;+ z-index: 3;+ }+ }+ }++ &:not(:last-child) {+ border-bottom: ${({ isInEditMode, shouldShowDivider }) =>+ !isInEditMode && shouldShowDivider+ ? `1px solid ${themeCssVariables.border.color.light}`+ : 'none'};+ }+`;++type PageLayoutVerticalListWidgetSlotProps = {+ canAcceptWidgetDrag: (source: Draggable) => boolean;+ index: number;+ isInEditMode: boolean;+ isSoloCanvasPresentation: boolean;+ layoutMode: PageLayoutTabLayoutMode;+ shouldShowDivider: boolean;+ tabId: string;+ widget: PageLayoutWidget;+};++export const PageLayoutVerticalListWidgetSlot = ({+ canAcceptWidgetDrag,+ index,+ isInEditMode,+ isSoloCanvasPresentation,+ layoutMode,+ shouldShowDivider,+ tabId,+ widget,+}: PageLayoutVerticalListWidgetSlotProps) => {+ const fillsViewport =+ isSoloCanvasPresentation ||+ (layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST &&+ isViewportFillingWidgetType(widget.type));++ const widgetDragData: PageLayoutWidgetDragData = {+ type: 'widget',+ widgetId: widget.id,+ widgetType: widget.type,+ tabId,+ index,+ };++ return (+ <StyledWidgetSlot+ className={+ fillsViewport ? 'page-layout-viewport-filling-widget-slot' : undefined+ }+ isInEditMode={isInEditMode}+ shouldShowDivider={shouldShowDivider}+ >+ <DragDropItemDropTarget+ index={index}+ droppableId={tabId}+ orientation="horizontal"+ compact+ />+ <DragDropItemSortableCell+ id={widget.id}+ index={index}+ group={tabId}+ data={widgetDragData}+ type={PAGE_LAYOUT_WIDGET_DND_TYPE}+ accept={canAcceptWidgetDrag}+ allowNativeDragWhenDisabled+ disabled={!isInEditMode}+ hasTransition={false}+ highlightWhileDragging={isInEditMode}+ orientation="horizontal"+ fill={fillsViewport}+ >+ <WidgetRenderer widget={widget} />+ </DragDropItemSortableCell>+ </StyledWidgetSlot>+ );+};diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutContent.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutContent.test.tsxnew file mode 100644index 00000000000..783d066c3d3--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutContent.test.tsx@@ -0,0 +1,156 @@+import { PageLayoutContent } from '@/page-layout/components/PageLayoutContent';+import { makeTab } from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { fireEvent, render, screen } from '@testing-library/react';+import type * as React from 'react';+import {+ PageLayoutTabLayoutMode,+ WidgetConfigurationType,+ WidgetType,+} from '~/generated-metadata/graphql';++let mockIsInEditMode = false;++const mockWidget = {+ __typename: 'PageLayoutWidget',+ applicationId: 'application-id',+ configuration: {+ __typename: 'FieldsConfiguration',+ configurationType: WidgetConfigurationType.FIELDS,+ viewId: null,+ },+ createdAt: '2026-08-19T00:00:00.000Z',+ deletedAt: null,+ gridPosition: {+ __typename: 'GridPosition',+ column: 0,+ columnSpan: 1,+ row: 0,+ rowSpan: 1,+ },+ id: 'widget-id',+ isActive: true,+ isSystemSideEffect: false,+ objectMetadataId: null,+ pageLayoutTabId: 'tab-id',+ title: 'Fields',+ type: WidgetType.FIELDS,+ universalIdentifier: 'widget-universal-id',+ updatedAt: '2026-08-19T00:00:00.000Z',+} satisfies PageLayoutWidget;++const mockTab = makeTab(+ 'tab-id',+ [mockWidget],+ 0,+ PageLayoutTabLayoutMode.VERTICAL_LIST,+);++jest.mock('@/page-layout/contexts/PageLayoutContentContext', () => ({+ usePageLayoutContentContext: () => ({+ layoutMode: 'VERTICAL_LIST',+ tabId: 'tab-id',+ }),+}));++jest.mock('@/page-layout/hooks/useCurrentPageLayoutOrThrow', () => ({+ useCurrentPageLayoutOrThrow: () => ({+ currentPageLayout: {+ type: 'RECORD_PAGE',+ },+ }),+}));++jest.mock('@/page-layout/hooks/useIsPageLayoutInEditMode', () => ({+ useIsPageLayoutInEditMode: () => mockIsInEditMode,+}));++jest.mock(+ '@/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow',+ () => ({+ usePageLayoutTabWithVisibleWidgetsOrThrow: () => mockTab,+ }),+);++jest.mock('@/page-layout/hooks/useIsSideColumnContext', () => ({+ useIsSideColumnContext: () => false,+}));++jest.mock('@/page-layout/widgets/hooks/useIsInPinnedTab', () => ({+ useIsInPinnedTab: () => ({ isInPinnedTab: false }),+}));++jest.mock('@/page-layout/widgets/components/WidgetRenderer', () => {+ const { useState } = jest.requireActual('react') as typeof React;++ return {+ WidgetRenderer: () => {+ const [isExpanded, setIsExpanded] = useState(false);++ return (+ <button+ type="button"+ aria-expanded={isExpanded}+ onClick={() => setIsExpanded((current: boolean) => !current)}+ >+ Toggle widget expansion+ </button>+ );+ },+ };+});++jest.mock(+ '@/page-layout/widgets/components/RecordPageAddWidgetSection',+ () => ({+ RecordPageAddWidgetSection: () => <div>Add widget</div>,+ }),+);++jest.mock(+ '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget',+ () => ({+ DragDropItemDropTarget: () => null,+ }),+);++jest.mock(+ '@/ui/utilities/drag-and-drop/components/DragDropItemSortableCell',+ () => ({+ DragDropItemSortableCell: ({ children }: { children: React.ReactNode }) =>+ children,+ }),+);++jest.mock('@dnd-kit/react', () => ({+ useDroppable: () => ({ ref: jest.fn() }),+}));++jest.mock('twenty-ui/utilities', () => ({+ useIsMobile: () => false,+}));++describe('PageLayoutContent', () => {+ beforeEach(() => {+ mockIsInEditMode = false;+ });++ it('keeps widget-local state when edit mode changes', () => {+ const { rerender } = render(<PageLayoutContent />);+ const expansionButton = screen.getByRole('button', {+ name: 'Toggle widget expansion',+ });++ fireEvent.click(expansionButton);++ expect(expansionButton).toHaveAttribute('aria-expanded', 'true');++ mockIsInEditMode = true;+ rerender(<PageLayoutContent />);++ expect(+ screen.getByRole('button', { name: 'Toggle widget expansion' }),+ ).toHaveAttribute('aria-expanded', 'true');+ expect(screen.getByText('Add widget')).toBeInTheDocument();+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutLeftPanel.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutLeftPanel.test.tsxnew file mode 100644index 00000000000..8edc9a26f83--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutLeftPanel.test.tsx@@ -0,0 +1,149 @@+import { PageLayoutLeftPanel } from '@/page-layout/components/PageLayoutLeftPanel';+import { render, screen } from '@testing-library/react';+import { type ReactNode } from 'react';+import { PageLayoutType } from '~/generated-metadata/graphql';++let mockTargetRecordIdentifier = {+ id: 'record-id',+ targetObjectNameSingular: 'company',+};+let mockIsInSidePanel = false;++jest.mock('@/object-record/record-show/components/SummaryCard', () => ({+ SummaryCard: () => null,+}));++jest.mock('@/page-layout/components/PageLayoutContent', () => ({+ PageLayoutContent: () => <div>Page layout content</div>,+}));++jest.mock('@/page-layout/hooks/useCurrentPageLayout', () => ({+ useCurrentPageLayout: () => ({+ currentPageLayout: {+ type: PageLayoutType.RECORD_PAGE,+ },+ }),+}));++jest.mock(+ '@/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow',+ () => ({+ usePageLayoutTabWithVisibleWidgetsOrThrow: () => ({+ id: 'pinned-tab-id',+ }),+ }),+);++jest.mock('@/page-layout/utils/getTabLayoutMode', () => ({+ getTabLayoutMode: () => 'VERTICAL_LIST',+}));++jest.mock('@/ui/layout/contexts/LayoutRenderingContext', () => ({+ useLayoutRenderingContext: () => ({+ isInSidePanel: mockIsInSidePanel,+ layoutType: PageLayoutType.RECORD_PAGE,+ }),+}));++jest.mock('@/ui/layout/contexts/useTargetRecord', () => ({+ useTargetRecord: () => mockTargetRecordIdentifier,+}));++jest.mock('@/ui/utilities/scroll/components/ScrollWrapper', () => ({+ ScrollWrapper: ({+ children,+ componentInstanceId,+ }: {+ children: ReactNode;+ componentInstanceId: string;+ }) => (+ <div+ id={`scroll-wrapper-${componentInstanceId}`}+ data-testid="pinned-scroll-wrapper"+ >+ {children}+ </div>+ ),+}));++describe('PageLayoutLeftPanel', () => {+ beforeEach(() => {+ mockTargetRecordIdentifier = {+ id: 'record-id',+ targetObjectNameSingular: 'company',+ };+ mockIsInSidePanel = false;+ });++ it('resets the pinned scroll position when the target record changes', () => {+ const { rerender } = render(+ <PageLayoutLeftPanel+ pageLayoutId="page-layout-id"+ pinnedLeftTabId="pinned-tab-id"+ />,+ );++ const scrollWrapper = screen.getByTestId('pinned-scroll-wrapper');+ scrollWrapper.scrollTop = 200;++ mockTargetRecordIdentifier = {+ ...mockTargetRecordIdentifier,+ id: 'another-record-id',+ };++ rerender(+ <PageLayoutLeftPanel+ pageLayoutId="page-layout-id"+ pinnedLeftTabId="pinned-tab-id"+ />,+ );++ expect(scrollWrapper.scrollTop).toBe(0);+ });++ it('resets the pinned scroll wrapper owned by the current rendering context', () => {+ render(+ <PageLayoutLeftPanel+ pageLayoutId="page-layout-id"+ pinnedLeftTabId="pinned-tab-id"+ />,+ );++ const mainViewScrollWrapper = screen.getByTestId('pinned-scroll-wrapper');+ mainViewScrollWrapper.scrollTop = 200;++ mockTargetRecordIdentifier = {+ ...mockTargetRecordIdentifier,+ id: 'side-panel-record-id',+ };+ mockIsInSidePanel = true;++ const { rerender } = render(+ <PageLayoutLeftPanel+ pageLayoutId="page-layout-id"+ pinnedLeftTabId="pinned-tab-id"+ />,+ );+ const sidePanelScrollWrapper = screen.getAllByTestId(+ 'pinned-scroll-wrapper',+ )[1];++ expect(sidePanelScrollWrapper.id).not.toBe(mainViewScrollWrapper.id);++ sidePanelScrollWrapper.scrollTop = 200;+ mockTargetRecordIdentifier = {+ ...mockTargetRecordIdentifier,+ id: 'another-side-panel-record-id',+ };++ rerender(+ <PageLayoutLeftPanel+ pageLayoutId="page-layout-id"+ pinnedLeftTabId="pinned-tab-id"+ />,+ );++ expect(mainViewScrollWrapper.scrollTop).toBe(200);+ expect(sidePanelScrollWrapper.scrollTop).toBe(0);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutRecordPageCustomizationSessionRegistrationEffect.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutRecordPageCustomizationSessionRegistrationEffect.test.tsxnew file mode 100644index 00000000000..f186df5ac28--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutRecordPageCustomizationSessionRegistrationEffect.test.tsx@@ -0,0 +1,115 @@+import { activeCustomizationPageLayoutIdsState } from '@/layout-customization/states/activeCustomizationPageLayoutIdsState';+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import { PageLayoutRecordPageCustomizationSessionRegistrationEffect } from '@/page-layout/components/PageLayoutRecordPageCustomizationSessionRegistrationEffect';+import { useIsPageLayoutInEditMode } from '@/page-layout/hooks/useIsPageLayoutInEditMode';+import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { pageLayoutPersistedComponentState } from '@/page-layout/states/pageLayoutPersistedComponentState';+import {+ makeDraft,+ makeTab,+ makeWidget,+} from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayout } from '@/page-layout/types/PageLayout';+import { render, waitFor } from '@testing-library/react';+import { createStore, Provider as JotaiProvider } from 'jotai';+import { PageLayoutType, WidgetType } from '~/generated-metadata/graphql';++const PAGE_LAYOUT_ID = 'page-layout-id';++jest.mock('@/page-layout/hooks/useIsPageLayoutInEditMode');++const mockUseIsPageLayoutInEditMode =+ useIsPageLayoutInEditMode as jest.MockedFunction<+ typeof useIsPageLayoutInEditMode+ >;++const setupPageLayout = () => {+ const store = createStore();+ const timelineWidget = {+ ...makeWidget('timeline', 0),+ type: WidgetType.TIMELINE,+ };+ const fieldsWidget = makeWidget('fields', 1);+ const verticalListTab = makeTab('vertical-list-tab', [+ timelineWidget,+ fieldsWidget,+ ]);+ const persistedPageLayout = {+ id: PAGE_LAYOUT_ID,+ name: 'Record Page',+ type: PageLayoutType.RECORD_PAGE,+ objectMetadataId: 'object-metadata-id',+ tabs: [verticalListTab],+ } as PageLayout;++ store.set(isLayoutCustomizationModeEnabledState.atom, true);+ store.set(+ pageLayoutPersistedComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ persistedPageLayout,+ );+ store.set(+ pageLayoutDraftComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ makeDraft([verticalListTab]),+ );++ return store;+};++const renderRegistrationEffect = (store: ReturnType<typeof createStore>) =>+ render(+ <JotaiProvider store={store}>+ <PageLayoutComponentInstanceContext.Provider+ value={{ instanceId: PAGE_LAYOUT_ID }}+ >+ <PageLayoutRecordPageCustomizationSessionRegistrationEffect />+ </PageLayoutComponentInstanceContext.Provider>+ </JotaiProvider>,+ );++const getDraftWidgetIds = (store: ReturnType<typeof createStore>) =>+ store+ .get(+ pageLayoutDraftComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_ID,+ }),+ )+ .tabs[0].widgets.map((widget) => widget.id);++const waitForPageLayoutRegistration = (store: ReturnType<typeof createStore>) =>+ waitFor(() => {+ expect(store.get(activeCustomizationPageLayoutIdsState.atom)).toEqual([+ PAGE_LAYOUT_ID,+ ]);+ });++describe('PageLayoutRecordPageCustomizationSessionRegistrationEffect', () => {+ beforeEach(() => {+ mockUseIsPageLayoutInEditMode.mockReturnValue(true);+ });++ it('normalizes the draft when the record page enters edit mode', async () => {+ const store = setupPageLayout();++ renderRegistrationEffect(store);++ await waitFor(() => {+ expect(getDraftWidgetIds(store)).toEqual(['fields', 'timeline']);+ });+ await waitForPageLayoutRegistration(store);+ });++ it('does not normalize a record page mounted outside edit mode', async () => {+ mockUseIsPageLayoutInEditMode.mockReturnValue(false);+ const store = setupPageLayout();++ renderRegistrationEffect(store);++ await waitForPageLayoutRegistration(store);+ expect(getDraftWidgetIds(store)).toEqual(['timeline', 'fields']);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsxindex c23dfa929b3..7562f063811 100644--- a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutTabsRenderer.test.tsx@@ -7,6 +7,8 @@ import {} from '~/generated-metadata/graphql';let mockActiveTabId = 'hidden-transcript-tab-id';+let mockTargetRecordId = 'calendar-event-id';+let mockIsInSidePanel = false;const mockSetActiveTabId = jest.fn();const homeTab = {@@ -71,10 +73,10 @@ jest.mock('@/page-layout/PageLayoutMainContent', () => ({jest.mock('@/ui/layout/contexts/LayoutRenderingContext', () => ({useLayoutRenderingContext: () => ({- isInSidePanel: false,- layoutType: 'record-page',+ isInSidePanel: mockIsInSidePanel,+ layoutType: PageLayoutType.RECORD_PAGE,targetRecordIdentifier: {- id: 'calendar-event-id',+ id: mockTargetRecordId,targetObjectNameSingular: 'calendarEvent',},}),@@ -96,11 +98,26 @@ jest.mock('@/ui/utilities/responsive/hooks/useIsMobile', () => ({}));jest.mock('@/ui/utilities/scroll/components/ScrollWrapper', () => ({- ScrollWrapper: ({ children }: { children: ReactNode }) => <>{children}</>,+ ScrollWrapper: ({+ children,+ componentInstanceId,+ }: {+ children: ReactNode;+ componentInstanceId: string;+ }) => (+ <div+ id={`scroll-wrapper-${componentInstanceId}`}+ data-testid="scroll-wrapper"+ >+ {children}+ </div>+ ),}));describe('PageLayoutTabsRenderer', () => {beforeEach(() => {+ mockTargetRecordId = 'calendar-event-id';+ mockIsInSidePanel = false;mockSetActiveTabId.mockClear();});@@ -120,4 +137,43 @@ describe('PageLayoutTabsRenderer', () => {expect(screen.getByText('Rendered tab: home-tab-id')).toBeVisible();});++ it('resets the scroll position when the target record changes', () => {+ mockActiveTabId = 'home-tab-id';++ const { rerender } = render(<PageLayoutTabsRenderer />);++ const scrollWrapper = screen.getByTestId('scroll-wrapper');++ scrollWrapper.scrollTop = 200;+ mockTargetRecordId = 'another-calendar-event-id';++ rerender(<PageLayoutTabsRenderer />);++ expect(scrollWrapper.scrollTop).toBe(0);+ });++ it('resets the scroll wrapper owned by the current rendering context', () => {+ mockActiveTabId = 'home-tab-id';++ render(<PageLayoutTabsRenderer />);++ const mainViewScrollWrapper = screen.getByTestId('scroll-wrapper');+ mainViewScrollWrapper.scrollTop = 200;++ mockIsInSidePanel = true;++ const { rerender } = render(<PageLayoutTabsRenderer />);+ const sidePanelScrollWrapper = screen.getAllByTestId('scroll-wrapper')[1];++ expect(sidePanelScrollWrapper.id).not.toBe(mainViewScrollWrapper.id);++ sidePanelScrollWrapper.scrollTop = 200;+ mockActiveTabId = 'hidden-transcript-tab-id';++ rerender(<PageLayoutTabsRenderer />);++ expect(mainViewScrollWrapper.scrollTop).toBe(200);+ expect(sidePanelScrollWrapper.scrollTop).toBe(0);+ });});diff --git a/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutVerticalList.test.tsx b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutVerticalList.test.tsxnew file mode 100644index 00000000000..f916f187411--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/components/__tests__/PageLayoutVerticalList.test.tsx@@ -0,0 +1,336 @@+import { PageLayoutVerticalList } from '@/page-layout/components/PageLayoutVerticalList';+import { makeWidget as makePageLayoutWidget } from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { WorkflowDiagramAllowPageScrollContext } from '@/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext';+import { render, screen } from '@testing-library/react';+import { type ReactNode, useContext } from 'react';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';++let mockLayoutMode = PageLayoutTabLayoutMode.VERTICAL_LIST;+let mockIsSideColumnContext = false;+let mockIsInPinnedTab = false;++jest.mock('@/page-layout/contexts/PageLayoutContentContext', () => ({+ usePageLayoutContentContext: () => ({+ layoutMode: mockLayoutMode,+ tabId: 'tab-id',+ }),+}));++jest.mock('@/page-layout/hooks/useIsSideColumnContext', () => ({+ useIsSideColumnContext: () => ({+ isInPinnedTab: mockIsInPinnedTab,+ isMobile: false,+ isSideColumnContext: mockIsSideColumnContext,+ }),+}));++jest.mock('@/page-layout/widgets/components/WidgetRenderer', () => ({+ WidgetRenderer: ({ widget }: { widget: PageLayoutWidget }) => {+ const allowPageScroll = useContext(WorkflowDiagramAllowPageScrollContext);++ return (+ <div+ data-allow-page-scroll={String(allowPageScroll)}+ data-testid={widget.id}+ />+ );+ },+}));++jest.mock(+ '@/ui/utilities/drag-and-drop/components/DragDropItemDropTarget',+ () => ({+ DragDropItemDropTarget: () => null,+ }),+);++jest.mock(+ '@/ui/utilities/drag-and-drop/components/DragDropItemSortableCell',+ () => ({+ DragDropItemSortableCell: ({+ children,+ fill,+ id,+ }: {+ children: ReactNode;+ fill?: boolean;+ id: string;+ }) => (+ <div data-fill={String(fill)} data-testid={`${id}-sortable-cell`}>+ {children}+ </div>+ ),+ }),+);++jest.mock('@dnd-kit/react', () => ({+ useDroppable: () => ({ ref: jest.fn() }),+}));++const makeWidget = (id: string, type: WidgetType): PageLayoutWidget => ({+ ...makePageLayoutWidget(id, 0, 'tab-id'),+ type,+});++describe('PageLayoutVerticalList', () => {+ beforeEach(() => {+ mockLayoutMode = PageLayoutTabLayoutMode.VERTICAL_LIST;+ mockIsSideColumnContext = false;+ mockIsInPinnedTab = false;+ });++ it('gives Timeline FILL_VIEWPORT sizing regardless of its position', () => {+ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[+ makeWidget('timeline', WidgetType.TIMELINE),+ makeWidget('fields', WidgetType.FIELDS),+ ]}+ />,+ );++ expect(+ screen+ .getByTestId('timeline')+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).not.toBeNull();+ expect(screen.getByTestId('timeline-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'true',+ );+ expect(+ screen+ .getByTestId('fields')+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).toBeNull();+ expect(screen.getByTestId('fields-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ });++ it('gives FILL_VIEWPORT sizing to other viewport-filling widgets', () => {+ const viewportWidgets = [+ makeWidget('calendar', WidgetType.CALENDAR),+ makeWidget('call-recording-summary', WidgetType.CALL_RECORDING_SUMMARY),+ makeWidget(+ 'call-recording-transcript',+ WidgetType.CALL_RECORDING_TRANSCRIPT,+ ),+ makeWidget('emails', WidgetType.EMAILS),+ makeWidget('email-thread', WidgetType.EMAIL_THREAD),+ makeWidget('files', WidgetType.FILES),+ makeWidget('message-campaign-body', WidgetType.MESSAGE_CAMPAIGN_BODY),+ makeWidget('notes', WidgetType.NOTES),+ makeWidget('tasks', WidgetType.TASKS),+ makeWidget('workflow', WidgetType.WORKFLOW),+ ];++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('fields', WidgetType.FIELDS), ...viewportWidgets]}+ />,+ );++ for (const widget of viewportWidgets) {+ expect(+ screen+ .getByTestId(widget.id)+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).not.toBeNull();+ expect(screen.getByTestId(`${widget.id}-sortable-cell`)).toHaveAttribute(+ 'data-fill',+ 'true',+ );+ }++ expect(+ screen+ .getByTestId('fields')+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).toBeNull();+ });++ it('gives a lone Canvas front component viewport-filling sizing', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('front-component', WidgetType.FRONT_COMPONENT)]}+ />,+ );++ expect(+ screen+ .getByTestId('front-component')+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).not.toBeNull();+ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'true',+ );+ });++ it('keeps multiple Canvas widgets fit-content', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[+ makeWidget('front-component', WidgetType.FRONT_COMPONENT),+ makeWidget('fields', WidgetType.FIELDS),+ ]}+ />,+ );++ expect(+ screen+ .getByTestId('front-component')+ .closest('.page-layout-viewport-filling-widget-slot'),+ ).toBeNull();+ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ expect(screen.getByTestId('fields-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ });++ it('keeps a lone Canvas widget fit-content in edit mode', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;++ render(+ <PageLayoutVerticalList+ isInEditMode+ widgets={[makeWidget('front-component', WidgetType.FRONT_COMPONENT)]}+ />,+ );++ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ });++ it('keeps a lone Canvas front component viewport-filling in a side panel', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;+ mockIsSideColumnContext = true;++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('front-component', WidgetType.FRONT_COMPONENT)]}+ />,+ );++ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'true',+ );+ });++ it('keeps a lone Canvas widget fit-content in a pinned tab', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;+ mockIsInPinnedTab = true;++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('front-component', WidgetType.FRONT_COMPONENT)]}+ />,+ );++ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ });++ it('keeps front components fit-content in vertical lists', () => {+ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('front-component', WidgetType.FRONT_COMPONENT)]}+ />,+ );++ expect(screen.getByTestId('front-component-sortable-cell')).toHaveAttribute(+ 'data-fill',+ 'false',+ );+ });++ it('keeps the wheel on a workflow canvas that is alone in its tab', () => {+ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('workflow', WidgetType.WORKFLOW)]}+ />,+ );++ expect(screen.getByTestId('workflow')).toHaveAttribute(+ 'data-allow-page-scroll',+ 'false',+ );+ });++ it('lets the page scroll over a workflow canvas that shares its tab', () => {+ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[+ makeWidget('fields', WidgetType.FIELDS),+ makeWidget('workflow', WidgetType.WORKFLOW),+ ]}+ />,+ );++ expect(screen.getByTestId('workflow')).toHaveAttribute(+ 'data-allow-page-scroll',+ 'true',+ );+ });++ it('lets the page scroll over a workflow in a multi-widget Canvas tab', () => {+ mockLayoutMode = PageLayoutTabLayoutMode.CANVAS;++ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[+ makeWidget('fields', WidgetType.FIELDS),+ makeWidget('workflow', WidgetType.WORKFLOW),+ ]}+ />,+ );++ expect(screen.getByTestId('workflow')).toHaveAttribute(+ 'data-allow-page-scroll',+ 'true',+ );+ });++ it('keeps page scroll disabled when the list cannot scroll', () => {+ render(+ <PageLayoutVerticalList+ isInEditMode={false}+ widgets={[makeWidget('fields', WidgetType.FIELDS)]}+ />,+ );++ expect(screen.getByTestId('fields')).toHaveAttribute(+ 'data-allow-page-scroll',+ 'false',+ );+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutTabWidgetDropTarget.tsx b/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutTabWidgetDropTarget.tsxindex 5738a9ebca7..19965fe60ca 100644--- a/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutTabWidgetDropTarget.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutTabWidgetDropTarget.tsx@@ -1,13 +1,15 @@+import { type Draggable } from '@dnd-kit/abstract';import { pointerIntersection } from '@dnd-kit/collision';import { useDroppable } from '@dnd-kit/react';import { styled } from '@linaria/react';-import { type ReactNode } from 'react';+import { type ReactNode, useCallback } from 'react';import { themeCssVariables } from 'twenty-ui/theme-constants';import { PAGE_LAYOUT_TAB_DROP_TARGET_DATA_ATTRIBUTE } from '@/page-layout/constants/PageLayoutTabDropTargetDataAttribute';-import { PAGE_LAYOUT_WIDGET_DND_TYPE } from '@/page-layout/constants/PageLayoutWidgetDndType';import { pageLayoutGridDragHoveredTabIdComponentState } from '@/page-layout/states/pageLayoutGridDragHoveredTabIdComponentState';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { type PageLayoutTabWidgetDropData } from '@/page-layout/types/PageLayoutTabWidgetDropData';+import { canVerticalListAcceptWidgetDrag } from '@/page-layout/utils/canVerticalListAcceptWidgetDrag';import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';const StyledDropTarget = styled.div<{ isActive: boolean }>`@@ -24,11 +26,13 @@ const StyledDropTarget = styled.div<{ isActive: boolean }>`type PageLayoutTabWidgetDropTargetProps = {tabId: string;+ destinationWidgets: PageLayoutWidget[];children: ReactNode;};export const PageLayoutTabWidgetDropTarget = ({tabId,+ destinationWidgets,children,}: PageLayoutTabWidgetDropTargetProps) => {const data: PageLayoutTabWidgetDropData = {@@ -36,9 +40,15 @@ export const PageLayoutTabWidgetDropTarget = ({tabId,};+ const canAcceptWidgetDrag = useCallback(+ (source: Draggable) =>+ canVerticalListAcceptWidgetDrag({ destinationWidgets, source }),+ [destinationWidgets],+ );+const { ref, isDropTarget } = useDroppable({id: `page-layout-tab-widget-drop-${tabId}`,- accept: PAGE_LAYOUT_WIDGET_DND_TYPE,+ accept: canAcceptWidgetDrag,collisionDetector: pointerIntersection,data,});diff --git a/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutWidgetDndProvider.tsx b/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutWidgetDndProvider.tsxindex e479d3a8c0f..738832cc739 100644--- a/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutWidgetDndProvider.tsx+++ b/packages/twenty-front/src/modules/page-layout/components/dnd/PageLayoutWidgetDndProvider.tsx@@ -13,8 +13,8 @@ type PageLayoutWidgetDndProviderProps = {// Mounted in both view and edit mode so toggling edit mode does not remount the// layout subtree (which would reset scroll position and widget-local state).-// Widget sortables and drop targets only render while editing, so the provider-// is inert in view mode.+// Widget sortables are disabled and their terminal drop target is detached in+// view mode, so the provider is inert there.export const PageLayoutWidgetDndProvider = ({children,}: PageLayoutWidgetDndProviderProps) => {diff --git a/packages/twenty-front/src/modules/page-layout/components/utils/__tests__/getPageLayoutVerticalListViewerVariant.test.ts b/packages/twenty-front/src/modules/page-layout/components/utils/__tests__/getPageLayoutVerticalListViewerVariant.test.tsdeleted file mode 100644index 403715a4f01..00000000000--- a/packages/twenty-front/src/modules/page-layout/components/utils/__tests__/getPageLayoutVerticalListViewerVariant.test.ts+++ /dev/null@@ -1,43 +0,0 @@-import { getPageLayoutVerticalListViewerVariant } from '@/page-layout/components/utils/getPageLayoutVerticalListViewerVariant';--describe('getPageLayoutVerticalListViewerVariant', () => {- it('should return side-column when isInPinnedTab is true', () => {- expect(- getPageLayoutVerticalListViewerVariant({- isInPinnedTab: true,- isMobile: false,- isInSidePanel: false,- }),- ).toBe('side-column');- });-- it('should return side-column when isMobile is true', () => {- expect(- getPageLayoutVerticalListViewerVariant({- isInPinnedTab: false,- isMobile: true,- isInSidePanel: false,- }),- ).toBe('side-column');- });-- it('should return side-column when isInSidePanel is true', () => {- expect(- getPageLayoutVerticalListViewerVariant({- isInPinnedTab: false,- isMobile: false,- isInSidePanel: true,- }),- ).toBe('side-column');- });-- it('should return default when none of the conditions are true', () => {- expect(- getPageLayoutVerticalListViewerVariant({- isInPinnedTab: false,- isMobile: false,- isInSidePanel: false,- }),- ).toBe('default');- });-});diff --git a/packages/twenty-front/src/modules/page-layout/components/utils/getPageLayoutVerticalListViewerVariant.ts b/packages/twenty-front/src/modules/page-layout/components/utils/getPageLayoutVerticalListViewerVariant.tsdeleted file mode 100644index be1f33bfcb9..00000000000--- a/packages/twenty-front/src/modules/page-layout/components/utils/getPageLayoutVerticalListViewerVariant.ts+++ /dev/null@@ -1,19 +0,0 @@-import { type PageLayoutVerticalListViewerVariant } from '@/page-layout/types/PageLayoutVerticalListViewerVariant';--type GetPageLayoutVerticalListViewerVariantParams = {- isInPinnedTab: boolean;- isMobile: boolean;- isInSidePanel: boolean;-};--export const getPageLayoutVerticalListViewerVariant = ({- isInPinnedTab,- isMobile,- isInSidePanel,-}: GetPageLayoutVerticalListViewerVariantParams): PageLayoutVerticalListViewerVariant => {- if (isInPinnedTab || isMobile || isInSidePanel) {- return 'side-column';- }-- return 'default';-};diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetDown.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetDown.test.tsxindex 59e410ebc46..b101e4174ed 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetDown.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetDown.test.tsx@@ -8,7 +8,10 @@ import {import { renderHook } from '@testing-library/react';import { createStore } from 'jotai';import { type ReactNode } from 'react';-import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';import {PAGE_LAYOUT_TEST_INSTANCE_ID,PageLayoutTestWrapper,@@ -110,4 +113,79 @@ describe('useCanMovePageLayoutWidgetDown', () => {expect(result.current.canMovePageLayoutWidgetDown('widget-a')).toBe(false);});++ it('should return false for a FILL_VIEWPORT widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const timelineWidget = {+ ...makeWidget('timeline-widget', 0),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 1);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [timelineWidget, widgetB])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetDown(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetDown('timeline-widget')).toBe(+ false,+ );+ });++ it('should return false for the last fit-content widget before a viewport-filling widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const fieldsWidget = makeWidget('fields-widget', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [fieldsWidget, timelineWidget])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetDown(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetDown('fields-widget')).toBe(+ false,+ );+ });++ it('should ignore viewport-filling widgets when resolving the fit-content widget below', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget, widgetB])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetDown(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetDown('widget-a')).toBe(true);+ expect(result.current.canMovePageLayoutWidgetDown('widget-b')).toBe(false);+ });});diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetUp.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetUp.test.tsxindex a69b2f9bb28..11eaa7e5966 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetUp.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCanMovePageLayoutWidgetUp.test.tsx@@ -8,7 +8,10 @@ import {import { renderHook } from '@testing-library/react';import { createStore } from 'jotai';import { type ReactNode } from 'react';-import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';import {PAGE_LAYOUT_TEST_INSTANCE_ID,PageLayoutTestWrapper,@@ -110,4 +113,78 @@ describe('useCanMovePageLayoutWidgetUp', () => {expect(result.current.canMovePageLayoutWidgetUp('widget-b')).toBe(false);});++ it('should return false for a FILL_VIEWPORT widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetUp(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetUp('timeline-widget')).toBe(+ false,+ );+ });++ it('should ignore viewport-filling widgets when resolving the fit-content widget above', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget, widgetB])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetUp(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetUp('widget-b')).toBe(true);+ expect(result.current.canMovePageLayoutWidgetUp('widget-a')).toBe(false);+ });++ it('should not let a preceding viewport-filling widget make the first fit-content widget movable', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const timelineWidget = {+ ...makeWidget('timeline-widget', 0),+ type: WidgetType.TIMELINE,+ };+ const widgetA = makeWidget('widget-a', 1);+ const widgetB = makeWidget('widget-b', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [timelineWidget, widgetA, widgetB])]),+ );++ const { result } = renderHook(+ () => useCanMovePageLayoutWidgetUp(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ expect(result.current.canMovePageLayoutWidgetUp('widget-a')).toBe(false);+ });});diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCurrentPageLayout.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCurrentPageLayout.test.tsxnew file mode 100644index 00000000000..080260e036e--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useCurrentPageLayout.test.tsx@@ -0,0 +1,79 @@+import { isLayoutCustomizationModeEnabledState } from '@/layout-customization/states/isLayoutCustomizationModeEnabledState';+import {+ PAGE_LAYOUT_TEST_INSTANCE_ID,+ PageLayoutTestWrapper,+} from '@/page-layout/hooks/__tests__/PageLayoutTestWrapper';+import { useCurrentPageLayout } from '@/page-layout/hooks/useCurrentPageLayout';+import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { pageLayoutPersistedComponentState } from '@/page-layout/states/pageLayoutPersistedComponentState';+import {+ makeTab,+ makeWidget,+} from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayout } from '@/page-layout/types/PageLayout';+import { normalizeVerticalListWidgetsInDraftPageLayout } from '@/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout';+import { toDraftPageLayout } from '@/page-layout/utils/toDraftPageLayout';+import { act, renderHook } from '@testing-library/react';+import { createStore } from 'jotai';+import { type ReactNode } from 'react';+import { PageLayoutType, WidgetType } from '~/generated-metadata/graphql';++describe('useCurrentPageLayout', () => {+ it('keeps persisted widget order in view mode and uses normalized draft order in edit mode', () => {+ const store = createStore();+ const timelineWidget = {+ ...makeWidget('timeline', 0),+ type: WidgetType.TIMELINE,+ };+ const fieldsWidget = makeWidget('fields', 1);+ const persistedPageLayout = {+ id: PAGE_LAYOUT_TEST_INSTANCE_ID,+ name: 'Record Page',+ type: PageLayoutType.RECORD_PAGE,+ objectMetadataId: 'object-metadata-id',+ tabs: [makeTab('vertical-list-tab', [timelineWidget, fieldsWidget])],+ } as PageLayout;++ store.set(+ pageLayoutPersistedComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID,+ }),+ persistedPageLayout,+ );+ store.set(+ pageLayoutDraftComponentState.atomFamily({+ instanceId: PAGE_LAYOUT_TEST_INSTANCE_ID,+ }),+ normalizeVerticalListWidgetsInDraftPageLayout(+ toDraftPageLayout(persistedPageLayout),+ ),+ );++ const wrapper = ({ children }: { children: ReactNode }) => (+ <PageLayoutTestWrapper+ store={store}+ layoutType={PageLayoutType.RECORD_PAGE}+ >+ {children}+ </PageLayoutTestWrapper>+ );++ const { result } = renderHook(() => useCurrentPageLayout(), { wrapper });++ expect(+ result.current.currentPageLayout?.tabs[0].widgets.map(+ (widget) => widget.id,+ ),+ ).toEqual(['timeline', 'fields']);++ act(() => {+ store.set(isLayoutCustomizationModeEnabledState.atom, true);+ });++ expect(+ result.current.currentPageLayout?.tabs[0].widgets.map(+ (widget) => widget.id,+ ),+ ).toEqual(['fields', 'timeline']);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useInsertCreatedWidgetAtContext.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useInsertCreatedWidgetAtContext.test.tsxindex e1486854563..a4e7892ce24 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useInsertCreatedWidgetAtContext.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useInsertCreatedWidgetAtContext.test.tsx@@ -9,7 +9,10 @@ import {import { act, renderHook } from '@testing-library/react';import { createStore } from 'jotai';import { type ReactNode } from 'react';-import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';import {PAGE_LAYOUT_TEST_INSTANCE_ID,PageLayoutTestWrapper,@@ -101,6 +104,44 @@ describe('useInsertCreatedWidgetAtContext', () => {expect(widgetIds).toEqual(['widget-a', 'widget-c', 'widget-b']);});+ it('should normalize a newly inserted widget before the viewport-filling widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const newWidget = makeWidget('new-widget', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget, newWidget])]),+ );+ store.set(getInsertionContextAtom(), {+ targetWidgetId: 'timeline-widget',+ direction: 'below',+ });++ const { result } = renderHook(+ () => useInsertCreatedWidgetAtContext(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ act(() => {+ result.current.insertCreatedWidgetAtContext('new-widget');+ });++ const draft = store.get(getDraftAtom());++ expect(draft.tabs[0].widgets.map(({ id }) => id)).toEqual([+ 'widget-a',+ 'new-widget',+ 'timeline-widget',+ ]);+ });+it('should reindex all widgets with sequential positions', () => {const store = createStore();const wrapper = getWrapper(store);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetDown.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetDown.test.tsxindex 94f79092ae5..01d6f9816d2 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetDown.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetDown.test.tsx@@ -8,6 +8,7 @@ import {import { act, renderHook } from '@testing-library/react';import { createStore } from 'jotai';import { type ReactNode } from 'react';+import { WidgetType } from '~/generated-metadata/graphql';import {PAGE_LAYOUT_TEST_INSTANCE_ID,PageLayoutTestWrapper,@@ -62,6 +63,75 @@ describe('useMovePageLayoutWidgetDown', () => {expect(widgetBPosition).toEqual(expect.objectContaining({ index: 0 }));});+ it('should move relative to the fit-content widget below and canonicalize the list', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget, widgetB])]),+ );++ const { result } = renderHook(+ () => useMovePageLayoutWidgetDown(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ act(() => {+ result.current.movePageLayoutWidgetDown('widget-a');+ });++ const draft = store.get(getDraftAtom());++ expect(draft.tabs[0].widgets.map((widget) => widget.id)).toEqual([+ 'widget-b',+ 'widget-a',+ 'timeline-widget',+ ]);+ expect(+ draft.tabs[0].widgets.map((widget) =>+ widget.position && 'index' in widget.position+ ? widget.position.index+ : undefined,+ ),+ ).toEqual([0, 1, 2]);+ });++ it('should not move a viewport-filling widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);+ const initialDraft = makeDraft([+ makeTab('tab-1', [widgetA, timelineWidget, widgetB]),+ ]);++ store.set(getDraftAtom(), initialDraft);++ const { result } = renderHook(+ () => useMovePageLayoutWidgetDown(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ act(() => {+ result.current.movePageLayoutWidgetDown('timeline-widget');+ });++ expect(store.get(getDraftAtom())).toBe(initialDraft);+ });+it('should not change draft when widget is at the bottom', () => {const store = createStore();const wrapper = getWrapper(store);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetUp.test.tsx b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetUp.test.tsxindex be362675197..d6a5747955e 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetUp.test.tsx+++ b/packages/twenty-front/src/modules/page-layout/hooks/__tests__/useMovePageLayoutWidgetUp.test.tsx@@ -8,6 +8,7 @@ import {import { act, renderHook } from '@testing-library/react';import { createStore } from 'jotai';import { type ReactNode } from 'react';+import { WidgetType } from '~/generated-metadata/graphql';import {PAGE_LAYOUT_TEST_INSTANCE_ID,PageLayoutTestWrapper,@@ -62,6 +63,75 @@ describe('useMovePageLayoutWidgetUp', () => {expect(widgetAPosition).toEqual(expect.objectContaining({ index: 1 }));});+ it('should move relative to the fit-content widget above and canonicalize the list', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);++ store.set(+ getDraftAtom(),+ makeDraft([makeTab('tab-1', [widgetA, timelineWidget, widgetB])]),+ );++ const { result } = renderHook(+ () => useMovePageLayoutWidgetUp(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ act(() => {+ result.current.movePageLayoutWidgetUp('widget-b');+ });++ const draft = store.get(getDraftAtom());++ expect(draft.tabs[0].widgets.map((widget) => widget.id)).toEqual([+ 'widget-b',+ 'widget-a',+ 'timeline-widget',+ ]);+ expect(+ draft.tabs[0].widgets.map((widget) =>+ widget.position && 'index' in widget.position+ ? widget.position.index+ : undefined,+ ),+ ).toEqual([0, 1, 2]);+ });++ it('should not move a viewport-filling widget', () => {+ const store = createStore();+ const wrapper = getWrapper(store);++ const widgetA = makeWidget('widget-a', 0);+ const timelineWidget = {+ ...makeWidget('timeline-widget', 1),+ type: WidgetType.TIMELINE,+ };+ const widgetB = makeWidget('widget-b', 2);+ const initialDraft = makeDraft([+ makeTab('tab-1', [widgetA, timelineWidget, widgetB]),+ ]);++ store.set(getDraftAtom(), initialDraft);++ const { result } = renderHook(+ () => useMovePageLayoutWidgetUp(PAGE_LAYOUT_TEST_INSTANCE_ID),+ { wrapper },+ );++ act(() => {+ result.current.movePageLayoutWidgetUp('timeline-widget');+ });++ expect(store.get(getDraftAtom())).toBe(initialDraft);+ });+it('should not change draft when widget is already at the top', () => {const store = createStore();const wrapper = getWrapper(store);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetDown.ts b/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetDown.tsindex 82319aa45ea..11693f7df25 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetDown.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetDown.ts@@ -1,10 +1,12 @@import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { getAdjacentFitContentWidgetIndex } from '@/page-layout/utils/getAdjacentFitContentWidgetIndex';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useStore } from 'jotai';import { useCallback } from 'react';+import { isDefined } from 'twenty-shared/utils';import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';export const useCanMovePageLayoutWidgetDown = (@@ -40,7 +42,13 @@ export const useCanMovePageLayoutWidgetDown = ((widget) => widget.id === widgetId,);- return widgetIndex >= 0 && widgetIndex < sortedWidgets.length - 1;+ return isDefined(+ getAdjacentFitContentWidgetIndex({+ widgets: sortedWidgets,+ widgetIndex,+ direction: 'down',+ }),+ );},[pageLayoutDraftState, store],);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetUp.ts b/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetUp.tsindex 7b3bdb0bd68..e46b6a2cf24 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetUp.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useCanMovePageLayoutWidgetUp.ts@@ -1,10 +1,12 @@import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { getAdjacentFitContentWidgetIndex } from '@/page-layout/utils/getAdjacentFitContentWidgetIndex';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useStore } from 'jotai';import { useCallback } from 'react';+import { isDefined } from 'twenty-shared/utils';import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';export const useCanMovePageLayoutWidgetUp = (@@ -40,7 +42,13 @@ export const useCanMovePageLayoutWidgetUp = ((widget) => widget.id === widgetId,);- return widgetIndex > 0;+ return isDefined(+ getAdjacentFitContentWidgetIndex({+ widgets: sortedWidgets,+ widgetIndex,+ direction: 'up',+ }),+ );},[pageLayoutDraftState, store],);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.tsindex 74448d7fd84..847768b583f 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts@@ -7,9 +7,7 @@ import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/paimport { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';import { addWidgetToTab } from '@/page-layout/utils/addWidgetToTab';import { generateDuplicatedTimestamps } from '@/page-layout/utils/generateDuplicatedTimestamps';-import { getScrollWrapperInstanceIdFromPageLayoutId } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutId';import { getUpdatedTabLayouts } from '@/page-layout/utils/getUpdatedTabLayouts';-import { useScrollWrapperHTMLElement } from '@/ui/utilities/scroll/hooks/useScrollWrapperHTMLElement';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';@@ -41,10 +39,6 @@ export const useDuplicatePageLayoutWidget = (pageLayoutId,);- const { getScrollWrapperElement } = useScrollWrapperHTMLElement(- getScrollWrapperInstanceIdFromPageLayoutId(pageLayoutId),- );-const store = useStore();const { duplicateFieldsWidget } = useDuplicateFieldsWidgetForPageLayout({@@ -140,22 +134,18 @@ export const useDuplicatePageLayoutWidget = (setPageLayoutEditingWidgetId(newWidgetId);- const { scrollWrapperElement } = getScrollWrapperElement();-- if (isDefined(scrollWrapperElement)) {- requestAnimationFrame(() => {- const widgetElement = scrollWrapperElement.querySelector(- `[data-widget-id="${newWidgetId}"]`,- );-- if (isDefined(widgetElement)) {+ requestAnimationFrame(() => {+ // The same page layout can be mounted in the main view and a side panel+ // at once, so every render of the new widget is brought into view.+ document+ .querySelectorAll(`[data-widget-id="${newWidgetId}"]`)+ .forEach((widgetElement) => {widgetElement.scrollIntoView({behavior: 'smooth',block: 'nearest',});- }- });- }+ });+ });return newWidgetId;},@@ -165,7 +155,6 @@ export const useDuplicatePageLayoutWidget = (pageLayoutCurrentLayoutsState,pageLayoutDraftState,setPageLayoutEditingWidgetId,- getScrollWrapperElement,store,],);diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useInsertCreatedWidgetAtContext.ts b/packages/twenty-front/src/modules/page-layout/hooks/useInsertCreatedWidgetAtContext.tsindex ee0d0ac6c5a..388a95f4921 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useInsertCreatedWidgetAtContext.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useInsertCreatedWidgetAtContext.ts@@ -1,13 +1,12 @@import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';import { widgetInsertionContextComponentState } from '@/page-layout/states/widgetInsertionContextComponentState';-import { isVerticalListPosition } from '@/page-layout/utils/isVerticalListPosition';+import { reindexWidgetsToVerticalListPositions } from '@/page-layout/utils/reindexWidgetsToVerticalListPositions';+import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useStore } from 'jotai';import { useCallback } from 'react';-import { isDefined } from 'twenty-shared/utils';-import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';export const useInsertCreatedWidgetAtContext = (pageLayoutIdFromProps?: string,@@ -48,19 +47,7 @@ export const useInsertCreatedWidgetAtContext = (return prev;}- const sortedWidgets = tab.widgets.toSorted((widgetA, widgetB) => {- const indexA =- isDefined(widgetA.position) &&- isVerticalListPosition(widgetA.position)- ? widgetA.position.index- : 0;- const indexB =- isDefined(widgetB.position) &&- isVerticalListPosition(widgetB.position)- ? widgetB.position.index- : 0;- return indexA - indexB;- });+ const sortedWidgets = sortWidgetsByVerticalListPosition(tab.widgets);const targetIndex = sortedWidgets.findIndex((widget) => widget.id === insertionContext.targetWidgetId,@@ -89,16 +76,8 @@ export const useInsertCreatedWidgetAtContext = (widgetsWithoutNew.splice(insertAtIndex, 0, newWidget);- const reindexedWidgets = widgetsWithoutNew.map(- (widget, widgetIndex) => ({- ...widget,- position: {- __typename: 'PageLayoutWidgetVerticalListPosition' as const,- layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,- index: widgetIndex,- },- }),- );+ const reindexedWidgets =+ reindexWidgetsToVerticalListPositions(widgetsWithoutNew);return {...prev,diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useIsSideColumnContext.ts b/packages/twenty-front/src/modules/page-layout/hooks/useIsSideColumnContext.tsindex 2a97cbbf43d..68dd8db2a5a 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useIsSideColumnContext.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useIsSideColumnContext.ts@@ -1,4 +1,3 @@-import { getPageLayoutVerticalListViewerVariant } from '@/page-layout/components/utils/getPageLayoutVerticalListViewerVariant';import { useIsInPinnedTab } from '@/page-layout/widgets/hooks/useIsInPinnedTab';import { useLayoutRenderingContext } from '@/ui/layout/contexts/LayoutRenderingContext';import { useIsMobile } from 'twenty-ui/utilities';@@ -17,11 +16,6 @@ export const useIsSideColumnContext = (): UseIsSideColumnContextReturn => {return {isInPinnedTab,isMobile,- isSideColumnContext:- getPageLayoutVerticalListViewerVariant({- isInPinnedTab,- isMobile,- isInSidePanel,- }) === 'side-column',+ isSideColumnContext: isInPinnedTab || isMobile || isInSidePanel,};};diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetDown.ts b/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetDown.tsindex 64065f1b1bc..71bd75dd8c9 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetDown.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetDown.ts@@ -1,11 +1,13 @@import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { getAdjacentFitContentWidgetIndex } from '@/page-layout/utils/getAdjacentFitContentWidgetIndex';import { moveWidgetWithinTabInDraft } from '@/page-layout/utils/moveWidgetWithinTabInDraft';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useStore } from 'jotai';import { useCallback } from 'react';+import { isDefined } from 'twenty-shared/utils';export const useMovePageLayoutWidgetDown = (pageLayoutIdFromProps?: string) => {const pageLayoutId = useAvailableComponentInstanceIdOrThrow(@@ -35,15 +37,20 @@ export const useMovePageLayoutWidgetDown = (pageLayoutIdFromProps?: string) => {const currentIndex = sortedWidgets.findIndex((widget) => widget.id === widgetId,);+ const targetIndex = getAdjacentFitContentWidgetIndex({+ widgets: sortedWidgets,+ widgetIndex: currentIndex,+ direction: 'down',+ });- if (currentIndex < 0 || currentIndex >= sortedWidgets.length - 1) {+ if (!isDefined(targetIndex)) {return prev;}return moveWidgetWithinTabInDraft(prev, {tabId: tab.id,fromIndex: currentIndex,- toIndex: currentIndex + 1,+ toIndex: targetIndex,});});},diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetUp.ts b/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetUp.tsindex 5d524b854fc..fe9e702e269 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetUp.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/useMovePageLayoutWidgetUp.ts@@ -1,11 +1,13 @@import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';+import { getAdjacentFitContentWidgetIndex } from '@/page-layout/utils/getAdjacentFitContentWidgetIndex';import { moveWidgetWithinTabInDraft } from '@/page-layout/utils/moveWidgetWithinTabInDraft';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';import { useStore } from 'jotai';import { useCallback } from 'react';+import { isDefined } from 'twenty-shared/utils';export const useMovePageLayoutWidgetUp = (pageLayoutIdFromProps?: string) => {const pageLayoutId = useAvailableComponentInstanceIdOrThrow(@@ -31,18 +33,24 @@ export const useMovePageLayoutWidgetUp = (pageLayoutIdFromProps?: string) => {return prev;}- const currentIndex = sortWidgetsByVerticalListPosition(- tab.widgets,- ).findIndex((widget) => widget.id === widgetId);+ const sortedWidgets = sortWidgetsByVerticalListPosition(tab.widgets);+ const currentIndex = sortedWidgets.findIndex(+ (widget) => widget.id === widgetId,+ );+ const targetIndex = getAdjacentFitContentWidgetIndex({+ widgets: sortedWidgets,+ widgetIndex: currentIndex,+ direction: 'up',+ });- if (currentIndex <= 0) {+ if (!isDefined(targetIndex)) {return prev;}return moveWidgetWithinTabInDraft(prev, {tabId: tab.id,fromIndex: currentIndex,- toIndex: currentIndex - 1,+ toIndex: targetIndex,});});},diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow.tsindex c062a431ce0..8553acfbe64 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabWithVisibleWidgetsOrThrow.ts@@ -4,6 +4,7 @@ import { useWidgetVisibilityContext } from '@/page-layout/hooks/useWidgetVisibilimport { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';import { filterVisibleWidgets } from '@/page-layout/utils/filterVisibleWidgets';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';+import { useMemo } from 'react';import { isDefined } from 'twenty-shared/utils';import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';@@ -17,32 +18,34 @@ export const usePageLayoutTabWithVisibleWidgetsOrThrow = (const tab = featureFilteredPageLayoutTabs.find((tab) => tab.id === tabId);- if (!isDefined(tab)) {- throw new Error('Tab not found');- }+ // Memoized because consumers feed this widget array to dnd-kit and to+ // memoized callbacks, which a fresh array on every render would defeat.+ const tabWithVisibleWidgets = useMemo(() => {+ if (!isDefined(tab)) {+ return undefined;+ }++ const activeWidgets = tab.widgets.filter((widget) => widget.isActive);- const activeWidgets = tab.widgets.filter((widget) => widget.isActive);+ const widgets = isPageLayoutInEditMode+ ? activeWidgets+ : filterVisibleWidgets({+ widgets: activeWidgets,+ context: widgetVisibilityContext,+ });- if (isPageLayoutInEditMode) {return {...tab,widgets:tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST- ? sortWidgetsByVerticalListPosition(activeWidgets)- : activeWidgets,+ ? sortWidgetsByVerticalListPosition(widgets)+ : widgets,};+ }, [isPageLayoutInEditMode, tab, widgetVisibilityContext]);++ if (!isDefined(tabWithVisibleWidgets)) {+ throw new Error('Tab not found');}- const visibleWidgets = filterVisibleWidgets({- widgets: activeWidgets,- context: widgetVisibilityContext,- });-- return {- ...tab,- widgets:- tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST- ? sortWidgetsByVerticalListPosition(visibleWidgets)- : visibleWidgets,- };+ return tabWithVisibleWidgets;};diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabsFilteredByFeatureFlags.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabsFilteredByFeatureFlags.tsindex 57fb232d13a..a25f1b83701 100644--- a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabsFilteredByFeatureFlags.ts+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutTabsFilteredByFeatureFlags.ts@@ -1,6 +1,7 @@import { useCurrentPageLayoutOrThrow } from '@/page-layout/hooks/useCurrentPageLayoutOrThrow';import { filterPageLayoutTabsByFeatureFlags } from '@/page-layout/utils/filterPageLayoutTabsByFeatureFlags';import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';+import { useMemo } from 'react';import { FeatureFlagKey } from '~/generated-metadata/graphql';export const usePageLayoutTabsFilteredByFeatureFlags = () => {@@ -10,10 +11,14 @@ export const usePageLayoutTabsFilteredByFeatureFlags = () => {FeatureFlagKey.IS_NATIVE_CALL_RECORDING_TABS_ENABLED,);- const featureFilteredPageLayoutTabs = filterPageLayoutTabsByFeatureFlags({- tabs: currentPageLayout.tabs,- isNativeCallRecordingTabsEnabled,- });+ const featureFilteredPageLayoutTabs = useMemo(+ () =>+ filterPageLayoutTabsByFeatureFlags({+ tabs: currentPageLayout.tabs,+ isNativeCallRecordingTabsEnabled,+ }),+ [currentPageLayout.tabs, isNativeCallRecordingTabsEnabled],+ );return { featureFilteredPageLayoutTabs };};diff --git a/packages/twenty-front/src/modules/page-layout/types/PageLayoutVerticalListViewerVariant.ts b/packages/twenty-front/src/modules/page-layout/types/PageLayoutVerticalListViewerVariant.tsdeleted file mode 100644index 7f8081a8dca..00000000000--- a/packages/twenty-front/src/modules/page-layout/types/PageLayoutVerticalListViewerVariant.ts+++ /dev/null@@ -1 +0,0 @@-export type PageLayoutVerticalListViewerVariant = 'default' | 'side-column';diff --git a/packages/twenty-front/src/modules/page-layout/types/PageLayoutWidgetDragData.ts b/packages/twenty-front/src/modules/page-layout/types/PageLayoutWidgetDragData.tsindex fa9c30030d0..57fcb6f5066 100644--- a/packages/twenty-front/src/modules/page-layout/types/PageLayoutWidgetDragData.ts+++ b/packages/twenty-front/src/modules/page-layout/types/PageLayoutWidgetDragData.ts@@ -1,6 +1,9 @@+import { type WidgetType } from '~/generated-metadata/graphql';+export type PageLayoutWidgetDragData = {type: 'widget';widgetId: string;+ widgetType: WidgetType;tabId: string;index: number;};diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/addWidgetToTab.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/addWidgetToTab.test.tsindex 29e876cc09a..81ed084353c 100644--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/addWidgetToTab.test.ts+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/addWidgetToTab.test.ts@@ -2,6 +2,7 @@ import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';import { addWidgetToTab } from '@/page-layout/utils/addWidgetToTab';import {AggregateOperations,+ PageLayoutTabLayoutMode,WidgetConfigurationType,WidgetType,type PageLayoutWidget,@@ -106,4 +107,74 @@ describe('addWidgetToTab', () => {expect(mockTabs[0].widgets).toHaveLength(0);expect(result[0].widgets).toHaveLength(1);});++ it('should normalize an appended widget before a viewport-filling widget in a vertical-list tab', () => {+ const timelineWidget = {+ ...mockWidget,+ id: 'timeline-widget',+ type: WidgetType.TIMELINE,+ };+ const verticalListTab = {+ ...mockTabs[0],+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [timelineWidget],+ };++ const result = addWidgetToTab([verticalListTab], 'tab-1', mockWidget);++ expect(result[0].widgets.map(({ id }) => id)).toEqual([+ 'widget-1',+ 'timeline-widget',+ ]);+ expect(result[0].widgets.map(({ position }) => position)).toEqual([+ {+ __typename: 'PageLayoutWidgetVerticalListPosition',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 0,+ },+ {+ __typename: 'PageLayoutWidgetVerticalListPosition',+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 1,+ },+ ]);+ });++ it('should preserve saved vertical-list order when appending to an unsorted widget array', () => {+ const widgetA = {+ ...mockWidget,+ id: 'widget-a',+ position: {+ __typename: 'PageLayoutWidgetVerticalListPosition' as const,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 1,+ },+ };+ const widgetB = {+ ...mockWidget,+ id: 'widget-b',+ position: {+ __typename: 'PageLayoutWidgetVerticalListPosition' as const,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ index: 0,+ },+ };+ const verticalListTab = {+ ...mockTabs[0],+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ widgets: [widgetA, widgetB],+ };+ const newWidget = {+ ...mockWidget,+ id: 'widget-c',+ };++ const result = addWidgetToTab([verticalListTab], 'tab-1', newWidget);++ expect(result[0].widgets.map(({ id }) => id)).toEqual([+ 'widget-b',+ 'widget-a',+ 'widget-c',+ ]);+ });});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/canVerticalListAcceptWidget.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/canVerticalListAcceptWidget.test.tsnew file mode 100644index 00000000000..130b70a8c6b--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/canVerticalListAcceptWidget.test.ts@@ -0,0 +1,68 @@+import { makeWidget } from '@/page-layout/testing/pageLayoutDraftFixtures';+import { canVerticalListAcceptWidget } from '@/page-layout/utils/canVerticalListAcceptWidget';+import { WidgetType } from '~/generated-metadata/graphql';++const makeWidgetWithType = (id: string, type: WidgetType, tabId = 'tab-1') => ({+ ...makeWidget(id, 0, tabId),+ type,+});++describe('canVerticalListAcceptWidget', () => {+ it('rejects a viewport-filling widget when the destination already has one', () => {+ expect(+ canVerticalListAcceptWidget({+ destinationWidgets: [+ makeWidgetWithType('emails', WidgetType.EMAILS, 'tab-2'),+ ],+ widget: makeWidgetWithType('notes', WidgetType.NOTES),+ }),+ ).toBe(false);+ });++ it('accepts a viewport-filling widget when the destination only has fit-content widgets', () => {+ expect(+ canVerticalListAcceptWidget({+ destinationWidgets: [+ makeWidgetWithType('fields', WidgetType.FIELDS, 'tab-2'),+ ],+ widget: makeWidgetWithType('notes', WidgetType.NOTES),+ }),+ ).toBe(true);+ });++ it('accepts a fit-content widget when the destination has a viewport-filling widget', () => {+ expect(+ canVerticalListAcceptWidget({+ destinationWidgets: [+ makeWidgetWithType('emails', WidgetType.EMAILS, 'tab-2'),+ ],+ widget: makeWidgetWithType('fields', WidgetType.FIELDS),+ }),+ ).toBe(true);+ });++ it('ignores the dragged widget itself during a same-tab reorder', () => {+ const notesWidget = makeWidgetWithType('notes', WidgetType.NOTES);++ expect(+ canVerticalListAcceptWidget({+ destinationWidgets: [notesWidget],+ widget: notesWidget,+ }),+ ).toBe(true);+ });++ it('ignores inactive viewport-filling widgets in the destination', () => {+ expect(+ canVerticalListAcceptWidget({+ destinationWidgets: [+ {+ ...makeWidgetWithType('emails', WidgetType.EMAILS, 'tab-2'),+ isActive: false,+ },+ ],+ widget: makeWidgetWithType('notes', WidgetType.NOTES),+ }),+ ).toBe(true);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/getIsSingleWidgetTab.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getIsSingleWidgetTab.test.tsnew file mode 100644index 00000000000..6d109465b18--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getIsSingleWidgetTab.test.ts@@ -0,0 +1,65 @@+import { makeWidget } from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { getIsSingleWidgetTab } from '@/page-layout/utils/getIsSingleWidgetTab';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';++const widget = (id: string, isActive: boolean): PageLayoutWidget => ({+ ...makeWidget(id, 0),+ isActive,+});++const tabWith = (+ layoutMode: PageLayoutTabLayoutMode,+ widgets: PageLayoutWidget[],+): Pick<PageLayoutTab, 'layoutMode' | 'widgets'> => ({ layoutMode, widgets });++describe('getIsSingleWidgetTab', () => {+ it('returns true for a list tab holding a single active widget', () => {+ expect(+ getIsSingleWidgetTab({+ tab: tabWith(PageLayoutTabLayoutMode.VERTICAL_LIST, [+ widget('widget-1', true),+ ]),+ }),+ ).toBe(true);+ });++ it('ignores inactive widgets', () => {+ expect(+ getIsSingleWidgetTab({+ tab: tabWith(PageLayoutTabLayoutMode.VERTICAL_LIST, [+ widget('widget-1', true),+ widget('widget-2', false),+ ]),+ }),+ ).toBe(true);+ });++ it('returns false when several widgets are active', () => {+ expect(+ getIsSingleWidgetTab({+ tab: tabWith(PageLayoutTabLayoutMode.VERTICAL_LIST, [+ widget('widget-1', true),+ widget('widget-2', true),+ ]),+ }),+ ).toBe(false);+ });++ it('returns false for an empty tab', () => {+ expect(+ getIsSingleWidgetTab({+ tab: tabWith(PageLayoutTabLayoutMode.VERTICAL_LIST, []),+ }),+ ).toBe(false);+ });++ it('returns false for grid tabs', () => {+ expect(+ getIsSingleWidgetTab({+ tab: tabWith(PageLayoutTabLayoutMode.GRID, [widget('widget-1', true)]),+ }),+ ).toBe(false);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/getScrollWrapperInstanceIdFromPageLayoutAndRecord.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getScrollWrapperInstanceIdFromPageLayoutAndRecord.test.tsnew file mode 100644index 00000000000..470a1a58e5d--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getScrollWrapperInstanceIdFromPageLayoutAndRecord.test.ts@@ -0,0 +1,52 @@+import { getScrollWrapperInstanceIdFromPageLayoutAndRecord } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord';+import { PageLayoutType } from '~/generated-metadata/graphql';++describe('getScrollWrapperInstanceIdFromPageLayoutAndRecord', () => {+ const getInstanceId = ({+ recordId,+ isInSidePanel = false,+ }: {+ recordId: string;+ isInSidePanel?: boolean;+ }) =>+ getScrollWrapperInstanceIdFromPageLayoutAndRecord({+ pageLayoutId: 'page-layout-id',+ layoutType: PageLayoutType.RECORD_PAGE,+ targetRecordIdentifier: {+ id: recordId,+ targetObjectNameSingular: 'company',+ },+ isInSidePanel,+ scrollWrapperArea: 'tab-content',+ });++ it('creates different instance IDs for different records', () => {+ expect(getInstanceId({ recordId: 'record-id' })).not.toBe(+ getInstanceId({ recordId: 'another-record-id' }),+ );+ });++ it('creates different instance IDs for main and side panel renderings', () => {+ expect(getInstanceId({ recordId: 'record-id' })).not.toBe(+ getInstanceId({ recordId: 'record-id', isInSidePanel: true }),+ );+ });++ it('creates different instance IDs for tab content and the left panel', () => {+ const tabContentInstanceId = getInstanceId({ recordId: 'record-id' });+ const leftPanelInstanceId =+ getScrollWrapperInstanceIdFromPageLayoutAndRecord({+ pageLayoutId: 'page-layout-id',+ layoutType: PageLayoutType.RECORD_PAGE,+ targetRecordIdentifier: {+ id: 'record-id',+ targetObjectNameSingular: 'company',+ },+ isInSidePanel: false,+ scrollWrapperArea: 'left-panel',+ pageLayoutTabId: 'pinned-tab-id',+ });++ expect(tabContentInstanceId).not.toBe(leftPanelInstanceId);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/moveWidgetToTabInDraft.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/moveWidgetToTabInDraft.test.tsindex e233be81c04..d8f6f04e544 100644--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/moveWidgetToTabInDraft.test.ts+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/moveWidgetToTabInDraft.test.ts@@ -5,7 +5,10 @@ import {makeTab,makeWidget,} from '@/page-layout/testing/pageLayoutDraftFixtures';-import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';const indicesOf = (draft: DraftPageLayout, tabIndex: number) =>draft.tabs[tabIndex].widgets.map((widget) =>@@ -153,4 +156,49 @@ describe('moveWidgetToTabInDraft', () => {}),).toBe(draft);});++ it('returns the draft unchanged when moving a viewport-filling widget into a tab that already has one', () => {+ const notesWidget = {+ ...makeWidget('notes', 0),+ type: WidgetType.NOTES,+ };+ const emailsWidget = {+ ...makeWidget('emails', 0, 'tab-2'),+ type: WidgetType.EMAILS,+ };+ const draft = makeDraft([+ makeTab('tab-1', [notesWidget]),+ makeTab('tab-2', [emailsWidget], 1),+ ]);++ expect(+ moveWidgetToTabInDraft(draft, {+ widgetId: 'notes',+ destinationTabId: 'tab-2',+ }),+ ).toBe(draft);+ });++ it('moves a fit-content widget into a tab that has a viewport-filling widget', () => {+ const fieldsWidget = makeWidget('fields', 0);+ const emailsWidget = {+ ...makeWidget('emails', 0, 'tab-2'),+ type: WidgetType.EMAILS,+ };+ const draft = makeDraft([+ makeTab('tab-1', [fieldsWidget]),+ makeTab('tab-2', [emailsWidget], 1),+ ]);++ const result = moveWidgetToTabInDraft(draft, {+ widgetId: 'fields',+ destinationTabId: 'tab-2',+ });++ expect(result.tabs[0].widgets).toHaveLength(0);+ expect(result.tabs[1].widgets.map(({ id }) => id)).toEqual([+ 'fields',+ 'emails',+ ]);+ });});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/normalizeVerticalListWidgetsInDraftPageLayout.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/normalizeVerticalListWidgetsInDraftPageLayout.test.tsnew file mode 100644index 00000000000..0c3f6cf5a95--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/normalizeVerticalListWidgetsInDraftPageLayout.test.ts@@ -0,0 +1,97 @@+import {+ makeDraft,+ makeTab,+ makeWidget,+} from '@/page-layout/testing/pageLayoutDraftFixtures';+import { isVerticalListPosition } from '@/page-layout/utils/isVerticalListPosition';+import { normalizeVerticalListWidgetsInDraftPageLayout } from '@/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout';+import { isDefined } from 'twenty-shared/utils';+import {+ PageLayoutTabLayoutMode,+ WidgetType,+} from '~/generated-metadata/graphql';++describe('normalizeVerticalListWidgetsInDraftPageLayout', () => {+ it('normalizes vertical-list widgets from their persisted positions', () => {+ const timelineWidget = {+ ...makeWidget('timeline', 0),+ type: WidgetType.TIMELINE,+ };+ const fieldsWidget = makeWidget('fields', 2);+ const fieldWidget = {+ ...makeWidget('field', 1),+ type: WidgetType.FIELD,+ };+ const draftPageLayout = makeDraft([+ makeTab('vertical-list-tab', [fieldsWidget, timelineWidget, fieldWidget]),+ ]);++ const normalizedDraft =+ normalizeVerticalListWidgetsInDraftPageLayout(draftPageLayout);++ expect(+ normalizedDraft.tabs[0].widgets.map((widget) => ({+ id: widget.id,+ position: widget.position,+ })),+ ).toEqual([+ {+ id: 'field',+ position: expect.objectContaining({ index: 0 }),+ },+ {+ id: 'fields',+ position: expect.objectContaining({ index: 1 }),+ },+ {+ id: 'timeline',+ position: expect.objectContaining({ index: 2 }),+ },+ ]);+ });++ it('does not modify the source draft', () => {+ const timelineWidget = {+ ...makeWidget('timeline', 0),+ type: WidgetType.TIMELINE,+ };+ const fieldsWidget = makeWidget('fields', 1);+ const draftPageLayout = makeDraft([+ makeTab('vertical-list-tab', [timelineWidget, fieldsWidget]),+ ]);++ normalizeVerticalListWidgetsInDraftPageLayout(draftPageLayout);++ expect(draftPageLayout.tabs[0].widgets.map((widget) => widget.id)).toEqual([+ 'timeline',+ 'fields',+ ]);+ expect(+ draftPageLayout.tabs[0].widgets.map((widget) =>+ isDefined(widget.position) && isVerticalListPosition(widget.position)+ ? widget.position.index+ : undefined,+ ),+ ).toEqual([0, 1]);+ });++ it('leaves grid widgets unchanged', () => {+ const firstWidget = makeWidget('first', 1);+ const secondWidget = makeWidget('second', 0);+ const gridTab = makeTab(+ 'grid-tab',+ [firstWidget, secondWidget],+ 0,+ PageLayoutTabLayoutMode.GRID,+ );++ const normalizedDraft = normalizeVerticalListWidgetsInDraftPageLayout(+ makeDraft([gridTab]),+ );++ expect(normalizedDraft.tabs[0].widgets).toEqual([+ firstWidget,+ secondWidget,+ ]);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/sortWidgetsWithViewportFillingLast.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/sortWidgetsWithViewportFillingLast.test.tsnew file mode 100644index 00000000000..cd1aca0ed6a--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/sortWidgetsWithViewportFillingLast.test.ts@@ -0,0 +1,68 @@+import { makeWidget } from '@/page-layout/testing/pageLayoutDraftFixtures';+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { sortWidgetsWithViewportFillingLast } from '@/page-layout/utils/sortWidgetsWithViewportFillingLast';+import { WidgetType } from '~/generated-metadata/graphql';++const makeWidgetWithType = (+ id: string,+ index: number,+ type: WidgetType,+): PageLayoutWidget => ({+ ...makeWidget(id, index),+ type,+});++describe('sortWidgetsWithViewportFillingLast', () => {+ it('normalizes a viewport-filling widget after fit-content widgets during edits', () => {+ const timelineWidget = makeWidgetWithType(+ 'timeline',+ 0,+ WidgetType.TIMELINE,+ );+ const fieldsWidget = makeWidgetWithType('fields', 1, WidgetType.FIELDS);+ const fieldWidget = makeWidgetWithType('field', 2, WidgetType.FIELD);++ expect(+ sortWidgetsWithViewportFillingLast([+ timelineWidget,+ fieldsWidget,+ fieldWidget,+ ]).map(({ id }) => id),+ ).toEqual(['fields', 'field', 'timeline']);+ });++ it('keeps two viewport-filling widgets at the end in their existing order', () => {+ const timelineWidget = makeWidgetWithType(+ 'timeline',+ 0,+ WidgetType.TIMELINE,+ );+ const fieldsWidget = makeWidgetWithType('fields', 1, WidgetType.FIELDS);+ const emailsWidget = makeWidgetWithType('emails', 2, WidgetType.EMAILS);+ const richTextWidget = makeWidgetWithType(+ 'rich-text',+ 3,+ WidgetType.STANDALONE_RICH_TEXT,+ );++ expect(+ sortWidgetsWithViewportFillingLast([+ timelineWidget,+ fieldsWidget,+ emailsWidget,+ richTextWidget,+ ]).map(({ id }) => id),+ ).toEqual(['fields', 'rich-text', 'timeline', 'emails']);+ });++ it('preserves the order of fit-content widgets', () => {+ const fieldsWidget = makeWidgetWithType('fields', 0, WidgetType.FIELDS);+ const fieldWidget = makeWidgetWithType('field', 1, WidgetType.FIELD);++ expect(+ sortWidgetsWithViewportFillingLast([fieldsWidget, fieldWidget]).map(+ ({ id }) => id,+ ),+ ).toEqual(['fields', 'field']);+ });+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/addWidgetToTab.ts b/packages/twenty-front/src/modules/page-layout/utils/addWidgetToTab.tsindex 1c71806a05c..c037a1a3338 100644--- a/packages/twenty-front/src/modules/page-layout/utils/addWidgetToTab.ts+++ b/packages/twenty-front/src/modules/page-layout/utils/addWidgetToTab.ts@@ -1,5 +1,8 @@import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { reindexWidgetsToVerticalListPositions } from '@/page-layout/utils/reindexWidgetsToVerticalListPositions';+import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';export const addWidgetToTab = (tabs: PageLayoutTab[],@@ -8,9 +11,18 @@ export const addWidgetToTab = (): PageLayoutTab[] => {return tabs.map((tab) => {if (tab.id === activeTabId) {+ const existingWidgets =+ tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST+ ? sortWidgetsByVerticalListPosition(tab.widgets)+ : tab.widgets;+ const widgets = [...existingWidgets, newWidget];+return {...tab,- widgets: [...(tab?.widgets ?? []), newWidget],+ widgets:+ tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST+ ? reindexWidgetsToVerticalListPositions(widgets)+ : widgets,};}return tab;diff --git a/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidget.ts b/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidget.tsnew file mode 100644index 00000000000..37ada2e4083--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidget.ts@@ -0,0 +1,19 @@+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { isViewportFillingWidgetType } from '@/page-layout/widgets/utils/isViewportFillingWidgetType';++type CanVerticalListAcceptWidgetParams = {+ destinationWidgets: PageLayoutWidget[];+ widget: Pick<PageLayoutWidget, 'id' | 'type'>;+};++export const canVerticalListAcceptWidget = ({+ destinationWidgets,+ widget,+}: CanVerticalListAcceptWidgetParams): boolean =>+ !isViewportFillingWidgetType(widget.type) ||+ !destinationWidgets.some(+ (destinationWidget) =>+ destinationWidget.id !== widget.id &&+ destinationWidget.isActive &&+ isViewportFillingWidgetType(destinationWidget.type),+ );diff --git a/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidgetDrag.ts b/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidgetDrag.tsnew file mode 100644index 00000000000..c76bdc9271c--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/canVerticalListAcceptWidgetDrag.ts@@ -0,0 +1,28 @@+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { type PageLayoutWidgetDndData } from '@/page-layout/types/PageLayoutWidgetDndData';+import { canVerticalListAcceptWidget } from '@/page-layout/utils/canVerticalListAcceptWidget';+import { type Draggable } from '@dnd-kit/abstract';++type CanVerticalListAcceptWidgetDragParams = {+ destinationWidgets: PageLayoutWidget[];+ source: Draggable;+};++export const canVerticalListAcceptWidgetDrag = ({+ destinationWidgets,+ source,+}: CanVerticalListAcceptWidgetDragParams): boolean => {+ const sourceData = source.data as PageLayoutWidgetDndData | undefined;++ if (sourceData?.type !== 'widget') {+ return false;+ }++ return canVerticalListAcceptWidget({+ destinationWidgets,+ widget: {+ id: sourceData.widgetId,+ type: sourceData.widgetType,+ },+ });+};diff --git a/packages/twenty-front/src/modules/page-layout/utils/getAdjacentFitContentWidgetIndex.ts b/packages/twenty-front/src/modules/page-layout/utils/getAdjacentFitContentWidgetIndex.tsnew file mode 100644index 00000000000..0043f3a42c4--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/getAdjacentFitContentWidgetIndex.ts@@ -0,0 +1,36 @@+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { isViewportFillingWidgetType } from '@/page-layout/widgets/utils/isViewportFillingWidgetType';++type GetAdjacentFitContentWidgetIndexParams = {+ widgets: PageLayoutWidget[];+ widgetIndex: number;+ direction: 'up' | 'down';+};++export const getAdjacentFitContentWidgetIndex = ({+ widgets,+ widgetIndex,+ direction,+}: GetAdjacentFitContentWidgetIndexParams): number | undefined => {+ if (+ !(widgetIndex in widgets) ||+ isViewportFillingWidgetType(widgets[widgetIndex].type)+ ) {+ return undefined;+ }++ const adjacentFitContentWidgetIndex =+ direction === 'up'+ ? widgets.findLastIndex(+ (widget, index) =>+ index < widgetIndex && !isViewportFillingWidgetType(widget.type),+ )+ : widgets.findIndex(+ (widget, index) =>+ index > widgetIndex && !isViewportFillingWidgetType(widget.type),+ );++ return adjacentFitContentWidgetIndex >= 0+ ? adjacentFitContentWidgetIndex+ : undefined;+};diff --git a/packages/twenty-front/src/modules/page-layout/utils/getIsSingleWidgetTab.ts b/packages/twenty-front/src/modules/page-layout/utils/getIsSingleWidgetTab.tsnew file mode 100644index 00000000000..579c5da75db--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/getIsSingleWidgetTab.ts@@ -0,0 +1,12 @@+import { type PageLayoutTab } from '@/page-layout/types/PageLayoutTab';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';++type GetIsSingleWidgetTabParams = {+ tab: Pick<PageLayoutTab, 'layoutMode' | 'widgets'>;+};++export const getIsSingleWidgetTab = ({+ tab,+}: GetIsSingleWidgetTabParams): boolean =>+ tab.layoutMode !== PageLayoutTabLayoutMode.GRID &&+ tab.widgets.filter((widget) => widget.isActive).length === 1;diff --git a/packages/twenty-front/src/modules/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord.ts b/packages/twenty-front/src/modules/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord.tsnew file mode 100644index 00000000000..ef2401f2ce8--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutAndRecord.ts@@ -0,0 +1,35 @@+import { getScrollWrapperInstanceIdFromPageLayoutId } from '@/page-layout/utils/getScrollWrapperInstanceIdFromPageLayoutId';+import { type LayoutRenderingContextType } from '@/ui/layout/contexts/LayoutRenderingContext';+import { type TargetRecordIdentifier } from '@/ui/layout/contexts/TargetRecordIdentifier';+import { isDefined } from 'twenty-shared/utils';+import { PageLayoutType } from '~/generated-metadata/graphql';++type PageLayoutScrollWrapperArea = 'left-panel' | 'tab-content';++export const getScrollWrapperInstanceIdFromPageLayoutAndRecord = ({+ pageLayoutId,+ layoutType,+ targetRecordIdentifier,+ isInSidePanel,+ scrollWrapperArea,+ pageLayoutTabId,+}: {+ pageLayoutId: string;+ layoutType: LayoutRenderingContextType['layoutType'];+ targetRecordIdentifier?: TargetRecordIdentifier;+ isInSidePanel: boolean;+ scrollWrapperArea: PageLayoutScrollWrapperArea;+ pageLayoutTabId?: string;+}) => {+ const recordId =+ layoutType === PageLayoutType.RECORD_PAGE+ ? targetRecordIdentifier?.id+ : undefined;+ const recordScope = isDefined(recordId) ? `-${recordId}` : '';+ const renderingScope = isInSidePanel ? 'side-panel' : 'main-view';+ const tabScope = isDefined(pageLayoutTabId) ? `-${pageLayoutTabId}` : '';++ return `${getScrollWrapperInstanceIdFromPageLayoutId(+ pageLayoutId,+ )}${recordScope}-${renderingScope}-${scrollWrapperArea}${tabScope}`;+};diff --git a/packages/twenty-front/src/modules/page-layout/utils/moveWidgetToTabInDraft.ts b/packages/twenty-front/src/modules/page-layout/utils/moveWidgetToTabInDraft.tsindex f9f03c5a755..cf16ccd549b 100644--- a/packages/twenty-front/src/modules/page-layout/utils/moveWidgetToTabInDraft.ts+++ b/packages/twenty-front/src/modules/page-layout/utils/moveWidgetToTabInDraft.ts@@ -1,4 +1,5 @@import { type DraftPageLayout } from '@/page-layout/types/DraftPageLayout';+import { canVerticalListAcceptWidget } from '@/page-layout/utils/canVerticalListAcceptWidget';import { reindexWidgetsToVerticalListPositions } from '@/page-layout/utils/reindexWidgetsToVerticalListPositions';import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';import { isDefined } from 'twenty-shared/utils';@@ -45,6 +46,15 @@ export const moveWidgetToTabInDraft = (return draft;}+ if (+ !canVerticalListAcceptWidget({+ destinationWidgets: destinationTab.widgets,+ widget,+ })+ ) {+ return draft;+ }+const remainingWidgets = reindexWidgetsToVerticalListPositions(sortWidgetsByVerticalListPosition(sourceTab.widgets).filter((tabWidget) => tabWidget.id !== widgetId,diff --git a/packages/twenty-front/src/modules/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout.ts b/packages/twenty-front/src/modules/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout.tsnew file mode 100644index 00000000000..b16df7e9d74--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/normalizeVerticalListWidgetsInDraftPageLayout.ts@@ -0,0 +1,20 @@+import { type DraftPageLayout } from '@/page-layout/types/DraftPageLayout';+import { reindexWidgetsToVerticalListPositions } from '@/page-layout/utils/reindexWidgetsToVerticalListPositions';+import { sortWidgetsByVerticalListPosition } from '@/page-layout/utils/sortWidgetsByVerticalListPosition';+import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';++export const normalizeVerticalListWidgetsInDraftPageLayout = (+ draftPageLayout: DraftPageLayout,+): DraftPageLayout => ({+ ...draftPageLayout,+ tabs: draftPageLayout.tabs.map((tab) =>+ tab.layoutMode === PageLayoutTabLayoutMode.VERTICAL_LIST+ ? {+ ...tab,+ widgets: reindexWidgetsToVerticalListPositions(+ sortWidgetsByVerticalListPosition(tab.widgets),+ ),+ }+ : tab,+ ),+});diff --git a/packages/twenty-front/src/modules/page-layout/utils/reindexWidgetsToVerticalListPositions.ts b/packages/twenty-front/src/modules/page-layout/utils/reindexWidgetsToVerticalListPositions.tsindex 3e961826a36..b613d45193a 100644--- a/packages/twenty-front/src/modules/page-layout/utils/reindexWidgetsToVerticalListPositions.ts+++ b/packages/twenty-front/src/modules/page-layout/utils/reindexWidgetsToVerticalListPositions.ts@@ -1,10 +1,11 @@import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { sortWidgetsWithViewportFillingLast } from '@/page-layout/utils/sortWidgetsWithViewportFillingLast';import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';export const reindexWidgetsToVerticalListPositions = (widgets: PageLayoutWidget[],): PageLayoutWidget[] =>- widgets.map((widget, index) => ({+ sortWidgetsWithViewportFillingLast(widgets).map((widget, index) => ({...widget,position: {__typename: 'PageLayoutWidgetVerticalListPosition' as const,diff --git a/packages/twenty-front/src/modules/page-layout/utils/sortWidgetsWithViewportFillingLast.ts b/packages/twenty-front/src/modules/page-layout/utils/sortWidgetsWithViewportFillingLast.tsnew file mode 100644index 00000000000..5ce273508d0--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/utils/sortWidgetsWithViewportFillingLast.ts@@ -0,0 +1,9 @@+import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';+import { isViewportFillingWidgetType } from '@/page-layout/widgets/utils/isViewportFillingWidgetType';++export const sortWidgetsWithViewportFillingLast = (+ widgets: PageLayoutWidget[],+): PageLayoutWidget[] => [+ ...widgets.filter((widget) => !isViewportFillingWidgetType(widget.type)),+ ...widgets.filter((widget) => isViewportFillingWidgetType(widget.type)),+];diff --git a/packages/twenty-front/src/modules/page-layout/widgets/utils/__tests__/isViewportFillingWidgetType.test.ts b/packages/twenty-front/src/modules/page-layout/widgets/utils/__tests__/isViewportFillingWidgetType.test.tsnew file mode 100644index 00000000000..155c1a094cd--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/widgets/utils/__tests__/isViewportFillingWidgetType.test.ts@@ -0,0 +1,39 @@+import { isViewportFillingWidgetType } from '@/page-layout/widgets/utils/isViewportFillingWidgetType';+import { WidgetType } from '~/generated-metadata/graphql';++const expectedIsViewportFillingByWidgetType = {+ [WidgetType.CALENDAR]: true,+ [WidgetType.CALL_RECORDING_SUMMARY]: true,+ [WidgetType.CALL_RECORDING_TRANSCRIPT]: true,+ [WidgetType.EMAILS]: true,+ [WidgetType.EMAIL_THREAD]: true,+ [WidgetType.FIELD]: false,+ [WidgetType.FIELDS]: false,+ [WidgetType.FIELD_RICH_TEXT]: false,+ [WidgetType.FILES]: true,+ [WidgetType.FRONT_COMPONENT]: false,+ [WidgetType.GRAPH]: false,+ [WidgetType.IFRAME]: false,+ [WidgetType.MESSAGE_CAMPAIGN_BODY]: true,+ [WidgetType.MESSAGE_CAMPAIGN_DETAILS]: false,+ [WidgetType.NOTES]: true,+ [WidgetType.RECORD_TABLE]: false,+ [WidgetType.STANDALONE_RICH_TEXT]: false,+ [WidgetType.TASKS]: true,+ [WidgetType.TIMELINE]: true,+ [WidgetType.VIEW]: false,+ [WidgetType.WORKFLOW]: true,+ [WidgetType.WORKFLOW_RUN]: true,+ [WidgetType.WORKFLOW_VERSION]: true,+} satisfies Record<WidgetType, boolean>;++describe('isViewportFillingWidgetType', () => {+ it.each(Object.values(WidgetType))(+ 'returns whether %s fills the viewport',+ (widgetType) => {+ expect(isViewportFillingWidgetType(widgetType)).toBe(+ expectedIsViewportFillingByWidgetType[widgetType],+ );+ },+ );+});diff --git a/packages/twenty-front/src/modules/page-layout/widgets/utils/isViewportFillingWidgetType.ts b/packages/twenty-front/src/modules/page-layout/widgets/utils/isViewportFillingWidgetType.tsnew file mode 100644index 00000000000..86f025c8d1d--- /dev/null+++ b/packages/twenty-front/src/modules/page-layout/widgets/utils/isViewportFillingWidgetType.ts@@ -0,0 +1,43 @@+import { WidgetType } from '~/generated-metadata/graphql';++export const isViewportFillingWidgetType = (+ widgetType: WidgetType,+): boolean => {+ switch (widgetType) {+ case WidgetType.CALENDAR:+ case WidgetType.CALL_RECORDING_SUMMARY:+ case WidgetType.CALL_RECORDING_TRANSCRIPT:+ case WidgetType.EMAILS:+ case WidgetType.EMAIL_THREAD:+ case WidgetType.FILES:+ case WidgetType.MESSAGE_CAMPAIGN_BODY:+ case WidgetType.NOTES:+ case WidgetType.TASKS:+ case WidgetType.TIMELINE:+ case WidgetType.WORKFLOW:+ case WidgetType.WORKFLOW_RUN:+ case WidgetType.WORKFLOW_VERSION:+ return true;++ case WidgetType.IFRAME:+ // Iframes use a fixed height because their content height is not measurable.+ return false;++ case WidgetType.RECORD_TABLE:+ // Record tables keep their own interactive frame and are not collapsed.+ return false;++ case WidgetType.MESSAGE_CAMPAIGN_DETAILS:+ // This type is classified even though it currently renders no content.+ return false;++ case WidgetType.FIELD:+ case WidgetType.FIELDS:+ case WidgetType.FIELD_RICH_TEXT:+ case WidgetType.FRONT_COMPONENT:+ case WidgetType.GRAPH:+ case WidgetType.STANDALONE_RICH_TEXT:+ case WidgetType.VIEW:+ return false;+ }+};diff --git a/packages/twenty-front/src/modules/ui/utilities/drag-and-drop/components/DragDropItemSortableCell.tsx b/packages/twenty-front/src/modules/ui/utilities/drag-and-drop/components/DragDropItemSortableCell.tsxindex c11992aea5f..a88f68d7f57 100644--- a/packages/twenty-front/src/modules/ui/utilities/drag-and-drop/components/DragDropItemSortableCell.tsx+++ b/packages/twenty-front/src/modules/ui/utilities/drag-and-drop/components/DragDropItemSortableCell.tsx@@ -2,7 +2,7 @@ import {RestrictToHorizontalAxis,RestrictToVerticalAxis,} from '@dnd-kit/abstract/modifiers';-import { useSortable } from '@dnd-kit/react/sortable';+import { type UseSortableInput, useSortable } from '@dnd-kit/react/sortable';import { styled } from '@linaria/react';import { type ReactNode } from 'react';import { isDefined } from 'twenty-shared/utils';@@ -55,7 +55,8 @@ const StyledSortableRoot = styled.div<{`;type DragDropItemSortableCellProps = {- accept?: string;+ accept?: UseSortableInput['accept'];+ allowNativeDragWhenDisabled?: boolean;children: ReactNode;data?: Record<string, unknown>;disabled?: boolean;@@ -75,6 +76,7 @@ type DragDropItemSortableCellProps = {export const DragDropItemSortableCell = ({accept,+ allowNativeDragWhenDisabled = false,children,data,disabled = false,@@ -122,7 +124,11 @@ export const DragDropItemSortableCell = ({$fill={fill}$isDragSourceFaded={fadeSourceWhileDragging && isDragSource}$isDraggingHighlighted={highlightWhileDragging && isDragging}- onDragStart={preventNativeDragStart}+ onDragStart={+ disabled && allowNativeDragWhenDisabled+ ? undefined+ : preventNativeDragStart+ }>{children}</StyledSortableRoot>diff --git a/packages/twenty-front/src/modules/workflow/workflow-diagram/components/WorkflowDiagramCanvasBase.tsx b/packages/twenty-front/src/modules/workflow/workflow-diagram/components/WorkflowDiagramCanvasBase.tsxindex 5f32ba7eb69..bf1d4798bc8 100644--- a/packages/twenty-front/src/modules/workflow/workflow-diagram/components/WorkflowDiagramCanvasBase.tsx+++ b/packages/twenty-front/src/modules/workflow/workflow-diagram/components/WorkflowDiagramCanvasBase.tsx@@ -9,6 +9,7 @@ import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSeimport { WorkflowDiagramRightClickCommandMenu } from '@/workflow/workflow-diagram/components/WorkflowDiagramRightClickCommandMenu';import { WORKFLOW_DIAGRAM_EMPTY_NODE_DEFINITION } from '@/workflow/workflow-diagram/constants/WorkflowDiagramEmptyNodeDefinition';import { useResetWorkflowInsertStepIds } from '@/workflow/workflow-diagram/hooks/useResetWorkflowInsertStepIds';+import { WorkflowDiagramAllowPageScrollContext } from '@/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext';import { useWorkflowDiagramScreenToFlowPosition } from '@/workflow/workflow-diagram/hooks/useWorkflowDiagramScreenToFlowPosition';import { workflowDiagramComponentState } from '@/workflow/workflow-diagram/states/workflowDiagramComponentState';import { workflowDiagramPanOnDragComponentState } from '@/workflow/workflow-diagram/states/workflowDiagramPanOnDragComponentState';@@ -165,6 +166,7 @@ export const WorkflowDiagramCanvasBase = ({}) => void;}) => {const { theme, colorScheme } = useContext(ThemeContext);+ const allowPageScroll = useContext(WorkflowDiagramAllowPageScrollContext);const store = useStore();const reactflow = useReactFlow();@@ -617,11 +619,11 @@ export const WorkflowDiagramCanvasBase = ({nodesDraggable={nodesDraggable}edgesFocusable={isDefined(onDeleteEdge)}panOnDrag={workflowDiagramPanOnDrag}- panOnScroll={true}+ panOnScroll={!allowPageScroll}onPaneContextMenu={onPaneContextMenu}nodesConnectable={nodesConnectable}paneClickDistance={10} // Fix small unwanted user dragging does not select node- preventScrolling={true}+ preventScrolling={!allowPageScroll}connectionLineComponent={WorkflowDiagramConnection}connectionRadius={0}colorMode={colorScheme}diff --git a/packages/twenty-front/src/modules/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext.ts b/packages/twenty-front/src/modules/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext.tsnew file mode 100644index 00000000000..d6c31367cd6--- /dev/null+++ b/packages/twenty-front/src/modules/workflow/workflow-diagram/contexts/WorkflowDiagramAllowPageScrollContext.ts@@ -0,0 +1,3 @@+import { createContext } from 'react';++export const WorkflowDiagramAllowPageScrollContext = createContext(false);diff --git a/packages/twenty-server/test/integration/metadata/suites/application/successful-manifest-update-page-layout-tab.integration-spec.ts b/packages/twenty-server/test/integration/metadata/suites/application/successful-manifest-update-page-layout-tab.integration-spec.tsindex 92a6b3e97a4..af6d74e62f6 100644--- a/packages/twenty-server/test/integration/metadata/suites/application/successful-manifest-update-page-layout-tab.integration-spec.ts+++ b/packages/twenty-server/test/integration/metadata/suites/application/successful-manifest-update-page-layout-tab.integration-spec.ts@@ -3,6 +3,7 @@ import { cleanupApplicationAndAppRegistration } from 'test/integration/metadata/import { setupApplicationForSync } from 'test/integration/metadata/suites/application/utils/setup-application-for-sync.util';import { syncApplication } from 'test/integration/metadata/suites/application/utils/sync-application.util';import { findPageLayoutTabs } from 'test/integration/metadata/suites/page-layout-tab/utils/find-page-layout-tabs.util';+import { findPageLayoutWidgets } from 'test/integration/metadata/suites/page-layout-widget/utils/find-page-layout-widgets.util';import { type Manifest } from 'twenty-shared/application';import { STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS } from 'twenty-shared/metadata';import { PageLayoutTabLayoutMode } from 'twenty-shared/types';@@ -11,6 +12,7 @@ import { v4 as uuidv4 } from 'uuid';const TEST_APP_ID = uuidv4();const TEST_ROLE_ID = uuidv4();const TEST_TAB_ID = uuidv4();+const TEST_WIDGET_ID = uuidv4();const STANDARD_PERSON_PAGE_LAYOUT_UNIVERSAL_ID =STANDARD_PAGE_LAYOUT_UNIVERSAL_IDENTIFIERS.personRecordPage@@ -18,12 +20,28 @@ const STANDARD_PERSON_PAGE_LAYOUT_UNIVERSAL_ID =const PAGE_LAYOUT_TAB_GQL_FIELDS = `id+ universalIdentifiertitleposition+ layoutModepageLayoutIdapplicationId`;+const PAGE_LAYOUT_WIDGET_GQL_FIELDS = `+ id+ universalIdentifier+ applicationId+ pageLayoutTabId+ title+ type+ configuration {+ ... on TimelineConfiguration {+ configurationType+ }+ }+`;+let testApplicationId: string;let standardPersonPageLayoutId: string;@@ -156,6 +174,107 @@ describe('Manifest update - page layout tabs (standalone)', () => {});}, 60000);+ it('should migrate a standalone tab from canvas to vertical list without replacing its widget', async () => {+ const buildPageLayoutTab = (layoutMode: PageLayoutTabLayoutMode) => ({+ universalIdentifier: TEST_TAB_ID,+ pageLayoutUniversalIdentifier: STANDARD_PERSON_PAGE_LAYOUT_UNIVERSAL_ID,+ title: 'Timeline',+ position: 1000,+ layoutMode,+ widgets: [+ {+ universalIdentifier: TEST_WIDGET_ID,+ title: 'Timeline',+ type: 'TIMELINE',+ configuration: {+ configurationType: 'TIMELINE' as const,+ },+ },+ ],+ });++ await syncApplication({+ manifest: buildManifest({+ pageLayoutTabs: [buildPageLayoutTab(PageLayoutTabLayoutMode.CANVAS)],+ }),+ expectToFail: false,+ });++ const tabsAfterFirstSync = await findStandardPersonPageLayoutTabs();++ expect(tabsAfterFirstSync).toHaveLength(1);++ const tabAfterFirstSync = tabsAfterFirstSync[0];++ expect(tabAfterFirstSync).toMatchObject({+ universalIdentifier: TEST_TAB_ID,+ layoutMode: PageLayoutTabLayoutMode.CANVAS,+ });++ const { data: widgetsAfterFirstSyncData } = await findPageLayoutWidgets({+ gqlFields: PAGE_LAYOUT_WIDGET_GQL_FIELDS,+ expectToFail: false,+ input: { pageLayoutTabId: tabAfterFirstSync.id },+ });++ expect(widgetsAfterFirstSyncData.getPageLayoutWidgets).toHaveLength(1);++ const widgetAfterFirstSync =+ widgetsAfterFirstSyncData.getPageLayoutWidgets[0];++ expect(widgetAfterFirstSync).toMatchObject({+ universalIdentifier: TEST_WIDGET_ID,+ applicationId: testApplicationId,+ pageLayoutTabId: tabAfterFirstSync.id,+ title: 'Timeline',+ type: 'TIMELINE',+ configuration: {+ configurationType: 'TIMELINE',+ },+ });++ await syncApplication({+ manifest: buildManifest({+ pageLayoutTabs: [+ buildPageLayoutTab(PageLayoutTabLayoutMode.VERTICAL_LIST),+ ],+ }),+ expectToFail: false,+ });++ const tabsAfterSecondSync = await findStandardPersonPageLayoutTabs();++ expect(tabsAfterSecondSync).toHaveLength(1);++ const tabAfterSecondSync = tabsAfterSecondSync[0];++ expect(tabAfterSecondSync).toMatchObject({+ id: tabAfterFirstSync.id,+ universalIdentifier: TEST_TAB_ID,+ layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,+ });++ const { data: widgetsAfterSecondSyncData } = await findPageLayoutWidgets({+ gqlFields: PAGE_LAYOUT_WIDGET_GQL_FIELDS,+ expectToFail: false,+ input: { pageLayoutTabId: tabAfterSecondSync.id },+ });++ expect(widgetsAfterSecondSyncData.getPageLayoutWidgets).toEqual([+ expect.objectContaining({+ id: widgetAfterFirstSync.id,+ universalIdentifier: TEST_WIDGET_ID,+ applicationId: testApplicationId,+ pageLayoutTabId: tabAfterSecondSync.id,+ title: 'Timeline',+ type: 'TIMELINE',+ configuration: {+ configurationType: 'TIMELINE',+ },+ }),+ ]);+ }, 60000);+it('should delete a standalone tab when removed from manifest on second sync', async () => {await syncApplication({manifest: buildManifest({diff --git a/packages/twenty-shared/src/types/page-layout/PageLayoutTabLayoutMode.ts b/packages/twenty-shared/src/types/page-layout/PageLayoutTabLayoutMode.tsindex 2c4a2e50e75..b9d52e14fc5 100644--- a/packages/twenty-shared/src/types/page-layout/PageLayoutTabLayoutMode.ts+++ b/packages/twenty-shared/src/types/page-layout/PageLayoutTabLayoutMode.ts@@ -1,10 +1,5 @@export enum PageLayoutTabLayoutMode {GRID = 'GRID',VERTICAL_LIST = 'VERTICAL_LIST',- /**- * @deprecated Solo full-page tabs are no longer stored as a layout mode.- * Presentation (solo vs stack) is derived from the tab's widgets. Kept only to- * read layouts persisted before this change; nothing new should write it.- */CANVAS = 'CANVAS',}