Skip to content

admin: Migrate all metabase dashboard to UI#121

Open
skelz0r wants to merge 28 commits into
developfrom
features/admin-metabase-to-natif-graphs
Open

admin: Migrate all metabase dashboard to UI#121
skelz0r wants to merge 28 commits into
developfrom
features/admin-metabase-to-natif-graphs

Conversation

@skelz0r
Copy link
Copy Markdown
Member

@skelz0r skelz0r commented May 12, 2026

@skelz0r skelz0r self-assigned this May 12, 2026
@linear
Copy link
Copy Markdown

linear Bot commented May 12, 2026

API-6748

skelz0r added 22 commits May 12, 2026 18:16
The existing dsfr-chart library already includes a <pie-chart> web
component. This adds the ERB partial to expose it alongside the
existing _kpi, _line, and _bar partials.

Accepts `title:` and `segments:` (array of {label:, value:}).
These readonly models map to the existing materialized views defined
in very_ansible (controller_name, kpi1, kpi2, kpi3). They follow the
same table naming convention as ConsumptionSummary:
admin_apientreprise_#{Rails.env}_access_logs_<name>
Shared filter for all admin statistics pages. Handles date range
(with presets), interval (jour/semaine/mois), domaine
(entreprise/particulier), and optional API/email/token/external_id
fields. Converts interval to PostgreSQL date_trunc unit.
Query object for the kpi query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the token consumption query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the top users query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api health query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api status query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the annual stats query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the api consumers query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the users overview query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Query object for the user status query admin statistics page.
Translates Metabase SQL cards into ActiveRecord queries against
ConsumptionSummary, AccessLog, AuthorizationRequest and Token models.
Migrates Metabase dashboards from collections 54, 63, 66, 67 into
native admin pages. Each page has its own query object and view.

Pages: KPI & Statistiques, Consommation d'un token, Top 10
utilisateurs, État de santé global, Statut d'une API, Statistiques
annuelles, Consommateurs d'une API, Vue générale utilisateurs,
Status utilisateur/datapass/jetons.

Merges: D90+D91 (KPI by domain filter), D86+D87 (annual stats by
domain filter). Drops: D49 (migration tokens), D43 (EdL anciens
jetons), D101 (Suivi FQF).

Adds /admin/statistics route, nav link, DSFR tile index, shared
filter partial with date presets and domain/interval/email selectors.
These views already exist in production (managed by very_ansible) but
were missing from db/schema.rb. Adds them alongside the existing
consumption_summary view, following the same naming convention.
Describes the 9 dashboard pages migrated from Metabase, their origin
collections/dashboards, architecture (query objects, filter, views),
chart components used, and the 3 excluded legacy dashboards.
Replace 9 collection routes with a single `resources :statistics,
only: [:index, :show], param: :page`. The show action validates
the page key against PAGES and renders the corresponding template.
Simplifies routing and removes per-page action boilerplate.
Add `# card XXX` comments to every public query method across all 9
admin query objects, matching the pattern established in
Provider::DashboardQuery. This makes it easy to trace each native
query back to its original Metabase saved question for debugging
and future maintenance.
token_status_breakdown compared exp (integer) against Time.current
(timestamp), causing a PG type mismatch error. Compare against
Time.current.to_i instead. Also fix the view which called strftime
on the raw integer — convert via Time.zone.at first.
A malformed token_id (typo, non-UUID input) would raise a raw PG
cast error and 500 the page. Validate the format upfront and raise
RecordNotFound instead, which Rails handles gracefully as a 404.
Date subtraction returns the exclusive day count (May 1..May 31 = 30),
but the range is inclusive so the actual window is 31 days. Add 1 to
get an equally sized comparison window for variation percentages.
Use where(exp: ..now) range syntax instead of manual SQL for the
expired tokens filter.
KpiView (abstract_class = true) has no table_name, so flushdb
tried to call delete_all on it and raised "no implicit conversion
of nil into String". Filter out abstract classes before iterating.
@skelz0r skelz0r force-pushed the features/admin-metabase-to-natif-graphs branch from ff946eb to 9f77c9e Compare May 12, 2026 16:17
skelz0r added 5 commits May 12, 2026 18:18
The additional abstract_class? check pushed the method 0.58 over
the AbcSize threshold. Inline disable matches the pattern used
elsewhere in this file.
- Api* → API* to match inflect.acronym 'API' in inflections.rb
- AnnualStats → AnnualStat, ApiConsumers → APIConsumer,
  TopUsers → TopUser to match classify singularization
  (controller uses "Admin::#{page.to_s.classify}Query".constantize)
- Qualify access_logs.status in SQL WHERE clauses to prevent
  PG::AmbiguousColumn when joining with authorization_requests
Prevent potential PG::AmbiguousColumn when joining with tables
that also have a status column (e.g. authorization_requests).
…uery

Both classes used `filter` in methods but had no accessor defined,
causing NameError at runtime.
Cover 8 query facades: APIStatusQuery, APIHealthQuery,
APIConsumerQuery, AnnualStatQuery, TopUserQuery,
TokenConsumptionQuery, UserStatusQuery, UsersOverviewQuery.

53 examples covering card methods, filter scoping, edge cases
(UUID validation, excluded controllers, epoch-based token expiry).
KpiQuery not tested — depends on ConsumptionSummary materialized view.
map { |r| r[:key] } → pluck(:key)
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.

1 participant