Skip to content

A local-first personal finance app

[AI] Add missing widget types to dashboard import validation (#8159)

Sebastián Maluk47ce6a5b31fb
diff --git a/packages/loot-core/src/server/dashboard/app.test.ts b/packages/loot-core/src/server/dashboard/app.test.ts
new file mode 100644
index 0000000000..606c9e6d46
--- /dev/null
+++ b/packages/loot-core/src/server/dashboard/app.test.ts
@@ -0,0 +1,40 @@
+import { describe, expect, it } from 'vitest';
+
+import type { DashboardWidgetEntity } from '#types/models';
+
+import { isWidgetType } from './app';
+
+function allWidgetTypes<T extends DashboardWidgetEntity['type'][]>(
+ ...types: T &
+ (DashboardWidgetEntity['type'] extends T[number] ? unknown : never)
+): T {
+ return types;
+}
+
+const ALL_WIDGET_TYPES = allWidgetTypes(
+ 'net-worth-card',
+ 'cash-flow-card',
+ 'spending-card',
+ 'crossover-card',
+ 'budget-analysis-card',
+ 'markdown-card',
+ 'summary-card',
+ 'calendar-card',
+ 'formula-card',
+ 'custom-report',
+ 'sankey-card',
+ 'balance-forecast-card',
+ 'age-of-money-card',
+);
+
+describe('isWidgetType', () => {
+ it('all known widget types should be recognized', () => {
+ for (const type of ALL_WIDGET_TYPES) {
+ expect(isWidgetType(type)).toBe(true);
+ }
+ });
+
+ it('unknown widget types should be rejected', () => {
+ expect(isWidgetType('unknown-card')).toBe(false);
+ });
+});
diff --git a/packages/loot-core/src/server/dashboard/app.ts b/packages/loot-core/src/server/dashboard/app.ts
index abf12e6d77..f719332ad4 100644
--- a/packages/loot-core/src/server/dashboard/app.ts
+++ b/packages/loot-core/src/server/dashboard/app.ts
@@ -28,7 +28,9 @@ function isExportedCustomReportWidget(
return widget.type === 'custom-report';
}
-function isWidgetType(type: string): type is DashboardWidgetEntity['type'] {
+export function isWidgetType(
+ type: string,
+): type is DashboardWidgetEntity['type'] {
return [
'net-worth-card',
'cash-flow-card',
@@ -41,6 +43,8 @@ function isWidgetType(type: string): type is DashboardWidgetEntity['type'] {
'formula-card',
'custom-report',
'sankey-card',
+ 'balance-forecast-card',
+ 'age-of-money-card',
].includes(type);
}
diff --git a/upcoming-release-notes/dashboard-import-all-widgets.md b/upcoming-release-notes/dashboard-import-all-widgets.md
new file mode 100644
index 0000000000..89b39b7cab
--- /dev/null
+++ b/upcoming-release-notes/dashboard-import-all-widgets.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [samaluk]
+---
+
+Dashboard import now supports all widget types, including balance-forecast and age-of-money cards.