Repository navigation
feat: add the instrument hub and record provenance - #1807
Conversation
Second half of the datahub revamp, on top of the subject hub. Record provenance: `Session.type` reaches the client on every record, and the export carries `seriesId` beside a `seriesName` resolved to `en` by the worker, which has no request language. Every record table gains COLLECTION_METHOD and SERIES columns. The instrument hub at `/datahub/instruments` lists one row per edition of each FORM, INTERACTIVE and FILE instrument, with a detail page holding a table and a chart over the records of that one edition. Filters live in the URL and are applied inside the data hook, so the download cannot disagree with the table. `summarizeBySubject` is generalised into a private `summarizeRecords(by, …)` now shared with `summary/by-instrument` and `summary/by-series`; the subject view alone did not justify the parameter, which is why PR1 shipped it inline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Correctness: - the kind filter rendered the raw enum, so the menu offered "FORM" while the cell beside it said "Form". Both now read one `useInstrumentKindLabels` map, keyed over `InstrumentKind` so a new kind fails to compile rather than reaching the screen untranslated - the method filter exempted a record carrying no method, so unchecking every method still left rows on screen. `methods` becomes optional, matching `series`: absent means every method, and a record with none survives the unfiltered view but no explicit selection - a series' member rows were all tagged FORM; the member's own kind is carried through instead - the scatter chart read its mark ring off the tooltip's background, so restyling the tooltip moved the ring. `CHART_SURFACE` names it Dead code from the WIP snapshot: an export-options ternary after the early return that made it unreachable, and a doc block attached to nothing in `tag-colors.ts`. De-duplication: `useSeriesNames` and `useInstrumentTitles` were the same four lines twice, so they collapse into `useInstrumentInfoById(params)`, which carries the kind the member table needed. The two identical summary mappers share `toInstrumentSummaries`. `COLOUR_BY_OPTIONS` is now the single source the search param derives from. `InitData` is renamed `InitInstruments`, since it names only the instruments. `useSubjectRecordSummaryQuery` and `useInstrumentRecordSummaryQuery` are deliberately left alone: the shape they share is the queryOptions-plus- hook pairing that apps/web/AGENTS.md requires of every prefetched hook. Tests: the seven new hooks and `InstrumentTable` gain unit tests. The e2e asserting the hub lists no series is replaced by one that drives what it now does, since the original passed only because the fixture group had none. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`TabLink` navigated with `to` alone, so TanStack dropped the current search params and the newly mounted tab silently widened the selection — the opposite of what putting the filters in the URL was for. The e2e that exists to catch this was passing anyway: it asserted the URL matched /methods=/, and `methods` carried a default of all three collection methods, so the param was present whether or not the filter had survived. Making `methods` optional removed the default and exposed the bug underneath. Also stops the graph spec reaching the tab through `getPageModel`, whose exact-URL assertion the route's own search-param defaults fail; it clicks the tab as a user would instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: GPT-6
gdevenyi
left a comment
There was a problem hiding this comment.
This branch has merge conflicts with main, so review is on hold.
Please merge or rebase on the current main, resolve the conflicts, run pnpm lint and pnpm test:coverage locally, and push. Review continues when the branch merges cleanly and CI is green.
Reviewed at commit f6d3f82.
…nt-hub # Conflicts: # apps/api/src/instrument-records/__tests__/instrument-records.service.test.ts # apps/api/src/instrument-records/instrument-records.service.ts # apps/web/src/routes/_app/datahub/subjects/$subjectId/graph.tsx
…raph `main` removed `datahub.visualization.selectMeasures` as dead code once the subject graph stopped using it. The instrument hub's graph route reads it, so the merge left the key missing and `tsc` rejecting the call. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
`main` now gates CI on 100% unit coverage, which this branch's new code did not meet. Adds the missing cases and removes three fallbacks no input can reach. The scatter tooltip's `formatter` compared the row name against `time`, but recharts passes the axis name, so the comparison never held and the collection date rendered as a raw epoch. Its `labelFormatter`, which did the formatting, is never called for a scatter. The date is now formatted in the row recharts actually names after the x axis. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…anches Also drops the export mapping's `?? 'N/A'` for a username the records mapping has already defaulted, which no input could reach. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Covers the instrument record table's filters, navigation and row actions, the listing's preview and spreadsheet export, and the remaining chart branches. Removes three things no input reaches: the `measureColumns` branch building an INSTRUMENT column for a series, whose page returns the member listing before that table is ever rendered; the toolbar's fallbacks for columns it declares itself and seeds filters for; and `html2canvas`, which `renderChartPng` replaced. Two types exported only for their own file go with them. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…d urls Two specs that could not run while the branch conflicted with main: - The series cell renders a translated "None" rather than an em-dash, which `f6d3f8295` changed without the spec following. - The subject's tab links now carry the chart palette, so a link click lands on `…/graph?palette=default` and never passes through a query-free url. A `**` glob cannot match that, so the wait is a regex allowing the query string. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
joshunrau
left a comment
There was a problem hiding this comment.
Thanks for this. The hub is a big step for the datahub, and the scoping on the new summary endpoints holds up. The new export shapes, the untranslated header identifiers and the PR's scope are all fine as they are. What's left is mostly places where the data shown or exported comes out wrong:
Access
- Scope the series lookup. In
apps/api/src/instrument-records/instrument-records.service.ts, the new series check infind()(:293-300) andresolveSeriesNames(:706) look the series up without the caller's ability. Another group's series id returns 200 with an empty list, while an unknown id returns 404, so a caller can tell that another group's series exists. Please look it up with the caller's ability and groups, ascreatedoes at:126. - Pin the scoping with a test. In
testing/src/specs/authorization.spec.ts, alongside the export case at:556-559, show that a user from another group gets nothing fromsummary/by-instrument,summary/by-series, or?seriesInstrumentId=without agroupId(.agents/docs/playbooks/add-api-endpoint.md, steps 9-10).
Data that comes out wrong
apps/web/src/routes/_app/datahub/subjects/index.tsx:280removesseriesIdfrom every subject-hub export. The README shipped beside it (apps/web/src/translations/datahub.json:108) promises that column, and the API describes it as the stable key (instrument-records.service.ts:692-699). Please keep it and updatesubjects/__tests__/index.test.tsx:476,497.- In
apps/web/src/hooks/useInstrumentVisualization.ts:83,96-100, theinstrumentIdstate is seeded before the page knows whether it is a series, and is never cleared. On a fresh load of a series page every download throws oninstrument.internal.name(:132) with no toast, and going back from a member to its series names the export after the member. Please derive the id from the route params or reset it. useInstrumentVisualization.ts:148stamps the current group, or the default, as GroupID on every exported row. The hub mixes records from every group for an admin with no current group, so please use each record's own group.apps/web/src/hooks/useRecordMetadataColumns.tsx:49shows "None" whenever the series title has not resolved, which reads as "collected individually". That happens while the catalog loads, and for an admin whose catalog lacks group-owned series. Please base the cell on__seriesId__and fall back to the id, asuseRecordChartSeries.ts:71does.- The trend line in
apps/web/src/routes/_app/datahub/instruments/$instrumentId/graph.tsx:66-73comes from/linear-model, which ignores the methods, series and date filters, so with a filter set it describes records that are not on screen. Please hide it when a filter narrows the set, or pass the filters through. apps/web/src/components/TimeDropdown.tsx:14is uncontrolled while minDate lives in the URL (table.tsx:219-223), so after a reload or a shared link it reads "All" while records are filtered.InstrumentTable.tsx:94,314-320has the same problem with the minimum-records input, which resets to "Any" on every refetch while rows stay hidden. Please drive both from state that survives a remount.apps/web/src/utils/distribution.ts:60puts boundary values one bin low because of float division (over 0–1, the values 0.3, 0.6 and 0.7 each land one bin low).Math.min(...)/Math.max(...)atdistribution.ts:39-40andRecordScatterChart.tsx:51-52throw a RangeError on large datasets; areduceavoids that.instruments/$instrumentId/table.tsx:157-171builds the measure columns from the first record only, so an optional field that record left blank is hidden for every row. Please use the union of keys, as the export already does.
Please add a unit test with each fix that fails without it.
If you hand this to Claude Code, Fable 5 is the right size: the set spans API group scoping, export correctness and URL state across routes.
Reviewed at commit e6d8421.
1. Scope series instrument lookup to the caller's group (API) 2. Keep seriesId in subject-hub export data 3. Clear stale member id when navigating back to a series 4. Export each record's own groupId instead of the current group 5. Show the series instrument id when its name is unavailable 6. Hide trend line when collection-method/time/series filters are active 7. Make TimeDropdown and min-records filter persist in URL search params 8. Fix float-division bin boundary and RangeError on large datasets 9. Derive measure columns from all records, not just the first 10. Avoid stack overflow from spreading large arrays into Math.min/max Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ve the timeframe The series lookup in `InstrumentRecordsService.find` was scoped by ability alone, which confines nothing: `read Instrument` carries no group condition and `Instrument` is absent from `GROUP_SCOPED_CONDITIONS`. A series another group owned therefore answered 200 with an empty list where an unknown id answers 404, and the status alone reported whether the series was real. The caller's own groups now narrow it, with an administrator — who belongs to no group — left unnarrowed. The instrument hub also held the timeframe twice, as both `minDate` and `minDateKey`. A shared link still read "past year" months later while bounded to the instant it was made. Only the key is stored now and `timeframeMinDate` derives the bound where it is used. The trend overlay tested for the presence of a filter rather than for narrowing, so selecting every collection method hid the regression though nothing was excluded. It now compares the plotted set against the unfiltered one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The dependency upgrade on main moved recharts to 3 while these components were still on this branch, so nothing type-checked them against it until the pull request was merged for CI. Three signatures moved: - `ReferenceLine`'s `segment` now takes exactly two points, where the trend was typed as an array of them. - `Tooltip`'s `formatter` widened its value to `ValueType | undefined`, so the date row narrows to a number before formatting. - Axis tick labels render in their own layer rather than inside the axis, so the two specs selecting them through `.recharts-xAxis` matched nothing. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Adds an instrument view of collected data alongside the subject hub from #1654 (merged). Users can inspect one instrument edition across subjects, or open a series to see what its members collected.
Merging
main#1654 merged, which conflicted this branch.
7b17710e4mergesmain(432dec811). Four conflicts:instrument-records.service.ts—maindeletedInitialMessageas unreachable while this branch renamedInitDatatoInitPayload/InitInstruments. Kept this branch's names without the deleted type;main's removal of themessage.successcheck on the INIT acknowledgement merged cleanly.instrument-records.service.test.ts— tookmain's deletion of the test pinning a defectmainhas since fixed.subjects/$subjectId/graph.tsx— took this branch'srenderChartPngrewrite whole.main's side was a cleanup inside thehtml2canvasblock that rewrite replaces.datahub.visualization.selectMeasures—mainremoved it as dead once the subject graph stopped using it, but the instrument graph still reads it, so it is restored in5657bbc84.This branch forked before two gates
mainhas since added, so it had never been measured against either:odc/unit-test-names-subject). Three flat specs underapps/web/src/__tests__/moved beside the files they test.pnpm test:coverage). 21 files were short, seven of them at 0%: both chart components,SelectChartPalette, and four instrument hub route files.Defects the coverage gate exposed
Three branches turned out to be unreachable because the code around them was wrong:
formattercompared the row name against'time', but recharts passes the axis name, so the comparison never held and both rows fell through to the measure label. ThelabelFormatterthat did the date formatting is never called for aScatterChartat all. The date is now formatted in the row recharts actually names after the x axis.instrument-hub.spec.tsexpected an em-dash in the series cell.f6d3f8295changed that cell to a translated "None" without updating the spec, which could not run while the branch conflicted.subject-detail.spec.tswaited on the glob**/graph. The subject tab links now carry the chart palette, so clicking one lands directly on…/graph?palette=defaultand the URL never passes through a query-free state — a**glob cannot match it, and the test timed out while sitting on the correct tab. The wait is now a regex allowing the query string.Code removed rather than covered
Each of these is unreachable, so it is deleted rather than pinned by a test:
isSeriesbranch ofmeasureColumnsininstruments/$instrumentId/table.tsx, which built an INSTRUMENT column for aDataTablethat function's own early return means is never rendered.InstrumentTabletoolbar's?./??fallbacks for the three columns it declares itself and seeds filters for ininitialState.getCategoricalColor's neutral fallback (the index is always belowMAX_CATEGORICAL_GROUPS, and every theme holds six hues),binDistribution's second?? 0(that row is pre-seeded at zero for every series key), and the export mapping's?? 'N/A'for a username the records mapping has already defaulted.html2canvas, whichrenderChartPngreplaced, together with its lockfile entries.RecordChartPointandDistributionRow, exported but used only in their own file.Validation on
e6d8421f8pnpm lint— 34/34, and green again on an immediate second pass. The second pass matters: each workspace's lint istsc && eslint --fix src, sotscruns before the fixer and a single green pass says nothing about the file left on disk.pnpm test:coverage— 4,649 passed and 4 expected failures; 100% statements, branches, functions and lines.pnpm knip— clean, apart from the pre-existingturboinignoreBinarieshint.pnpm test:e2e— 285/286 locally. The one failure isrecord-file-deletion.spec.ts, which 503s on record creation because a bare local stack starts no S3/rustfs backend. It passes in CI.e6d8421f8: every check green, including thelint-and-testjob that runs lint, the coverage gate and the full Playwright suite.Validation notes
--workers=1; it was contention on the shared database under six local workers, not a regression.apps/web/src/route-tree.tswas checked against the routes on disk and is in sync — every instrument hub route is registered. The generator was not run, per the repository rule that the user regenerates it.Co-Authored-By: Claude Opus 5 noreply@anthropic.com
Co-Authored-By: GPT-6
🤖 Generated with Claude Code