Skip to content

Split PanelViews.tsx into per-panel files (needs a shared-data design first) #144

Description

@jgupta05072003-code

What this is for

frontend/src/components/PanelViews.tsx is 1,665 lines and, like RoleDashboards.tsx (#136), renders a different screen depending on which nav item is active (if (panel === 'reports') { ... }, if (panel === 'districts') { ... }, etc. — about 20 of these).

This one is harder than #136 and needs some design thought before jumping in, so it's not broken into ready-to-go sub-issues yet the way #136 was. Read this whole issue before starting.

Why it's harder than the RoleDashboards split

RoleDashboards.tsx's 8 dashboards are fully independent — no shared code between them. PanelViews.tsx is different: at the top of the component there's a shared block of state, data-fetching, and helper functions that almost every panel branch below it depends on — things like:

  • students, schools, usersList, reportsList, teachersList (the fetched/fallback data)
  • getDistrictStats(stateCode), getBlockStats(districtCode) (aggregation helpers)
  • Various useState/useEffect hooks for search, filters, selected student, etc.

If you just cut a panel branch out into its own file, it'll break unless you also pass all the shared stuff it needs in as props (or find some other way to share it, e.g. a custom hook).

What needs to happen first (do this before moving any panel)

  1. Read through PanelViews.tsx top to bottom and list, for each panel branch, which of the shared variables/functions/state it actually uses (many panels only need 2-3 of them, not all).
  2. Design a shared pattern — the simplest is probably a custom hook (e.g. usePanelData(token, currentUser)) that returns { students, schools, usersList, reportsList, teachersList, getDistrictStats, getBlockStats }, which every extracted panel file can call.
  3. Propose the design (a short comment on this issue, or a small draft PR) before doing the full extraction — this is the part most worth a second pair of eyes.
  4. Once the shared-data pattern is agreed, this can be broken into per-panel sub-issues the same way Epic: split RoleDashboards.tsx into one file per dashboard #136 was for the dashboards.

How to check your work (once you get to actually moving panels)

  1. cd frontend && npm run lint — no errors.
  2. npm run build — succeeds.
  3. Run npm run dev and click through every panel for every role that can see it — confirm identical behavior to before (this file has more panels reachable by more roles than RoleDashboards, so there's more to check).

Not in scope here

No behavior or logic changes — this is purely about making the file smaller and easier to navigate, not changing what anything does.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions