feat(dashboard): expand grid to 16 columns with auto-migration for saved 12-col layouts
This commit is contained in:
@@ -162,7 +162,10 @@ export function normalizeDashboardLayout(input: unknown): DashboardLayoutConfig
|
||||
return createDefaultDashboardLayout();
|
||||
}
|
||||
|
||||
const gridCols = clamp(Math.max(1, toInt(input.gridCols) ?? DASHBOARD_GRID_COLUMNS), 1, 24);
|
||||
const savedGridCols = clamp(Math.max(1, toInt(input.gridCols) ?? DASHBOARD_GRID_COLUMNS), 1, 24);
|
||||
// Migrate layouts saved with 12 columns to the current 16-column grid.
|
||||
const needsColumnMigration = savedGridCols === 12 && DASHBOARD_GRID_COLUMNS === 16;
|
||||
const gridCols = needsColumnMigration ? DASHBOARD_GRID_COLUMNS : savedGridCols;
|
||||
const rawWidgets = Array.isArray(input.widgets) ? input.widgets : [];
|
||||
const widgets: DashboardWidgetInstance[] = [];
|
||||
const seenIds = new Set<string>();
|
||||
@@ -184,14 +187,20 @@ export function normalizeDashboardLayout(input: unknown): DashboardLayoutConfig
|
||||
}
|
||||
seenIds.add(id);
|
||||
|
||||
// Scale x and w when migrating from a 12-column to 16-column layout.
|
||||
const scaleCol = (v: number) => Math.round(v * 16 / 12);
|
||||
const rawX = typeof rawWidget.x === "number" ? (needsColumnMigration ? scaleCol(rawWidget.x) : rawWidget.x) : undefined;
|
||||
const rawW = typeof rawWidget.w === "number" ? (needsColumnMigration ? scaleCol(rawWidget.w) : rawWidget.w) : undefined;
|
||||
const rawMinW = typeof rawWidget.minW === "number" ? (needsColumnMigration ? scaleCol(rawWidget.minW) : rawWidget.minW) : undefined;
|
||||
|
||||
const widgetOptions: Parameters<typeof createDashboardWidget<typeof type>>[1] = {
|
||||
id,
|
||||
...(typeof rawWidget.title === "string" ? { title: rawWidget.title } : {}),
|
||||
...(typeof rawWidget.x === "number" ? { x: rawWidget.x } : {}),
|
||||
...(rawX !== undefined ? { x: rawX } : {}),
|
||||
...(typeof rawWidget.y === "number" ? { y: rawWidget.y } : {}),
|
||||
...(typeof rawWidget.w === "number" ? { w: rawWidget.w } : {}),
|
||||
...(rawW !== undefined ? { w: rawW } : {}),
|
||||
...(typeof rawWidget.h === "number" ? { h: rawWidget.h } : {}),
|
||||
...(typeof rawWidget.minW === "number" ? { minW: rawWidget.minW } : {}),
|
||||
...(rawMinW !== undefined ? { minW: rawMinW } : {}),
|
||||
...(typeof rawWidget.minH === "number" ? { minH: rawWidget.minH } : {}),
|
||||
...(rawWidget.config !== undefined ? { config: rawWidget.config } : {}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user