fix: pull dashboard widget data from a ChartDataService (#20)
CI / build-and-test (pull_request) Successful in 2m32s

Chart and KPI numbers were literals in DashboardView, duplicated between
the line and bar chart, and only existed at construction time. Add a thin
data layer as the seam for later refresh/filter work:

- ChartSeries / KpiData records, immutable, carrying translation keys
  rather than display text so the data layer stays free of a UI locale.
- ChartDataService interface plus an in-memory implementation returning
  the previous hardcoded numbers, so nothing changes visually.
- DashboardView injects the service, lays out the KPI tiles from its
  list (grid ids come from the data, so saved layouts still match), and
  resolves the keys against the bundle.

Also fixes DashboardChartPlaywrightTest, red on main since the KPI tiles
landed: it patched the first apex-chart, which is now a sparkline with no
xaxis.categories, so the axis-chart patch was a structural change and
legitimately redrew the SVG. It now targets an axis chart.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0124BiJikbhbiEsNfJxdWM69
This commit is contained in:
Pit Friedrich
2026-07-28 20:19:17 +02:00
parent e62292b96c
commit b341b2ed5d
7 changed files with 256 additions and 41 deletions
@@ -26,7 +26,7 @@ class DashboardChartPlaywrightTest extends PlaywrightTestBase {
@Test
void dataUpdate_keepsTheRenderedSvgInPlace() {
Locator chart = page.locator("apex-chart").first();
Locator chart = axisChart();
assertThat(chart.locator("svg").first()).isVisible();
// Tag the live SVG node: a full rebuild would replace it and drop the tag.
@@ -43,7 +43,7 @@ class DashboardChartPlaywrightTest extends PlaywrightTestBase {
@Test
void dataUpdate_keepsTheThemeOverlay() {
Locator chart = page.locator("apex-chart").first();
Locator chart = axisChart();
assertThat(chart.locator("svg").first()).isVisible();
chart.evaluate("(el, patch) => el.updateData(patch)", PATCH);
@@ -55,4 +55,12 @@ class DashboardChartPlaywrightTest extends PlaywrightTestBase {
assertTrue(String.valueOf(borderColor).startsWith("rgb"),
"expected a resolved theme color, got: " + borderColor);
}
/** The first chart in the DOM is a KPI sparkline, which has no
* {@code xaxis.categories} — patching one with categories is a structural
* change and legitimately redraws. The patch above is an axis-chart patch,
* so it has to be applied to an axis chart. */
private Locator axisChart() {
return page.locator("apex-chart:not(.dialect-sparkline)").first();
}
}