Skip to content

The open alternative to Salesforce, designed for AI.

Migrate react-grid-layout to v2 (#24922)

nitin262f63ad6940
diff --git a/packages/twenty-front/package.json b/packages/twenty-front/package.json
index f597b400731..5385555b320 100644
--- a/packages/twenty-front/package.json
+++ b/packages/twenty-front/package.json
@@ -125,7 +125,7 @@
"react-dom": "^19.2.0",
"react-dropzone": "^14.2.3",
"react-error-boundary": "^4.0.11",
- "react-grid-layout": "^1.5.2",
+ "react-grid-layout": "^2.2.4",
"react-hook-form": "^7.45.1",
"react-hotkeys-hook": "^4.4.4",
"react-imask": "^7.6.0",
@@ -179,7 +179,6 @@
"@types/jest": "^30.0.0",
"@types/js-cookie": "^3.0.3",
"@types/json-logic-js": "^2",
- "@types/react-grid-layout": "^1",
"@types/uuid": "^9.0.2",
"@vitejs/plugin-react-swc": "^4.3.1",
"@vitest/coverage-istanbul": "^4.1.0",
diff --git a/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx b/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
index 55148a827cd..f6b6010c07e 100644
--- a/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
+++ b/packages/twenty-front/src/modules/page-layout/components/PageLayoutGridLayout.tsx
@@ -32,13 +32,13 @@ import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/use
import { useSetAtomComponentState } from '@/ui/utilities/state/jotai/hooks/useSetAtomComponentState';
import { css } from '@linaria/core';
import { styled } from '@linaria/react';
-import { useMemo, useRef } from 'react';
+import { useMemo } from 'react';
import {
type Layout,
- type Layouts,
Responsive,
- type ResponsiveProps,
- WidthProvider,
+ type ResponsiveLayouts,
+ useContainerWidth,
+ verticalCompactor,
} from 'react-grid-layout';
import { isDefined } from 'twenty-shared/utils';
import { themeCssVariables } from 'twenty-ui/theme-constants';
@@ -117,15 +117,6 @@ const StyledGridContainer = styled.div`
}
`;
-type ExtendedResponsiveProps = ResponsiveProps & {
- maxCols?: number;
- preventCollision?: boolean;
-};
-
-const ResponsiveGridLayout = WidthProvider(
- Responsive,
-) as React.ComponentType<ExtendedResponsiveProps>;
-
type PageLayoutGridLayoutProps = {
tabId: string;
};
@@ -164,7 +155,11 @@ export const PageLayoutGridLayout = ({ tabId }: PageLayoutGridLayoutProps) => {
tabId,
});
- const gridContainerRef = useRef<HTMLDivElement>(null);
+ const {
+ width,
+ containerRef: gridContainerRef,
+ mounted,
+ } = useContainerWidth();
const isPageLayoutInEditMode = useIsPageLayoutInEditMode();
@@ -189,8 +184,8 @@ export const PageLayoutGridLayout = ({ tabId }: PageLayoutGridLayoutProps) => {
const hasPendingPlaceholder = isDefined(pageLayoutDraggedArea);
const handleLayoutChangeWithoutPendingPlaceholder = (
- currentLayout: Layout[],
- allLayouts: Layouts,
+ currentLayout: Layout,
+ allLayouts: ResponsiveLayouts,
) => {
if (consumeShouldIgnoreNextGridLayoutChange()) {
return;
@@ -237,57 +232,69 @@ export const PageLayoutGridLayout = ({ tabId }: PageLayoutGridLayoutProps) => {
</>
)}
- <ResponsiveGridLayout
- className="layout"
- layouts={layouts}
- breakpoints={PAGE_LAYOUT_CONFIG.breakpoints}
- cols={PAGE_LAYOUT_CONFIG.columns}
- rowHeight={PAGE_LAYOUT_GRID_ROW_HEIGHT}
- maxCols={12}
- containerPadding={[0, 0]}
- margin={[PAGE_LAYOUT_GRID_MARGIN, PAGE_LAYOUT_GRID_MARGIN]}
- isDraggable={isPageLayoutInEditMode && !isLayoutEmpty}
- isResizable={isPageLayoutInEditMode && !isLayoutEmpty}
- draggableHandle=".drag-handle"
- compactType="vertical"
- preventCollision={false}
- resizeHandle={
- isPageLayoutInEditMode && !isLayoutEmpty ? (
- <PageLayoutGridResizeHandle />
- ) : undefined
- }
- resizeHandles={['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw']}
- onDragStart={(_layout, _oldItem, newItem) => {
- setPageLayoutDraggingWidgetId(newItem.i);
- }}
- onDrag={(_layout, _oldItem, _newItem, _placeholder, event) => {
- handleGridDrag(event);
- }}
- onDragStop={(_layout, _oldItem, newItem, _placeholder, event) => {
- handleGridDragStop(newItem.i, event);
- setPageLayoutDraggingWidgetId(null);
- }}
- onResizeStart={(_layout, _oldItem, newItem) => {
- setPageLayoutResizingWidgetId(newItem.i);
- }}
- onResizeStop={() => {
- setPageLayoutResizingWidgetId(null);
- }}
- onLayoutChange={handleLayoutChangeWithoutPendingPlaceholder}
- onBreakpointChange={(newBreakpoint) =>
- setPageLayoutCurrentBreakpoint(newBreakpoint as PageLayoutBreakpoint)
- }
- >
- {gridLayoutItems.map((item) => (
- <ReactGridLayoutCardWrapper key={item.id}>
- {item.type === 'placeholder' ? (
- <WidgetPlaceholder />
- ) : (
- <WidgetRenderer widget={item.widget} />
- )}
- </ReactGridLayoutCardWrapper>
- ))}
- </ResponsiveGridLayout>
+ {mounted && (
+ <Responsive
+ className="layout"
+ width={width}
+ layouts={layouts}
+ breakpoints={PAGE_LAYOUT_CONFIG.breakpoints}
+ cols={PAGE_LAYOUT_CONFIG.columns}
+ rowHeight={PAGE_LAYOUT_GRID_ROW_HEIGHT}
+ containerPadding={[0, 0]}
+ margin={[PAGE_LAYOUT_GRID_MARGIN, PAGE_LAYOUT_GRID_MARGIN]}
+ compactor={verticalCompactor}
+ dragConfig={{
+ enabled: isPageLayoutInEditMode && !isLayoutEmpty,
+ handle: '.drag-handle',
+ }}
+ resizeConfig={{
+ enabled: isPageLayoutInEditMode && !isLayoutEmpty,
+ handles: ['n', 's', 'e', 'w', 'ne', 'nw', 'se', 'sw'],
+ handleComponent:
+ isPageLayoutInEditMode && !isLayoutEmpty ? (
+ <PageLayoutGridResizeHandle />
+ ) : undefined,
+ }}
+ onDragStart={(_layout, _oldItem, newItem) => {
+ if (isDefined(newItem)) {
+ setPageLayoutDraggingWidgetId(newItem.i);
+ }
+ }}
+ onDrag={(_layout, _oldItem, _newItem, _placeholder, event) => {
+ handleGridDrag(event);
+ }}
+ onDragStop={(_layout, _oldItem, newItem, _placeholder, event) => {
+ if (isDefined(newItem)) {
+ handleGridDragStop(newItem.i, event);
+ }
+ setPageLayoutDraggingWidgetId(null);
+ }}
+ onResizeStart={(_layout, _oldItem, newItem) => {
+ if (isDefined(newItem)) {
+ setPageLayoutResizingWidgetId(newItem.i);
+ }
+ }}
+ onResizeStop={() => {
+ setPageLayoutResizingWidgetId(null);
+ }}
+ onLayoutChange={handleLayoutChangeWithoutPendingPlaceholder}
+ onBreakpointChange={(newBreakpoint) =>
+ setPageLayoutCurrentBreakpoint(
+ newBreakpoint as PageLayoutBreakpoint,
+ )
+ }
+ >
+ {gridLayoutItems.map((item) => (
+ <ReactGridLayoutCardWrapper key={item.id}>
+ {item.type === 'placeholder' ? (
+ <WidgetPlaceholder />
+ ) : (
+ <WidgetRenderer widget={item.widget} />
+ )}
+ </ReactGridLayoutCardWrapper>
+ ))}
+ </Responsive>
+ )}
</StyledGridContainer>
);
};
diff --git a/packages/twenty-front/src/modules/page-layout/constants/EmptyLayout.ts b/packages/twenty-front/src/modules/page-layout/constants/EmptyLayout.ts
index 4116515f53c..e7ea96ae7dd 100644
--- a/packages/twenty-front/src/modules/page-layout/constants/EmptyLayout.ts
+++ b/packages/twenty-front/src/modules/page-layout/constants/EmptyLayout.ts
@@ -1,6 +1,6 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
-export const EMPTY_LAYOUT: Layouts = {
+export const EMPTY_LAYOUT: ResponsiveLayouts = {
desktop: [{ i: 'empty-placeholder', x: 0, y: 0, w: 4, h: 4, static: true }],
mobile: [{ i: 'empty-placeholder', x: 0, y: 0, w: 1, h: 4, static: true }],
};
diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutTab.ts b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutTab.ts
index f047e9cdef7..809f273aa48 100644
--- a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutTab.ts
+++ b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutTab.ts
@@ -135,17 +135,14 @@ export const useDuplicatePageLayoutTab = ({
...generateDuplicatedTimestamps(),
};
- const sourceLayouts = allTabLayouts[tabId] ?? {
- desktop: [],
- mobile: [],
- };
+ const sourceLayouts = allTabLayouts[tabId];
const newLayouts = {
- desktop: sourceLayouts.desktop.map((layout) => ({
+ desktop: (sourceLayouts?.desktop ?? []).map((layout) => ({
...layout,
i: widgetOldIdNewIdMap.get(layout.i) || layout.i,
})),
- mobile: sourceLayouts.mobile.map((layout) => ({
+ mobile: (sourceLayouts?.mobile ?? []).map((layout) => ({
...layout,
i: widgetOldIdNewIdMap.get(layout.i) || layout.i,
})),
diff --git a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts
index 847768b583f..f8c8da86e9a 100644
--- a/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts
+++ b/packages/twenty-front/src/modules/page-layout/hooks/useDuplicatePageLayoutWidget.ts
@@ -95,12 +95,10 @@ export const useDuplicatePageLayoutWidget = (
...generateDuplicatedTimestamps(),
};
- const currentTabLayouts = allTabLayouts[sourceTab.id] ?? {
- desktop: [],
- mobile: [],
- };
+ const currentTabDesktopLayouts =
+ allTabLayouts[sourceTab.id]?.desktop ?? [];
- const sourceLayout = currentTabLayouts.desktop.find(
+ const sourceLayout = currentTabDesktopLayouts.find(
(layout) => layout.i === widgetId,
);
@@ -108,7 +106,7 @@ export const useDuplicatePageLayoutWidget = (
throw new Error(`Layout for widget ${widgetId} not found`);
}
- const maxY = currentTabLayouts.desktop.reduce(
+ const maxY = currentTabDesktopLayouts.reduce(
(max, layout) => Math.max(max, layout.y + layout.h),
0,
);
diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutGridCrossTabDrop.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutGridCrossTabDrop.ts
index 0777f795d47..97a165cfc84 100644
--- a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutGridCrossTabDrop.ts
+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutGridCrossTabDrop.ts
@@ -10,6 +10,7 @@ import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDr
import { pageLayoutGridDragHoveredTabIdComponentState } from '@/page-layout/states/pageLayoutGridDragHoveredTabIdComponentState';
import { pageLayoutShouldIgnoreNextGridLayoutChangeComponentState } from '@/page-layout/states/pageLayoutShouldIgnoreNextGridLayoutChangeComponentState';
import { buildTabWidgetLayouts } from '@/page-layout/utils/buildTabWidgetLayouts';
+import { getPointerEventClientPosition } from '@/page-layout/utils/getPointerEventClientPosition';
import { moveWidgetToGridTabInDraft } from '@/page-layout/utils/moveWidgetToGridTabInDraft';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';
@@ -95,11 +96,15 @@ export const usePageLayoutGridCrossTabDrop = ({ tabId }: { tabId: string }) => {
);
const handleGridDrag = useCallback(
- (event: MouseEvent) => {
- const destinationTabId = findGridDropDestinationTabId(
- event.clientX,
- event.clientY,
- );
+ (event: Event) => {
+ const pointerPosition = getPointerEventClientPosition(event);
+
+ const destinationTabId = isDefined(pointerPosition)
+ ? findGridDropDestinationTabId(
+ pointerPosition.clientX,
+ pointerPosition.clientY,
+ )
+ : null;
if (store.get(gridDragHoveredTabIdState) !== destinationTabId) {
store.set(gridDragHoveredTabIdState, destinationTabId);
@@ -109,12 +114,18 @@ export const usePageLayoutGridCrossTabDrop = ({ tabId }: { tabId: string }) => {
);
const handleGridDragStop = useCallback(
- (widgetId: string, event: MouseEvent): boolean => {
+ (widgetId: string, event: Event): boolean => {
store.set(gridDragHoveredTabIdState, null);
+ const pointerPosition = getPointerEventClientPosition(event);
+
+ if (!isDefined(pointerPosition)) {
+ return false;
+ }
+
const destinationTabId = findGridDropDestinationTabId(
- event.clientX,
- event.clientY,
+ pointerPosition.clientX,
+ pointerPosition.clientY,
);
if (!isDefined(destinationTabId)) {
diff --git a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutHandleLayoutChange.ts b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutHandleLayoutChange.ts
index 2c992127635..35a3c759ded 100644
--- a/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutHandleLayoutChange.ts
+++ b/packages/twenty-front/src/modules/page-layout/hooks/usePageLayoutHandleLayoutChange.ts
@@ -7,7 +7,7 @@ import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/com
import { useAtomComponentStateCallbackState } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateCallbackState';
import { useStore } from 'jotai';
import { useCallback } from 'react';
-import { type Layout, type Layouts } from 'react-grid-layout';
+import { type Layout, type ResponsiveLayouts } from 'react-grid-layout';
import { isDefined } from 'twenty-shared/utils';
export const usePageLayoutHandleLayoutChange = ({
@@ -35,7 +35,7 @@ export const usePageLayoutHandleLayoutChange = ({
);
const handleLayoutChange = useCallback(
- (_: Layout[], allLayouts: Layouts) => {
+ (_: Layout, allLayouts: ResponsiveLayouts) => {
const activeTabId = store.get(
activeTabIdComponentState.atomFamily({
instanceId: tabListInstanceId,
diff --git a/packages/twenty-front/src/modules/page-layout/types/TabLayouts.ts b/packages/twenty-front/src/modules/page-layout/types/TabLayouts.ts
index fc8c947fa20..10af080859a 100644
--- a/packages/twenty-front/src/modules/page-layout/types/TabLayouts.ts
+++ b/packages/twenty-front/src/modules/page-layout/types/TabLayouts.ts
@@ -1,3 +1,3 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
-export type TabLayouts = Record<string, Layouts>;
+export type TabLayouts = Record<string, ResponsiveLayouts>;
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/convertPageLayoutToTabLayouts.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/convertPageLayoutToTabLayouts.test.ts
index d97fb60123d..f901ab5438e 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/convertPageLayoutToTabLayouts.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/convertPageLayoutToTabLayouts.test.ts
@@ -182,7 +182,7 @@ describe('convertPageLayoutToTabLayouts', () => {
const result = convertPageLayoutToTabLayouts(pageLayout);
- expect(result['tab-1'].desktop[0]).toMatchObject({
+ expect(result['tab-1'].desktop![0]).toMatchObject({
i: 'widget-no-grid-pos',
x: 0,
y: 0,
@@ -254,7 +254,7 @@ describe('convertPageLayoutToTabLayouts', () => {
const richTextMinSize =
WIDGET_SIZES[WidgetType.STANDALONE_RICH_TEXT]!.minimum;
- expect(result['tab-1'].desktop[0]).toMatchObject({
+ expect(result['tab-1'].desktop![0]).toMatchObject({
i: 'rich-text-widget',
minW: richTextMinSize.w,
minH: richTextMinSize.h,
@@ -323,7 +323,7 @@ describe('convertPageLayoutToTabLayouts', () => {
const result = convertPageLayoutToTabLayouts(pageLayout);
const iframeMinSize = WIDGET_SIZES[WidgetType.IFRAME]!.minimum;
- expect(result['tab-1'].desktop[0]).toMatchObject({
+ expect(result['tab-1'].desktop![0]).toMatchObject({
i: 'iframe-widget',
minW: iframeMinSize.w,
minH: iframeMinSize.h,
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/filterPendingPlaceholderFromLayouts.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/filterPendingPlaceholderFromLayouts.test.ts
index 8c3afa61f8a..345eb42d62f 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/filterPendingPlaceholderFromLayouts.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/filterPendingPlaceholderFromLayouts.test.ts
@@ -1,10 +1,10 @@
import { PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY } from '@/page-layout/constants/PendingWidgetPlaceholderLayoutKey';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { filterPendingPlaceholderFromLayouts } from '@/page-layout/utils/filterPendingPlaceholderFromLayouts';
describe('filterPendingPlaceholderFromLayouts', () => {
it('should remove pending placeholder from both desktop and mobile layouts', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 4 },
{ i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY, x: 4, y: 0, w: 4, h: 4 },
@@ -33,7 +33,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
});
it('should handle layouts with no pending placeholder', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 4 },
{ i: 'widget-2', x: 4, y: 0, w: 4, h: 4 },
@@ -58,7 +58,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
{ i: 'widget-1', x: 0, y: 0, w: 1, h: 4 },
{ i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY, x: 0, y: 4, w: 1, h: 4 },
],
- } as Layouts;
+ } as ResponsiveLayouts;
const result1 = filterPendingPlaceholderFromLayouts(layoutsWithoutDesktop);
@@ -71,7 +71,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 4 },
{ i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY, x: 4, y: 0, w: 4, h: 4 },
],
- } as Layouts;
+ } as ResponsiveLayouts;
const result2 = filterPendingPlaceholderFromLayouts(layoutsWithoutMobile);
@@ -83,7 +83,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
});
it('should handle empty layouts', () => {
- const emptyLayouts: Layouts = {
+ const emptyLayouts: ResponsiveLayouts = {
desktop: [],
mobile: [],
};
@@ -95,7 +95,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
});
it('should handle layouts with only pending placeholder', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY, x: 0, y: 0, w: 4, h: 4 },
],
@@ -111,7 +111,7 @@ describe('filterPendingPlaceholderFromLayouts', () => {
});
it('should not mutate the original layouts', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 4 },
{ i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY, x: 4, y: 0, w: 4, h: 4 },
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/getPointerEventClientPosition.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getPointerEventClientPosition.test.ts
new file mode 100644
index 00000000000..38dcd9a27b5
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getPointerEventClientPosition.test.ts
@@ -0,0 +1,33 @@
+import { getPointerEventClientPosition } from '@/page-layout/utils/getPointerEventClientPosition';
+
+describe('getPointerEventClientPosition', () => {
+ it('should extract coordinates from a mouse event', () => {
+ const event = new MouseEvent('mouseup', { clientX: 120, clientY: 240 });
+
+ expect(getPointerEventClientPosition(event)).toEqual({
+ clientX: 120,
+ clientY: 240,
+ });
+ });
+
+ it('should extract coordinates from a touch event ending touch', () => {
+ const event = Object.assign(new Event('touchend'), {
+ changedTouches: [{ clientX: 60, clientY: 80 }],
+ });
+
+ expect(getPointerEventClientPosition(event)).toEqual({
+ clientX: 60,
+ clientY: 80,
+ });
+ });
+
+ it('should return null for a touch event without touches', () => {
+ const event = Object.assign(new Event('touchend'), { changedTouches: [] });
+
+ expect(getPointerEventClientPosition(event)).toBeNull();
+ });
+
+ it('should return null for an event without pointer coordinates', () => {
+ expect(getPointerEventClientPosition(new Event('scroll'))).toBeNull();
+ });
+});
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/getUpdatedTabLayouts.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getUpdatedTabLayouts.test.ts
index 7900253e5cd..e6328e353df 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/getUpdatedTabLayouts.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/getUpdatedTabLayouts.test.ts
@@ -19,18 +19,18 @@ describe('getUpdatedTabLayouts', () => {
const result = getUpdatedTabLayouts(mockTabLayouts, 'tab-1', newLayout);
expect(result['tab-1'].desktop).toHaveLength(2);
- expect(result['tab-1'].desktop[1]).toEqual(newLayout);
+ expect(result['tab-1'].desktop![1]).toEqual(newLayout);
expect(result['tab-1'].mobile).toHaveLength(2);
- expect(result['tab-1'].mobile[1]).toEqual({ ...newLayout, w: 1, x: 0 });
+ expect(result['tab-1'].mobile![1]).toEqual({ ...newLayout, w: 1, x: 0 });
});
it('should add layout to empty tab', () => {
const result = getUpdatedTabLayouts(mockTabLayouts, 'tab-2', newLayout);
expect(result['tab-2'].desktop).toHaveLength(1);
- expect(result['tab-2'].desktop[0]).toEqual(newLayout);
+ expect(result['tab-2'].desktop![0]).toEqual(newLayout);
expect(result['tab-2'].mobile).toHaveLength(1);
- expect(result['tab-2'].mobile[0]).toEqual({ ...newLayout, w: 1, x: 0 });
+ expect(result['tab-2'].mobile![0]).toEqual({ ...newLayout, w: 1, x: 0 });
});
it('should create new tab entry if tab does not exist', () => {
@@ -38,7 +38,7 @@ describe('getUpdatedTabLayouts', () => {
expect(result['tab-3']).toBeDefined();
expect(result['tab-3'].desktop).toHaveLength(1);
- expect(result['tab-3'].desktop[0]).toEqual(newLayout);
+ expect(result['tab-3'].desktop![0]).toEqual(newLayout);
expect(result['tab-3'].mobile).toHaveLength(1);
});
@@ -53,7 +53,7 @@ describe('getUpdatedTabLayouts', () => {
const result = getUpdatedTabLayouts(mockTabLayouts, 'tab-1', wideLayout);
const mobileLayout =
- result['tab-1'].mobile[result['tab-1'].mobile.length - 1];
+ result['tab-1'].mobile![result['tab-1'].mobile!.length - 1];
expect(mobileLayout.w).toBe(1);
expect(mobileLayout.x).toBe(0);
expect(mobileLayout.y).toBe(wideLayout.y);
@@ -70,13 +70,18 @@ describe('getUpdatedTabLayouts', () => {
expect(mockTabLayouts['tab-1'].desktop).toHaveLength(1);
});
- it('should throw an error for malformed tab layouts', () => {
- const malformedLayouts: TabLayouts = {
- 'tab-1': {} as any,
+ it('should treat missing breakpoint layouts as empty', () => {
+ const layoutsWithMissingBreakpoints: TabLayouts = {
+ 'tab-1': {},
};
- expect(() => {
- getUpdatedTabLayouts(malformedLayouts, 'tab-1', newLayout);
- }).toThrow();
+ const result = getUpdatedTabLayouts(
+ layoutsWithMissingBreakpoints,
+ 'tab-1',
+ newLayout,
+ );
+
+ expect(result['tab-1'].desktop).toEqual([newLayout]);
+ expect(result['tab-1'].mobile).toEqual([{ ...newLayout, w: 1, x: 0 }]);
});
});
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/removeWidgetLayoutFromTab.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/removeWidgetLayoutFromTab.test.ts
index fbd473b3dfc..0899e9eaf3d 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/removeWidgetLayoutFromTab.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/removeWidgetLayoutFromTab.test.ts
@@ -29,12 +29,12 @@ describe('removeWidgetLayoutFromTab', () => {
);
expect(result['tab-1'].desktop).toHaveLength(2);
- expect(result['tab-1'].desktop.map((l) => l.i)).toEqual([
+ expect(result['tab-1'].desktop!.map((l) => l.i)).toEqual([
'widget-1',
'widget-3',
]);
expect(result['tab-1'].mobile).toHaveLength(2);
- expect(result['tab-1'].mobile.map((l) => l.i)).toEqual([
+ expect(result['tab-1'].mobile!.map((l) => l.i)).toEqual([
'widget-1',
'widget-3',
]);
@@ -116,8 +116,8 @@ describe('removeWidgetLayoutFromTab', () => {
'widget-2',
);
- const desktopIds = result['tab-1'].desktop.map((l) => l.i);
- const mobileIds = result['tab-1'].mobile.map((l) => l.i);
+ const desktopIds = result['tab-1'].desktop!.map((l) => l.i);
+ const mobileIds = result['tab-1'].mobile!.map((l) => l.i);
expect(desktopIds).not.toContain('widget-2');
expect(mobileIds).not.toContain('widget-2');
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateLayoutItemConstraints.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateLayoutItemConstraints.test.ts
index 20f1bd0a100..bb5c2acf67f 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateLayoutItemConstraints.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateLayoutItemConstraints.test.ts
@@ -1,9 +1,9 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { updateLayoutItemConstraints } from '@/page-layout/utils/updateLayoutItemConstraints';
describe('updateLayoutItemConstraints', () => {
it('should update constraints for the specified layout item in desktop layout', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
{ i: 'widget-2', x: 4, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
@@ -36,7 +36,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should update constraints for the specified layout item in mobile layout', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
mobile: [
{ i: 'widget-1', x: 0, y: 0, w: 2, h: 2, minW: 1, minH: 1 },
{ i: 'widget-2', x: 0, y: 2, w: 2, h: 2, minW: 1, minH: 1 },
@@ -69,7 +69,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should update constraints in both desktop and mobile layouts when item exists in both', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
{ i: 'widget-2', x: 4, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
@@ -92,7 +92,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should not modify layouts when layout item does not exist', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 }],
mobile: [{ i: 'widget-1', x: 0, y: 0, w: 2, h: 2, minW: 1, minH: 1 }],
};
@@ -107,7 +107,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should handle undefined desktop layout', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
mobile: [{ i: 'widget-1', x: 0, y: 0, w: 2, h: 2, minW: 1, minH: 1 }],
};
@@ -122,7 +122,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should handle undefined mobile layout', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 }],
};
@@ -137,7 +137,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should handle empty layouts object', () => {
- const layouts: Layouts = {};
+ const layouts: ResponsiveLayouts = {};
const result = updateLayoutItemConstraints(layouts, 'widget-1', {
minW: 3,
@@ -148,7 +148,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should preserve other properties of layout items', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{
i: 'widget-1',
@@ -183,7 +183,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should handle layouts with multiple widgets and only update the target', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
{ i: 'widget-2', x: 4, y: 0, w: 4, h: 3, minW: 2, minH: 2 },
@@ -205,7 +205,7 @@ describe('updateLayoutItemConstraints', () => {
});
it('should handle constraints with zero values', () => {
- const layouts: Layouts = {
+ const layouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 2, minH: 2 }],
};
diff --git a/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateWidgetMinimumSizeForGraphType.test.ts b/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateWidgetMinimumSizeForGraphType.test.ts
index 8a1868373eb..a861012f8ca 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateWidgetMinimumSizeForGraphType.test.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/__tests__/updateWidgetMinimumSizeForGraphType.test.ts
@@ -1,7 +1,7 @@
import { getWidgetSize } from '@/page-layout/utils/getWidgetSize';
import { updateLayoutItemConstraints } from '@/page-layout/utils/updateLayoutItemConstraints';
import { updateWidgetMinimumSizeForGraphType } from '@/page-layout/utils/updateWidgetMinimumSizeForGraphType';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { WidgetConfigurationType } from '~/generated-metadata/graphql';
jest.mock('../getWidgetSize');
@@ -13,7 +13,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should update widget minimum size for a valid graph type and existing tab', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
@@ -22,7 +22,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
},
};
- const updatedLayouts: Layouts = {
+ const updatedLayouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 3, minH: 2 }],
};
@@ -52,7 +52,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should return original layouts when tab does not exist', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
@@ -75,7 +75,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should handle different graph types correctly', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
@@ -123,7 +123,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should preserve other tabs when updating a specific tab', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
@@ -135,7 +135,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
},
};
- const updatedTab2Layouts: Layouts = {
+ const updatedTab2Layouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-2', x: 0, y: 0, w: 5, h: 4, minW: 4, minH: 3 }],
};
@@ -159,7 +159,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should handle empty layouts object', () => {
- const mockLayouts: Record<string, Layouts> = {};
+ const mockLayouts: Record<string, ResponsiveLayouts> = {};
(getWidgetSize as jest.Mock).mockReturnValue({ w: 3, h: 2 });
@@ -175,14 +175,14 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should handle layouts with both desktop and mobile', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
mobile: [{ i: 'widget-1', x: 0, y: 0, w: 2, h: 2 }],
},
};
- const updatedLayouts: Layouts = {
+ const updatedLayouts: ResponsiveLayouts = {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3, minW: 3, minH: 2 }],
mobile: [{ i: 'widget-1', x: 0, y: 0, w: 2, h: 2, minW: 3, minH: 2 }],
};
@@ -201,7 +201,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should handle widget not found in tab layouts', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
@@ -230,7 +230,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should call updateLayoutItemConstraints with correct parameters', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [
{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 },
@@ -262,7 +262,7 @@ describe('updateWidgetMinimumSizeForGraphType', () => {
});
it('should handle undefined tab layouts gracefully', () => {
- const mockLayouts: Record<string, Layouts> = {
+ const mockLayouts: Record<string, ResponsiveLayouts> = {
'tab-1': {
desktop: [{ i: 'widget-1', x: 0, y: 0, w: 4, h: 3 }],
},
diff --git a/packages/twenty-front/src/modules/page-layout/utils/addPendingPlaceholderToLayouts.ts b/packages/twenty-front/src/modules/page-layout/utils/addPendingPlaceholderToLayouts.ts
index 54d6651d078..1626685e7ab 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/addPendingPlaceholderToLayouts.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/addPendingPlaceholderToLayouts.ts
@@ -1,10 +1,10 @@
import { createPendingWidgetPlaceholderLayoutItem } from '@/page-layout/utils/createPendingWidgetPlaceholderLayoutItem';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
export const addPendingPlaceholderToLayouts = (
- baseLayouts: Layouts,
+ baseLayouts: ResponsiveLayouts,
draggedArea: { x: number; y: number; w: number; h: number },
-): Layouts => ({
+): ResponsiveLayouts => ({
desktop: [
...(baseLayouts.desktop ?? []),
createPendingWidgetPlaceholderLayoutItem(draggedArea, 'desktop'),
diff --git a/packages/twenty-front/src/modules/page-layout/utils/buildTabWidgetLayouts.ts b/packages/twenty-front/src/modules/page-layout/utils/buildTabWidgetLayouts.ts
index 7d0cabfaa40..337b80e9ae0 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/buildTabWidgetLayouts.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/buildTabWidgetLayouts.ts
@@ -1,4 +1,4 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { DEFAULT_WIDGET_SIZE } from 'twenty-shared/constants';
import { isDefined } from 'twenty-shared/utils';
@@ -24,7 +24,9 @@ const getWidgetMinimumSize = (widget: PageLayoutWidget) => {
return DEFAULT_WIDGET_SIZE.minimum;
};
-export const buildTabWidgetLayouts = (widgets: PageLayoutWidget[]): Layouts => {
+export const buildTabWidgetLayouts = (
+ widgets: PageLayoutWidget[],
+): ResponsiveLayouts => {
const layouts = widgets.map((widget) => {
const minimumSize = getWidgetMinimumSize(widget);
const gridPos = getWidgetGridPosition(widget);
diff --git a/packages/twenty-front/src/modules/page-layout/utils/calculateTotalGridRows.ts b/packages/twenty-front/src/modules/page-layout/utils/calculateTotalGridRows.ts
index 682b3be5bf5..7d80b622eb4 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/calculateTotalGridRows.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/calculateTotalGridRows.ts
@@ -1,9 +1,9 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { GRID_BUFFER_ROWS } from '@/page-layout/constants/GridBufferRows';
import { GRID_MIN_ROWS } from '@/page-layout/constants/GridMinRows';
export const calculateTotalGridRows = (
- layouts: Layouts,
+ layouts: ResponsiveLayouts,
minRows = GRID_MIN_ROWS,
bufferRows = GRID_BUFFER_ROWS,
): number => {
diff --git a/packages/twenty-front/src/modules/page-layout/utils/convertLayoutsToWidgets.ts b/packages/twenty-front/src/modules/page-layout/utils/convertLayoutsToWidgets.ts
index eb1a03a8777..a6214a6b3ef 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/convertLayoutsToWidgets.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/convertLayoutsToWidgets.ts
@@ -1,10 +1,10 @@
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { PageLayoutTabLayoutMode } from '~/generated-metadata/graphql';
export const convertLayoutsToWidgets = (
widgets: PageLayoutWidget[],
- layouts: Layouts,
+ layouts: ResponsiveLayouts,
): PageLayoutWidget[] => {
const activeLayouts = layouts.desktop ?? layouts.mobile ?? [];
diff --git a/packages/twenty-front/src/modules/page-layout/utils/createPendingWidgetPlaceholderLayoutItem.ts b/packages/twenty-front/src/modules/page-layout/utils/createPendingWidgetPlaceholderLayoutItem.ts
index 88522ac977e..7aa742ffc3f 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/createPendingWidgetPlaceholderLayoutItem.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/createPendingWidgetPlaceholderLayoutItem.ts
@@ -1,11 +1,11 @@
import { DEFAULT_WIDGET_SIZE } from 'twenty-shared/constants';
import { PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY } from '@/page-layout/constants/PendingWidgetPlaceholderLayoutKey';
-import { type Layout } from 'react-grid-layout';
+import { type LayoutItem } from 'react-grid-layout';
export const createPendingWidgetPlaceholderLayoutItem = (
draggedArea: { x: number; y: number; w: number; h: number },
breakpoint: 'desktop' | 'mobile',
-): Layout => ({
+): LayoutItem => ({
i: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY,
x: breakpoint === 'mobile' ? 0 : draggedArea.x,
y: draggedArea.y,
diff --git a/packages/twenty-front/src/modules/page-layout/utils/filterPendingPlaceholderFromLayouts.ts b/packages/twenty-front/src/modules/page-layout/utils/filterPendingPlaceholderFromLayouts.ts
index 25f5e1db0e2..5ab04a037ea 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/filterPendingPlaceholderFromLayouts.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/filterPendingPlaceholderFromLayouts.ts
@@ -1,9 +1,9 @@
import { PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY } from '@/page-layout/constants/PendingWidgetPlaceholderLayoutKey';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
export const filterPendingPlaceholderFromLayouts = (
- layouts: Layouts,
-): Layouts => ({
+ layouts: ResponsiveLayouts,
+): ResponsiveLayouts => ({
desktop: layouts.desktop?.filter(
(layoutItem) => layoutItem.i !== PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY,
),
diff --git a/packages/twenty-front/src/modules/page-layout/utils/getPointerEventClientPosition.ts b/packages/twenty-front/src/modules/page-layout/utils/getPointerEventClientPosition.ts
new file mode 100644
index 00000000000..b409158dbbd
--- /dev/null
+++ b/packages/twenty-front/src/modules/page-layout/utils/getPointerEventClientPosition.ts
@@ -0,0 +1,19 @@
+import { isDefined } from 'twenty-shared/utils';
+
+// react-grid-layout v2 types drag events as plain Event; at runtime they are
+// the native MouseEvent or TouchEvent coming from react-draggable.
+export const getPointerEventClientPosition = (
+ event: Event,
+): { clientX: number; clientY: number } | null => {
+ if (event instanceof MouseEvent) {
+ return { clientX: event.clientX, clientY: event.clientY };
+ }
+
+ const touch = (event as Partial<TouchEvent>).changedTouches?.[0];
+
+ if (isDefined(touch)) {
+ return { clientX: touch.clientX, clientY: touch.clientY };
+ }
+
+ return null;
+};
diff --git a/packages/twenty-front/src/modules/page-layout/utils/getUpdatedTabLayouts.ts b/packages/twenty-front/src/modules/page-layout/utils/getUpdatedTabLayouts.ts
index 99d19c51c6e..bfddef15ee0 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/getUpdatedTabLayouts.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/getUpdatedTabLayouts.ts
@@ -5,16 +5,16 @@ export const getUpdatedTabLayouts = (
activeTabId: string,
newLayout: { i: string; x: number; y: number; w: number; h: number },
): TabLayouts => {
- const currentTabLayouts = allTabLayouts[activeTabId] ?? {
- desktop: [],
- mobile: [],
- };
+ const currentTabLayouts = allTabLayouts[activeTabId];
return {
...allTabLayouts,
[activeTabId]: {
- desktop: [...currentTabLayouts.desktop, newLayout],
- mobile: [...currentTabLayouts.mobile, { ...newLayout, w: 1, x: 0 }],
+ desktop: [...(currentTabLayouts?.desktop ?? []), newLayout],
+ mobile: [
+ ...(currentTabLayouts?.mobile ?? []),
+ { ...newLayout, w: 1, x: 0 },
+ ],
},
};
};
diff --git a/packages/twenty-front/src/modules/page-layout/utils/removeWidgetLayoutFromTab.ts b/packages/twenty-front/src/modules/page-layout/utils/removeWidgetLayoutFromTab.ts
index 2b80c98171c..3c1c294603c 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/removeWidgetLayoutFromTab.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/removeWidgetLayoutFromTab.ts
@@ -6,18 +6,19 @@ export const removeWidgetLayoutFromTab = (
tabId: string,
widgetId: string,
): TabLayouts => {
- if (!isDefined(allTabLayouts[tabId])) {
+ const currentTabLayouts = allTabLayouts[tabId];
+
+ if (!isDefined(currentTabLayouts)) {
return allTabLayouts;
}
- const currentTabLayouts = allTabLayouts[tabId];
return {
...allTabLayouts,
[tabId]: {
- desktop: currentTabLayouts.desktop.filter(
+ desktop: (currentTabLayouts.desktop ?? []).filter(
(layout) => layout.i !== widgetId,
),
- mobile: currentTabLayouts.mobile.filter(
+ mobile: (currentTabLayouts.mobile ?? []).filter(
(layout) => layout.i !== widgetId,
),
},
diff --git a/packages/twenty-front/src/modules/page-layout/utils/updateLayoutItemConstraints.ts b/packages/twenty-front/src/modules/page-layout/utils/updateLayoutItemConstraints.ts
index ea704b3dd12..b2106210d8a 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/updateLayoutItemConstraints.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/updateLayoutItemConstraints.ts
@@ -1,10 +1,10 @@
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
export const updateLayoutItemConstraints = (
- layouts: Layouts,
+ layouts: ResponsiveLayouts,
layoutItemId: string,
constraints: { minW: number; minH: number },
-): Layouts => ({
+): ResponsiveLayouts => ({
desktop: layouts.desktop?.map((layoutItem) =>
layoutItem.i === layoutItemId
? {
diff --git a/packages/twenty-front/src/modules/page-layout/utils/updateWidgetMinimumSizeForGraphType.ts b/packages/twenty-front/src/modules/page-layout/utils/updateWidgetMinimumSizeForGraphType.ts
index 260ad9da551..caae06e5bc3 100644
--- a/packages/twenty-front/src/modules/page-layout/utils/updateWidgetMinimumSizeForGraphType.ts
+++ b/packages/twenty-front/src/modules/page-layout/utils/updateWidgetMinimumSizeForGraphType.ts
@@ -1,6 +1,6 @@
import { getWidgetSize } from '@/page-layout/utils/getWidgetSize';
import { updateLayoutItemConstraints } from '@/page-layout/utils/updateLayoutItemConstraints';
-import { type Layouts } from 'react-grid-layout';
+import { type ResponsiveLayouts } from 'react-grid-layout';
import { isDefined } from 'twenty-shared/utils';
import { type WidgetConfigurationType } from '~/generated-metadata/graphql';
@@ -13,8 +13,8 @@ export const updateWidgetMinimumSizeForGraphType = ({
configurationType: WidgetConfigurationType;
widgetId: string;
tabId: string;
- currentLayouts: Record<string, Layouts>;
-}): Record<string, Layouts> => {
+ currentLayouts: Record<string, ResponsiveLayouts>;
+}): Record<string, ResponsiveLayouts> => {
const minimumSize = getWidgetSize(configurationType, 'minimum');
const currentTabLayouts = currentLayouts[tabId];
diff --git a/yarn.lock b/yarn.lock
index 4d1f1521c7b..c878e86612c 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -21107,15 +21107,6 @@ __metadata:
languageName: node
linkType: hard
-"@types/react-grid-layout@npm:^1":
- version: 1.3.5
- resolution: "@types/react-grid-layout@npm:1.3.5"
- dependencies:
- "@types/react": "npm:*"
- checksum: 10c0/abd2a1dda9625c753ff2571a10b69740b2fb9ed1d3141755d54d5814cc12a9701c7c5cd78e8797e945486b441303b82543be71043a32d6a988b57a14237f93c6
- languageName: node
- linkType: hard
-
"@types/react-transition-group@npm:^4.4.12":
version: 4.4.12
resolution: "@types/react-transition-group@npm:4.4.12"
@@ -21125,7 +21116,7 @@ __metadata:
languageName: node
linkType: hard
-"@types/react@npm:*, @types/react@npm:^19":
+"@types/react@npm:^19":
version: 19.1.0
resolution: "@types/react@npm:19.1.0"
dependencies:
@@ -43803,7 +43794,7 @@ __metadata:
languageName: node
linkType: hard
-"react-draggable@npm:^4.0.3, react-draggable@npm:^4.4.6":
+"react-draggable@npm:^4.4.6":
version: 4.5.0
resolution: "react-draggable@npm:4.5.0"
dependencies:
@@ -43816,6 +43807,19 @@ __metadata:
languageName: node
linkType: hard
+"react-draggable@npm:^4.5.0":
+ version: 4.7.1
+ resolution: "react-draggable@npm:4.7.1"
+ dependencies:
+ clsx: "npm:^2.1.1"
+ prop-types: "npm:^15.8.1"
+ peerDependencies:
+ react: ">= 16.3.0"
+ react-dom: ">= 16.3.0"
+ checksum: 10c0/1ab282a51794bb62b09b2b781805adfc9b86f2b92266b23b28de03a45c54d38d99d522395e0b592430451def488c54313880a036367818344bd087592f2a9a32
+ languageName: node
+ linkType: hard
+
"react-dropzone@npm:^14.2.3":
version: 14.4.1
resolution: "react-dropzone@npm:14.4.1"
@@ -43875,20 +43879,20 @@ __metadata:
languageName: node
linkType: hard
-"react-grid-layout@npm:^1.5.2":
- version: 1.5.2
- resolution: "react-grid-layout@npm:1.5.2"
+"react-grid-layout@npm:^2.2.4":
+ version: 2.2.4
+ resolution: "react-grid-layout@npm:2.2.4"
dependencies:
clsx: "npm:^2.1.1"
fast-equals: "npm:^4.0.3"
prop-types: "npm:^15.8.1"
react-draggable: "npm:^4.4.6"
- react-resizable: "npm:^3.0.5"
+ react-resizable: "npm:^3.1.3"
resize-observer-polyfill: "npm:^1.5.1"
peerDependencies:
react: ">= 16.3.0"
react-dom: ">= 16.3.0"
- checksum: 10c0/b6605d1435fe116c3720d168100a5a08da924c6905686fe8a486c33b82abbde8ccacbb59e5c6243fa52f5e808ad393a7bdf0c09a3446ebf76efe43f29d9f13ee
+ checksum: 10c0/cde80a1fa5aaa40ac5b42a0c99c7bb07436e14c5e076b11c6a66810665ff9e23c78cc5583e2edcabec57629801af976bf34c3345a25b85662aea470eca40813b
languageName: node
linkType: hard
@@ -44166,15 +44170,16 @@ __metadata:
languageName: node
linkType: hard
-"react-resizable@npm:^3.0.5":
- version: 3.0.5
- resolution: "react-resizable@npm:3.0.5"
+"react-resizable@npm:^3.1.3":
+ version: 3.2.0
+ resolution: "react-resizable@npm:3.2.0"
dependencies:
prop-types: "npm:15.x"
- react-draggable: "npm:^4.0.3"
+ react-draggable: "npm:^4.5.0"
peerDependencies:
react: ">= 16.3"
- checksum: 10c0/cfe50aa6efb79e0aa09bd681a5beab2fcd1186737c4952eb4c3974ed9395d5d263ccd1130961d06b8f5e24c8f544dd2967b5c740ce68719962d1771de7bdb350
+ react-dom: ">= 16.3"
+ checksum: 10c0/b589bca0b1135dc4bf875f09dd677821bfe4b468e5c9ec7e37d91a06ca49281f3dec289d5aa41a7cc0f4603872610b0c5d1d077287c3fef73a5c9339d3216598
languageName: node
linkType: hard
@@ -49581,7 +49586,6 @@ __metadata:
"@types/js-cookie": "npm:^3.0.3"
"@types/json-logic-js": "npm:^2"
"@types/marked": "npm:^6.0.0"
- "@types/react-grid-layout": "npm:^1"
"@types/uuid": "npm:^9.0.2"
"@vitejs/plugin-react-swc": "npm:^4.3.1"
"@vitest/coverage-istanbul": "npm:^4.1.0"
@@ -49646,7 +49650,7 @@ __metadata:
react-dom: "npm:^19.2.0"
react-dropzone: "npm:^14.2.3"
react-error-boundary: "npm:^4.0.11"
- react-grid-layout: "npm:^1.5.2"
+ react-grid-layout: "npm:^2.2.4"
react-hook-form: "npm:^7.45.1"
react-hotkeys-hook: "npm:^4.4.4"
react-imask: "npm:^7.6.0"