Skip to content

Admin in-file cleanup: platform, orgs, reports, events - #44

Closed
theobong wants to merge 6 commits into
chore/admin-campaign-06-stylesfrom
chore/admin-campaign-07-cleanup-a
Closed

theobong wants to merge 6 commits into
chore/admin-campaign-06-stylesfrom
chore/admin-campaign-07-cleanup-a

Conversation

@theobong

Copy link
Copy Markdown
Member

What changed

A behavior-neutral cleanup of the platform code, Organizations, Reports and Events. Nothing on screen or in any request changes:

  • The very long report and event pages are split into focused files. For example, the 700-line report detail is now a detail pane plus separate send, city, discussion, media, quick-action and activity parts.
  • Long org panels are split into named pieces.
  • Magic numbers are named, and values used across files come from one shared module: search debounce, map settle delay, short-ID length, byte sizes.
  • Dead code is deleted: 8 unused icons, an unused skeleton component and its CSS, a redundant report-status mapper.
  • Symbols used only inside their own file are no longer exported.

Visible in: admin (nothing should change).

Before you start

Verify

[Admin]

Reports:

  1. Open "Reports" and select a report. Expect: the same detail as before: header, photos, location, "Send to city", "Message the city", chat and activity.
  2. Type a message in the city message box, then switch to another report and back. Expect: as before, the draft is cleared when you switch reports.
  3. Type a message in the city message box. In DevTools go offline, click "Try again" when the error shows, then go back online. Expect: the typed message is still there.
  4. Search the list. Expect: the list filters after a short pause, as before.

Events:
5. Open "Events", select a cleanup, type in "Update for attendees" and in "Bags collected", then trigger and recover an error the same way. Expect: both values survive.
6. Click "Link reports". Expect: the picker works as before.

Organizations:
7. Open "Organizations", select an org, and open each tab: Profile, Members, Verification, Events. Expect: the same content and actions as before.
8. On Members, open a member's actions menu. Expect: the same menu.
9. On an org with evidence, open "Document 1". Leave it open while the org refreshes in the background. Expect: the viewer closes and keyboard focus stays on the document row.

Shared parts:
10. On the "Dashboard", tap a live-map pin, then close the card. Expect: the same card and legend.
11. On "Users", click "Ban account" and press Escape. Then open a report photo and use the arrow keys. Expect: the dialog and the photo viewer behave as before.

Regression

Everything that shares the moved code: [Admin]

  1. Walk every section from the Dashboard and run one action in each: flag, message, link, verify. Expect: the same toasts, the same selection behavior, and no visual change.

Not covered

  • The split files are covered by the full characterization suite, which is unchanged apart from import paths: 105 files, 1,087 tests.

Findings addressed

  • Reports and events: reports-page.tsx (7 components, 10 helpers, the 700-line detail) and events-page.tsx (the 440-line detail) are split into focused modules. ReportsPage and EventsPage stay exported from their page files.
  • Orgs: MemberRow, VerificationPanel, CreateOrgSlideOver, OrgProfileFields and OrgDetail are split into named parts in the same folder.
  • Platform:
    • LiveMap, LeafletMap, DialogHost and LightboxHost are split into named parts and hooks.
    • The page registry is built from one table.
    • One report-bucket mapper remains.
    • One brand-mark component.
    • Date formatting has one helper.
  • Magic values: new constants include SEARCH_DEBOUNCE_MS, MAP_SETTLE_MS, QUERY_STALE_MS, QUERY_GC_MS, SHORT_ID_LENGTH, INITIALS_MAX_LETTERS, BYTES_PER_MB, pin sizes, zoom levels, tooltip offset, ACCESS_LOGOUT_PATH and HOME_HASH. Values used across files live in lib/timing.ts, lib/display.ts and lib/bytes.ts.
  • Dead code:
    • 8 icons (Map, Settings, Bell, ChevronUp, Bookmark, Phone, Sidebar, Filter).
    • Skeleton and its .skel CSS.
    • reportBucket.
    • Unreachable ?? fallbacks.
    • An unused eslint-disable.
    • About 20 file-local symbols are no longer exported.

Decisions for the reviewer

  • One deliberate deviation. The report status view now uses Object.hasOwn. A status that equals an Object.prototype name, such as "constructor", used to crash the row; it now renders as "Needs verification", like any unknown status. Only a server sending a status outside its own enum can reach this. A test pins it.

Tests changed

  • Existing assertions are unchanged. One source-reading test (official-author.test.ts) points at the file the chat rows moved to.
  • Added tests:
    • drafts survive an error and recovery in the report and event details;
    • the evidence viewer resets and keeps focus on a refresh;
    • carto key handling;
    • event-kind views;
    • org form and slug helpers;
    • the report-status prototype-key case.

Verification

  • Node v22.23.2. pnpm lint, pnpm typecheck, pnpm build and pnpm test pass: 105 files, 1,087 tests, in 3 runs.
  • Adversarial review ran per chunk. It found and this PR fixed:
    • drafts and mutations moved below the detail error return (a failed refetch would have reset typed drafts);
    • the evidence list remounting and dropping focus on a refresh;
    • shared constants re-declared locally.
  • The fixes are proven by tests that pass on the base and failed on the branch before the fix.

🤖 Generated with Claude Code

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