Skip to content

Show sync activity per user (#7) - #35

Merged
beygorghor merged 12 commits into
mainfrom
feat/user-activity
Sep 18, 2026
Merged

beygorghor merged 12 commits into
mainfrom
feat/user-activity

Conversation

@beygorghor

@beygorghor beygorghor commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes #7.

What changes

A Users entry in the left nav opens a page listing every user in the directory with, over a
switchable window of 7 days (the default), 30 days or 3 months: their number of syncs, total
submissions, distinct devices and last sync. Every column header sorts, and clicking it again
reverses. A user with no activity in the window keeps their row — zeros, an em-dash, dimmed —
because a supervisor looking for who went quiet needs to see them.

How it works

One SQL aggregate per window returns one row per user (41 of them); the browser re-sorts that
array in place, so only a change of window goes back to the server.

Two details in src/features/user-activity/api/queries.ts carry the whole query:

  • The window predicate sits in the on clause of a left join, not in a where. In a where it
    would drop exactly the inactive users the ticket is about. This is Django's FilteredRelation.
  • Every aggregate is cast ::int. Postgres returns count() as bigint, and pg hands bigint
    back as a string — measured: "6066" against 6066. Without the cast the table sorts "9"
    above "10" and nothing errors.

The window lives in the URL as ?period=7d|30d|90d — declared on the route with validateSearch
and a zod .catch('7d'), read with getRouteApi('/users'), written with replace: true. That is
ADR 0015, which landed on main while this branch was open; the window started in useState and
was moved. A window is now bookmarkable, and /users?period=bogus redirects to ?period=7d
instead of throwing. The server turns the enum into a cutoff date, and the query takes that date as
a parameter rather than calling now(), so the tests pin the window instead of racing the clock.

No migration: every column already exists.

New ADR

0017 — Cast aggregates to int in the SQL. It records the cast, rejects the alternative (a
global pg.types.setTypeParser), and states the uncomfortable part: PGlite returns an uncast
count() as a number, so no test can catch a missing cast. Review is the only check. ADR 0003
anticipated PGlite lacking something Neon has; this is the mirror image, where the test stays green.

What was checked

  • 72 tests pass (pnpm test), 13 of them new here; pnpm exec tsc --noEmit clean.
  • The query tests run on in-process Postgres and cover: a user who never synced, a user whose syncs
    all predate the window, repeat syncs from one device counted once, alphabetical order.
  • The table tests run in jsdom on props: default order, sorting and reversing, the em-dash, quiet
    users last in both directions, the empty state.
  • Against the real database: 41 users returned, 342 syncs over 7 days against 6,066 over 90.

One round of review found two real defects, both fixed here:

  • The sort test's fixture made syncCount order and alphabetical order identical, so a table that
    never left the username column passed it. New fixture (10 and 9) disagrees with the alphabet
    and with text ordering; mutating the comparator now fails it.
  • Switching the window unmounted the table and silently reset the sort. Fixed with
    placeholderData: keepPreviousData.

Worth knowing

  • The seed has no quiet user. Every one of the 41 users has synced within 7 days, so the dimmed
    row will not appear in the preview. ADR 0006 makes districts go silent, not users. The behaviour
    is covered by tests; it is just not demonstrable on seeded data.
  • Follow-ups deliberately not done here: asserting ::int in the compiled SQL (needs the builder
    exposed separately from the function that runs it), and moving relativeDays out of both table
    components into src/ui/ (it would edit device-syncs while other pairs are in it).

Merged with main

stale-devices landed first. Three conflicts, all the ones ADR 0010 predicts: one line in
nav.ts, one in router.ts, and the generated routeTree.gen.ts, which was regenerated rather
than hand-merged. That feature also took ADR numbers 0015 and 0016, so the ADR proposed here is
0017.

Spec: docs/superpowers/specs/2026-09-18-user-activity-design.md (with a "changed after the spec"
note) · Plan: docs/superpowers/plans/2026-09-18-user-activity.md

@Phil-V
Phil-V requested review from Crebert08 and Phil-V September 18, 2026 09:19
The preview of this branch was deleted when pull request #34 was closed,
and opening #35 on the same commit did not start a new one.

Claude-Session: https://claude.ai/code/session_01BLKZu4E8T123xzXASL2erH
@vercel

vercel Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
wee-app Ready Ready Preview Sep 18, 2026 10:22am UTC

Request Review

@Phil-V Phil-V 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.

LGTM!

@plmercereau

Copy link
Copy Markdown
Collaborator

the one that opened the PR can merge it then

Three conflicts, all the ones ADR 0010 predicts: one nav line, one router
line, and the generated route tree, which was regenerated rather than merged.

The stale devices feature took ADR numbers 0015 and 0016, so the ADR on
casting aggregates to int is renumbered 0017.
ADR 0015 landed on main while this branch was open: a page's state lives in
the URL. The window moves from useState to ?period=, declared on the route
with validateSearch and a zod catch('7d'), so a window can be bookmarked and
a hand-edited value falls back instead of throwing.
The sync trend feature landed. Same three conflicts as the last merge: one
nav line, one router line, and the generated route tree, regenerated.
@beygorghor
beygorghor merged commit 5df1fb0 into main Sep 18, 2026
1 of 2 checks passed

This branch was successfully deployed

1 active deployment
Preview — b6959ca1 Deployed Sep 18, 2026 by vercel[bot]
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.

Show sync activity per user

3 participants