feat(dashboard): add indicator widget type#1392
Conversation
Add a KPI indicator tile to the dashboard panel alongside the existing chart widgets (histogram, scatter, bar, line, box, pie). Changes: - Add 'indicator' to DashboardWidgetType in types.ts - Add IndicatorAggregation type: count, sum, mean, min, max, median - Add indicator fields to DashboardWidget: indicatorAggregation, prefix, suffix (field is reused from existing schema) - Implement computeIndicator() and formatIndicatorValue() in DashboardPanel with a centered big-number tile render - Add indicator option to WidgetEditorDialog with aggregation picker, field selector (hidden for count), and prefix/suffix inputs - Register 'indicator' in DASHBOARD_WIDGET_TYPES in normalizeWidgets - Add INDICATOR_AGGREGATIONS validation array in project.ts - Add i18n keys for indicator chart type and aggregations (en, es) - Add tests: indicator round-trip, count without field, invalid aggregation rejection The indicator widget is the first step toward richer dashboard elements. Cross-filtering and selector/list widgets will follow in subsequent PRs.
normalizeString does not trim, so removing the explicit .trim() call on prefix/suffix preserves intentional leading/trailing spaces like ' ha' or '$ '.
❌ Deploy Preview for geolibre-app failed.
|
📝 WalkthroughWalkthroughAdds an ChangesIndicator widget support
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant WidgetEditorDialog
participant normalizeWidgets
participant DashboardPanel
participant WidgetCard
WidgetEditorDialog->>normalizeWidgets: save indicator configuration
normalizeWidgets->>DashboardPanel: provide normalized widget
DashboardPanel->>WidgetCard: render indicator widget
WidgetCard->>WidgetCard: compute and format KPI value
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx`:
- Line 230: Update the widget type selector fallback around the “indicator”
option so count indicators remain selectable when hasChartable is false. Keep
the selector available for layers without chartable columns, while disabling or
filtering only widget types that require a field; preserve the existing
indicator option and renderer behavior.
- Around line 147-156: Update the indicator save logic in WidgetEditorDialog to
preserve the original prefix and suffix whitespace instead of trimming them.
Store prefix and suffix values directly when saving, while retaining the
existing conditional behavior for empty values and other indicator fields.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: c51e14ef-6e99-4835-803f-be8b88b7ab9d
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (7)
apps/geolibre-desktop/src/components/panels/DashboardPanel.tsxapps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsxapps/geolibre-desktop/src/i18n/locales/en.jsonapps/geolibre-desktop/src/i18n/locales/es.jsonpackages/core/src/project.tspackages/core/src/types.tstests/dashboard-widgets.test.ts
- Preserve prefix/suffix whitespace in editor save (was trimming) - Allow count indicator on layers without chartable columns - Use DashboardWidgetType instead of ChartType in editor state (ChartType does not include 'indicator') - Remove unused ChartType import Tests: 27/27 pass.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx`:
- Around line 189-191: Update the WidgetEditorDialog rendering around the
hasChartable/type condition so the widget type selector remains visible when no
chartable fields exist. Disable only options that require fields, keep the
indicator option selectable, and render the noFields message separately without
replacing the selector.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 0f8a0b3e-6c4c-43bc-a78f-ccf64a1c5d51
📒 Files selected for processing (1)
apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx
| {!hasChartable && type !== "indicator" ? ( | ||
| <p className="text-sm text-muted-foreground">{t("dashboard.editor.noFields")}</p> | ||
| ) : ( |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Keep the widget type selector available without chartable fields.
For a new widget, type defaults to "histogram", so this branch hides the entire selector before the user can choose the enabled "indicator" option. Consequently, count indicators still cannot be created on layers with no numeric or categorical columns. Render the type selector regardless, disable only field-dependent options, and show the “no fields” message separately.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx` around
lines 189 - 191, Update the WidgetEditorDialog rendering around the
hasChartable/type condition so the widget type selector remains visible when no
chartable fields exist. Disable only options that require fields, keep the
indicator option selectable, and render the noFields message separately without
replacing the selector.
Summary
Adds an indicator widget to the dashboard panel — a KPI tile showing a single aggregated value (count, sum, mean, min, max, median) as a large number with optional prefix/suffix. First PR from #1381.
What changed
Types (
packages/core/src/types.ts):"indicator"toDashboardWidgetTypeIndicatorAggregationtype:"count" | "sum" | "mean" | "min" | "max" | "median"indicatorAggregation,prefix, andsuffixfields toDashboardWidgetDashboard panel (
DashboardPanel.tsx):computeIndicator()— aggregates layer rows by the selected functionformatIndicatorValue()— locale-aware number formattingWidget editor (
WidgetEditorDialog.tsx):Persistence (
project.ts):"indicator"inDASHBOARD_WIDGET_TYPESINDICATOR_AGGREGATIONSvalidation arrayi18n (
en.json,es.json)Tests: All 27 tests pass (round-trip, count without field, invalid aggregation)
First step from #1381. Selector, list, and cross-filtering will follow.
Summary by CodeRabbit