Skip to content

refactor: Consolidate charts with BarChart component#7223

Draft
talissoncosta wants to merge 1 commit intofeat/feature-analytics-6067from
refactor/consolidate-charts-with-barchart
Draft

refactor: Consolidate charts with BarChart component#7223
talissoncosta wants to merge 1 commit intofeat/feature-analytics-6067from
refactor/consolidate-charts-with-barchart

Conversation

@talissoncosta
Copy link
Copy Markdown
Contributor

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Follow-up to #7215 — migrates the two raw-recharts consumers in the org-level Usage page to the shared <BarChart /> component, retiring the legacy recharts SCSS overrides.

What's migrated

Component Path What
OrganisationUsage (chart section) web/components/organisation-settings/usage/OrganisationUsage.container.tsx 4-metric stack with custom display labels (environment_document → "Environment Document"), selection-driven series, pre-formatted day axis
SingleSDKLabelsChart web/components/organisation-settings/usage/components/SingleSDKLabelsChart.tsx Per-SDK stack with palette colour map from parent + MultiSelect filter
OrganisationUsageMetrics (parent) web/components/organisation-settings/usage/OrganisationUsageMetrics.container.tsx Pre-formats day to 'D MMM' (matches BarChart's day-as-display-string contract); userAgentColorMap switched from MapRecord<string, string> for consistency with the BarChart prop

BarChart API additions

Both consumers needed two props the existing BarChart didn't expose:

  • barSize?: number — fixed bar width in pixels (OrganisationUsage uses 14px to fit four series per day comfortably)
  • verticalGrid?: boolean (default true) — toggles CartesianGrid's vertical lines (legacy charts hide them)

seriesLabels (added in #7215) handles the display-name mapping for OrganisationUsage (environment_document → "Environment Document").

Cleanup

  • Delete web/styles/3rdParty/_recharts.scss entirely — its rules existed solely to style the two legacy charts' tooltips. With both consumers migrated, no recharts global-className consumer remains; the new BarChart's ChartTooltip uses Bootstrap utilities + semantic token classes directly. Drop the @import too.
  • SingleSDKLabelsChart loses unused props (metricKey, colours) that the migration made redundant.

Net diff

+101 / -312 — six files changed, one deleted.

Type strictness

OrganisationUsage's colorMap and seriesLabels are typed against Record<MetricDataKey, string> where MetricDataKey is derived from the METRICS array ((typeof METRICS)[number]['dataKey']). Adding a new metric to METRICS forces both maps to be updated — TS errors on missing keys.

How did you test this code?

In the app

  1. ENV=local npm run dev
  2. Navigate to Organisation → Usage → 4-metric stacked chart renders, tooltip shows display names ("Flags", "Environment Document", etc.) with formatted dates
  3. Toggle metric checkboxes → series add/remove correctly
  4. Switch to SDK view (requires sdk_usage_charts flag enabled) → per-SDK stack renders, MultiSelect filter narrows visible series, tooltip shows SDK names

Automated

  • npx eslint — 0 errors on touched files
  • npm run typecheck — 0 new errors (pre-existing any cluster in useFeatureAnalytics.ts unchanged; pre-existing errors in OrganisationUsageSideBar/OrganisationUsagePage are unrelated)

Stack: 2/2 — depends on #7215 (Feature Analytics label grouping) for the BarChart component, seriesLabels prop, and chart colour tokens. Will rebase onto main when #7215 lands.

🤖 Generated with Claude Code

…rts SCSS

Replaces the two raw-recharts consumers with the shared <BarChart />
component introduced in #7215. Both pages keep their behaviour and
visual contract; the JSX collapses substantially.

BarChart API additions to support these consumers:
- `barSize?: number` — fixed bar width in pixels (OrganisationUsage
  uses 14px to fit four series per day comfortably)
- `verticalGrid?: boolean` (default true) — toggles CartesianGrid's
  vertical lines (legacy charts hide them)

Migrations:
- OrganisationUsage.container.tsx (4 metric series stacked, custom
  display labels via seriesLabels, selection-driven series filter,
  pre-formatted day axis)
- SingleSDKLabelsChart.tsx (per-SDK stacked, palette colour map
  passed in from parent, MultiSelect-driven SDK filter)
- OrganisationUsageMetrics.container.tsx — pre-formats day to
  'D MMM' (matches the new chart-side day-as-display-string contract),
  switches userAgentColorMap from Map to Record (consistent with
  BarChart's prop after #7215)

Cleanup:
- Delete web/styles/3rdParty/_recharts.scss entirely — its rules
  existed solely to style the two legacy charts' tooltips. With both
  consumers migrated, no consumer of recharts global classNames
  remains; the new BarChart's ChartTooltip uses Bootstrap utilities +
  semantic token classes directly. Drop the @import too.
- SingleSDKLabelsChart loses unused props (`metricKey`, `colours`)
  that the migration made redundant.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
flagsmith-frontend-preview Ready Ready Preview, Comment Apr 13, 2026 7:32pm
flagsmith-frontend-staging Ready Ready Preview, Comment Apr 13, 2026 7:32pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Preview Apr 13, 2026 7:32pm

Request Review

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard refactor labels Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

front-end Issue related to the React Front End Dashboard refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant