Files
twenty/packages/twenty-front/src/modules/page-layout/utils/prepareGridLayoutItemsWithPlaceholders.ts
T
nitin 902eb2c5d2 Instant widget placeholder placement on drag end (#15496)
closes -
https://discord.com/channels/1130383047699738754/1430596561137700957

fixed a bug - where on chart type change in side panel -- wont update
the widgets minimum size

---------

Co-authored-by: Raphaël Bosi <71827178+bosiraphael@users.noreply.github.com>
Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2025-11-03 17:08:13 +00:00

36 lines
1000 B
TypeScript

import { PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY } from '@/page-layout/constants/PendingWidgetPlaceholderLayoutKey';
import { type GridLayoutItem } from '@/page-layout/types/GridLayoutItem';
import { isDefined } from 'twenty-shared/utils';
import { type PageLayoutWidget } from '~/generated/graphql';
export const prepareGridLayoutItemsWithPlaceholders = (
widgets: PageLayoutWidget[] | undefined,
shouldIncludePendingPlaceholder: boolean,
): GridLayoutItem[] => {
const hasWidgets = isDefined(widgets) && widgets.length > 0;
if (!hasWidgets) {
return [
{
id: 'empty-placeholder',
type: 'placeholder' as const,
},
];
}
const gridLayoutItems: GridLayoutItem[] = widgets.map((widget) => ({
id: widget.id,
type: 'widget' as const,
widget,
}));
if (shouldIncludePendingPlaceholder) {
gridLayoutItems.push({
id: PENDING_WIDGET_PLACEHOLDER_LAYOUT_KEY,
type: 'placeholder' as const,
});
}
return gridLayoutItems;
};