fix(webui): preserve dashboard widget settings

Keep per-widget configuration when persisted overview layouts are migrated against the current widget catalogue. Account shortcuts, notes, links, filters, and other configurable widgets now retain their saved values after a page reload.

Add a WebUI Vitest entry point and regression coverage for restoring an account widget with saved configuration.

Fixes #243.
This commit is contained in:
DrSmoothl committed 2026-07-19 15:26:22 +08:00
1 parent 605b5d1104
commit 87bab6666b
4 files changed
+37 -3

No files matched your search

+3 -1
View File
@@ -7,6 +7,7 @@
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"test": "vitest run",
"typecheck": "tsc -b",
"lint": "eslint .",
"preview": "vite preview"
@@ -48,6 +49,7 @@
"tailwindcss": "^4.2.2",
"typescript": "catalog:",
"typescript-eslint": "^8.58.2",
"vite": "catalog:"
"vite": "catalog:",
"vitest": "^4.1.4"
}
}
+3 -2
View File
@@ -90,7 +90,7 @@ export function defaultOverviewMobile(): UiLayoutItem[] {
* Bring any stored overview layout up to the current grid catalogue:
* - expand the legacy single `stats` block into the 5 individual tiles
* (inheriting its visibility),
* - keep stored coords/visibility for known widgets, assign the default
* - keep stored coords/visibility/config for known widgets, assign the default
* placement to any widget missing coords,
* - append catalogue widgets the stored layout predates (visible),
* - drop unknown ids.
@@ -117,7 +117,8 @@ export function migrateOverviewBlocks(stored: UiLayoutItem[] | undefined): UiLay
const coords = validCoords(item)
? { x: item!.x!, y: item!.y!, w: item!.w!, h: item!.h! }
: { ...spec.def };
return { id: spec.id, visible, ...coords };
const config = isObj(item?.config) ? { config: { ...item.config } } : {};
return { id: spec.id, visible, ...coords, ...config };
});
}
@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { migrateOverviewBlocks } from '../src/lib/dashboard-layout';
describe('migrateOverviewBlocks', () => {
it('preserves saved widget configuration while restoring the grid', () => {
const migrated = migrateOverviewBlocks([
{
id: 'account',
visible: true,
x: 8,
y: 14,
w: 4,
h: 1,
config: { uin: '123456789' },
},
]);
expect(migrated.find((item) => item.id === 'account')).toEqual({
id: 'account',
visible: true,
x: 8,
y: 14,
w: 4,
h: 1,
config: { uin: '123456789' },
});
});
});
+3
View File
@@ -461,6 +461,9 @@ importers:
vite:
specifier: 'catalog:'
version: 8.1.0(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
vitest:
specifier: ^4.1.4
version: 4.1.4(@types/[email protected])(@vitest/[email protected])(@vitest/[email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected]))
packages: