Skip to content

feat(dashboard): add indicator widget type#1392

Open
bgoniasa wants to merge 5 commits into
opengeos:mainfrom
bgoniasa:feature/dashboard-indicator-widget
Open

feat(dashboard): add indicator widget type#1392
bgoniasa wants to merge 5 commits into
opengeos:mainfrom
bgoniasa:feature/dashboard-indicator-widget

Conversation

@bgoniasa

@bgoniasa bgoniasa commented Jul 23, 2026

Copy link
Copy Markdown

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):

  • Added "indicator" to DashboardWidgetType
  • Added IndicatorAggregation type: "count" | "sum" | "mean" | "min" | "max" | "median"
  • Added indicatorAggregation, prefix, and suffix fields to DashboardWidget

Dashboard panel (DashboardPanel.tsx):

  • computeIndicator() — aggregates layer rows by the selected function
  • formatIndicatorValue() — locale-aware number formatting
  • Renders a centered big-number tile (no axes, no legend) instead of a chart

Widget editor (WidgetEditorDialog.tsx):

  • New "Indicator" option in the chart type dropdown
  • Aggregation picker (count, sum, mean, min, max, median)
  • Field selector (hidden for count)
  • Prefix/suffix text inputs

Persistence (project.ts):

  • Registered "indicator" in DASHBOARD_WIDGET_TYPES
  • Added INDICATOR_AGGREGATIONS validation array

i18n (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

  • New Features
    • Added dashboard indicator widgets for KPI-style single-value display.
    • Supports count, sum, mean, min, max, and median aggregations.
    • Added optional prefix and suffix formatting for indicator values.
    • Extended the widget editor and English/Spanish translations for the new indicator options.
  • Bug Fixes
    • Improved handling of empty or invalid indicator configurations, including safe fallback messaging and correct preservation of user-entered prefix/suffix whitespace.

bgoniasa added 2 commits July 23, 2026 04:29
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 '$ '.
@netlify

netlify Bot commented Jul 23, 2026

Copy link
Copy Markdown

Deploy Preview for geolibre-app failed.

Name Link
🔨 Latest commit 36f3d0a
🔍 Latest deploy log https://app.netlify.com/projects/geolibre-app/deploys/6a619ad62b824f00082f2d0a

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds an indicator dashboard widget with configurable aggregations, numeric formatting, prefixes and suffixes, KPI rendering, persistence normalization, localization, and test coverage.

Changes

Indicator widget support

Layer / File(s) Summary
Widget contract and persistence
packages/core/src/types.ts, packages/core/src/project.ts, tests/dashboard-widgets.test.ts
Dashboard widgets support indicator aggregations and formatting fields; normalization and project serialization tests cover valid, invalid, and count-based indicators.
Indicator editor configuration
apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx, apps/geolibre-desktop/src/i18n/locales/*.json
The editor exposes indicator type, aggregation, numeric field, prefix, and suffix controls with English and Spanish translations.
KPI computation and rendering
apps/geolibre-desktop/src/components/panels/DashboardPanel.tsx
Indicator values are computed using count, sum, mean, min, max, or median, formatted for display, titled from their configuration, and rendered with a no-data fallback.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related issues

  • opengeos/GeoLibre#1381 — Directly covers indicator widget types, aggregations, formatting, UI, rendering, and persistence.

Possibly related PRs

  • opengeos/GeoLibre#405 — Modifies the same dashboard widget editing, rendering, normalization, and test paths.

Suggested reviewers: craun718, giswqs

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
Loading

Poem

A rabbit counts the rows with care,
Finds sums and medians hiding there.
A prefix hops, a suffix sings,
While KPI numbers grow bright wings.
The dashboard tile now shines anew!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a new dashboard indicator widget type.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f1ecb3d and 36f3d0a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • apps/geolibre-desktop/src/components/panels/DashboardPanel.tsx
  • apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx
  • apps/geolibre-desktop/src/i18n/locales/en.json
  • apps/geolibre-desktop/src/i18n/locales/es.json
  • packages/core/src/project.ts
  • packages/core/src/types.ts
  • tests/dashboard-widgets.test.ts

Comment thread apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx
Comment thread apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx
- 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 36f3d0a and b793e45.

📒 Files selected for processing (1)
  • apps/geolibre-desktop/src/components/panels/WidgetEditorDialog.tsx

Comment on lines +189 to 191
{!hasChartable && type !== "indicator" ? (
<p className="text-sm text-muted-foreground">{t("dashboard.editor.noFields")}</p>
) : (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants