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:
4 files changed
+37
-3
No files matched your search
@@ -7,6 +7,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "tsc -b && vite build",
|
"build": "tsc -b && vite build",
|
||||||
|
"test": "vitest run",
|
||||||
"typecheck": "tsc -b",
|
"typecheck": "tsc -b",
|
||||||
"lint": "eslint .",
|
"lint": "eslint .",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview"
|
||||||
@@ -48,6 +49,7 @@
|
|||||||
"tailwindcss": "^4.2.2",
|
"tailwindcss": "^4.2.2",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"typescript-eslint": "^8.58.2",
|
"typescript-eslint": "^8.58.2",
|
||||||
"vite": "catalog:"
|
"vite": "catalog:",
|
||||||
|
"vitest": "^4.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ export function defaultOverviewMobile(): UiLayoutItem[] {
|
|||||||
* Bring any stored overview layout up to the current grid catalogue:
|
* Bring any stored overview layout up to the current grid catalogue:
|
||||||
* - expand the legacy single `stats` block into the 5 individual tiles
|
* - expand the legacy single `stats` block into the 5 individual tiles
|
||||||
* (inheriting its visibility),
|
* (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,
|
* placement to any widget missing coords,
|
||||||
* - append catalogue widgets the stored layout predates (visible),
|
* - append catalogue widgets the stored layout predates (visible),
|
||||||
* - drop unknown ids.
|
* - drop unknown ids.
|
||||||
@@ -117,7 +117,8 @@ export function migrateOverviewBlocks(stored: UiLayoutItem[] | undefined): UiLay
|
|||||||
const coords = validCoords(item)
|
const coords = validCoords(item)
|
||||||
? { x: item!.x!, y: item!.y!, w: item!.w!, h: item!.h! }
|
? { x: item!.x!, y: item!.y!, w: item!.w!, h: item!.h! }
|
||||||
: { ...spec.def };
|
: { ...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' },
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Generated
+3
@@ -461,6 +461,9 @@ importers:
|
|||||||
vite:
|
vite:
|
||||||
specifier: 'catalog:'
|
specifier: 'catalog:'
|
||||||
version: 8.1.0(@types/[email protected])([email protected])([email protected])([email protected])([email protected])
|
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:
|
packages:
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user