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>
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user