Files
twenty/packages/twenty-front/src/modules/page-layout/utils/convertPageLayoutToTabLayouts.ts
T
nitin 5bc876e4b4 IFrame widget improvements (#15483)
changes - 
- make iframe side panel to match others -- ie use SidePanelHeader for
title
- make url optional in configuration to match that of the other widgets
(allow partial saves) - render No data status when error or no url
- split widget sizes into two -- graph widget sizes and widget sizes
(graph widgets are a subset of chart widgets)
2025-11-03 17:30:06 +00:00

61 lines
1.8 KiB
TypeScript

import { DEFAULT_WIDGET_SIZE } from '@/page-layout/constants/DefaultWidgetSize';
import { WIDGET_SIZES } from '@/page-layout/constants/WidgetSizes';
import { type PageLayout } from '@/page-layout/types/PageLayout';
import { type TabLayouts } from '@/page-layout/types/tab-layouts';
import { getWidgetSize } from '@/page-layout/utils/getWidgetSize';
import { isDefined } from 'twenty-shared/utils';
import { WidgetType } from '~/generated/graphql';
export const convertPageLayoutToTabLayouts = (
pageLayout: PageLayout,
): TabLayouts => {
if (pageLayout.tabs.length === 0) {
return {};
}
const tabLayouts: TabLayouts = {};
pageLayout.tabs.forEach((tab) => {
const layouts = tab.widgets.map((widget) => {
let minW = DEFAULT_WIDGET_SIZE.minimum.w;
let minH = DEFAULT_WIDGET_SIZE.minimum.h;
if (widget.type === WidgetType.GRAPH && isDefined(widget.configuration)) {
const graphType =
'graphType' in widget.configuration
? widget.configuration.graphType
: undefined;
if (isDefined(graphType)) {
const minimumSize = getWidgetSize(graphType, 'minimum');
minW = minimumSize.w;
minH = minimumSize.h;
}
}
if (widget.type === WidgetType.IFRAME) {
const iframeMinimumSize = WIDGET_SIZES[WidgetType.IFRAME]!.minimum;
minW = iframeMinimumSize.w;
minH = iframeMinimumSize.h;
}
return {
i: widget.id,
x: widget.gridPosition.column,
y: widget.gridPosition.row,
w: widget.gridPosition.columnSpan,
h: widget.gridPosition.rowSpan,
minW,
minH,
};
});
tabLayouts[tab.id] = {
desktop: layouts,
mobile: layouts.map((layout) => ({ ...layout, w: 1, x: 0 })),
};
});
return tabLayouts;
};