From 87bab6666bb389cb07ad576b2bb13ec687a84874 Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Sun, 19 Jul 2026 15:26:22 +0800 Subject: [PATCH] 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. --- packages/webui/package.json | 4 ++- packages/webui/src/lib/dashboard-layout.ts | 5 ++-- packages/webui/tests/dashboard-layout.test.ts | 28 +++++++++++++++++++ pnpm-lock.yaml | 3 ++ 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 packages/webui/tests/dashboard-layout.test.ts diff --git a/packages/webui/package.json b/packages/webui/package.json index dd3a3849..d1a16ffe 100644 --- a/packages/webui/package.json +++ b/packages/webui/package.json @@ -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" } } diff --git a/packages/webui/src/lib/dashboard-layout.ts b/packages/webui/src/lib/dashboard-layout.ts index 7eb033f9..ef404fdd 100644 --- a/packages/webui/src/lib/dashboard-layout.ts +++ b/packages/webui/src/lib/dashboard-layout.ts @@ -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 }; }); } diff --git a/packages/webui/tests/dashboard-layout.test.ts b/packages/webui/tests/dashboard-layout.test.ts new file mode 100644 index 00000000..5e30c4d8 --- /dev/null +++ b/packages/webui/tests/dashboard-layout.test.ts @@ -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' }, + }); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ca9676b0..fbe6c6dd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -461,6 +461,9 @@ importers: vite: specifier: 'catalog:' version: 8.1.0(@types/node@25.6.0)(esbuild@0.28.1)(jiti@2.6.1)(sass@1.99.0)(tsx@4.21.0) + vitest: + specifier: ^4.1.4 + version: 4.1.4(@types/node@25.6.0)(@vitest/coverage-istanbul@4.1.4)(@vitest/coverage-v8@4.1.4)(vite@8.1.0(@types/node@25.6.0)(esbuild@0.28.1)(jiti@2.6.1)(sass@1.99.0)(tsx@4.21.0)) packages: