fe4512f80c
- Fix duplication of tabs in dashboards that didn't open the duplicated tab in the side panel: replaced the logic that used Math.round with an algorithm that switches the positions of the elements. We will keep relying on integers, but it will work well in all cases. - Make dnd work with record page layouts, where there is a pinned tab - Make tab movements work with pinned tab, too - Allow user to set a tab as the pinned tab - Make backend changes to be able to save tabs with `layoutMode` https://github.com/user-attachments/assets/ce1130fa-71df-49ba-ba2f-6f971e15dd49 --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
77 lines
2.4 KiB
TypeScript
77 lines
2.4 KiB
TypeScript
import { type DraftPageLayout } from '@/page-layout/types/DraftPageLayout';
|
|
import { type PageLayoutWidget } from '@/page-layout/types/PageLayoutWidget';
|
|
import { isDynamicRelationWidget } from '@/page-layout/utils/isDynamicRelationWidget';
|
|
import {
|
|
PageLayoutTabLayoutMode,
|
|
type UpdatePageLayoutWithTabsInput,
|
|
} from '~/generated-metadata/graphql';
|
|
|
|
const buildWidgetPosition = (
|
|
widget: PageLayoutWidget,
|
|
widgetIndex: number,
|
|
tabLayoutMode: PageLayoutTabLayoutMode,
|
|
) => {
|
|
switch (tabLayoutMode) {
|
|
case PageLayoutTabLayoutMode.VERTICAL_LIST: {
|
|
const index =
|
|
widget.position?.__typename === 'PageLayoutWidgetVerticalListPosition'
|
|
? widget.position.index
|
|
: widgetIndex;
|
|
|
|
return {
|
|
layoutMode: PageLayoutTabLayoutMode.VERTICAL_LIST,
|
|
index,
|
|
};
|
|
}
|
|
case PageLayoutTabLayoutMode.CANVAS:
|
|
return {
|
|
layoutMode: PageLayoutTabLayoutMode.CANVAS,
|
|
};
|
|
case PageLayoutTabLayoutMode.GRID:
|
|
return {
|
|
layoutMode: PageLayoutTabLayoutMode.GRID,
|
|
row: widget.gridPosition.row,
|
|
column: widget.gridPosition.column,
|
|
rowSpan: widget.gridPosition.rowSpan,
|
|
columnSpan: widget.gridPosition.columnSpan,
|
|
};
|
|
}
|
|
};
|
|
|
|
export const convertPageLayoutDraftToUpdateInput = (
|
|
pageLayoutDraft: DraftPageLayout,
|
|
): UpdatePageLayoutWithTabsInput => {
|
|
return {
|
|
name: pageLayoutDraft.name,
|
|
type: pageLayoutDraft.type,
|
|
objectMetadataId: pageLayoutDraft.objectMetadataId ?? null,
|
|
tabs: pageLayoutDraft.tabs.map((tab) => ({
|
|
id: tab.id,
|
|
title: tab.title,
|
|
position: tab.position,
|
|
layoutMode: tab.layoutMode,
|
|
widgets: tab.widgets
|
|
.filter((widget) => !isDynamicRelationWidget(widget))
|
|
.map((widget, widgetIndex) => ({
|
|
id: widget.id,
|
|
pageLayoutTabId: widget.pageLayoutTabId,
|
|
title: widget.title,
|
|
type: widget.type,
|
|
objectMetadataId: widget.objectMetadataId ?? null,
|
|
gridPosition: {
|
|
row: widget.gridPosition.row,
|
|
column: widget.gridPosition.column,
|
|
rowSpan: widget.gridPosition.rowSpan,
|
|
columnSpan: widget.gridPosition.columnSpan,
|
|
},
|
|
position: buildWidgetPosition(
|
|
widget,
|
|
widgetIndex,
|
|
tab.layoutMode ?? PageLayoutTabLayoutMode.GRID,
|
|
),
|
|
configuration: widget.configuration ?? null,
|
|
})),
|
|
})),
|
|
};
|
|
};
|