dashboard: sync layout with configuration when adjusting column count

This prevents edge cases of widget deletion or additions in one layout mode
still showing up in others. This also handles privilege changes, where
users don't have access to specific widgets anymore, making sure
these persisted widget layouts are cleaned up when requested.
This commit is contained in:
Stephan de Wit 2026-02-17 14:45:34 +01:00
parent 5ce6895e4a
commit ab102b588b

View file

@ -290,6 +290,20 @@ class WidgetManager {
this.curColCount = curCount;
if (this.layouts != null && this.curColCount in this.layouts) {
// sync configurations and layouts, making sure the content
// of each widget isn't reset.
Object.values(this.widgetConfigurations).forEach(cfg => {
delete cfg.content
})
Object.values(this.layouts).forEach(layout => {
Object.keys(layout).forEach(id => {
if (!(id in this.widgetConfigurations)) {
delete layout[id]
}
})
})
// load a known layout based on the current column count
this.grid.load(Object.values({...this.widgetConfigurations, ...this.layouts[this.curColCount]}));
}
@ -691,7 +705,7 @@ class WidgetManager {
let items = this.grid.save(false);
const colCount = this.grid.getColumn();
this.layouts ??= {};
this.layouts[colCount] ??= {};
this.layouts[colCount] = {};
items = await Promise.all(items.map(async (item) => {
let widgetConfig = await this.widgetClasses[item.id].getWidgetConfig();
if (widgetConfig) {
@ -855,5 +869,6 @@ class WidgetManager {
if (id in this.widgetClasses) this.widgetClasses[id].onWidgetClose();
this.grid.removeWidget(this.widgetHTMLElements[id]);
if (id in this.loadedModules) this.moduleDiff.push(id);
delete this.widgetConfigurations[id];
}
}