feat: data service layer for chart widgets (#20) #34
Reference in New Issue
Block a user
Delete Branch "ai/issue-20-chart-data-service"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #20
What
Adds a thin data layer between the dashboard and its widgets, so the numbers no longer live as literals in the view.
New package
com.example.data:ChartSeries(nameKey, values, categoryKeys)— one named series plus its categories. Defensive copies, and the constructor rejects a mismatched value/category count.KpiData(id, labelKey, deltaPercent, trend)— the numbers behind a KPI tile.valueKey()derives the pre-formatted display value's bundle key.ChartDataService— interface withrevenueByMonth(),revenueByRegion(),kpis().InMemoryChartDataService—@Service, returns exactly the numbers the view used to hold.DashboardViewtakes the service via constructor injection, lays the KPI tiles out fromkpis()(i * 3reproduces the previous x positions), and feeds line/bar from one sharedrevenueByMonth()instead of two copies of the same list.Design note: translation keys, not text
The records carry bundle keys (
month.jan,kpi.revenueTotal), not display strings. Category and series labels are locale-dependent, and resolving them needs aUI— keeping that in the view is what makes the service testable as plain Java, per the acceptance criteria. The view resolves them with a smalltranslate(List<String>)helper.The grid id of a KPI tile now comes from
KpiData.id()(kpi-revenue,kpi-orders, …) — unchanged values, so layouts already saved inlocalStoragestill match.Tests
InMemoryChartDataServiceTest: no Spring context, no Vaadin UI — values/categories, uniquekpi-ids, value-key derivation, immutability and the balance check.DashboardViewTestpasses unchanged (same eight widgets, same tile geometry, same three charts), which is the "renders identically" check.Unrelated fix included
DashboardChartPlaywrightTest.dataUpdate_keepsTheRenderedSvgInPlacewas already red onmain(verified by stashing this branch's changes). Since the KPI tiles landed, the firstapex-chartin the DOM is a sparkline, which has noxaxis.categories; the test's axis-chart patch was therefore a structural change, andupdateOptions(..., redrawPaths=true)legitimately recreated the SVG. The test now targetsapex-chart:not(.dialect-sparkline). No production JS/Java changed for this../mvnw testgreen (30 tests, incl. Playwright e2e).