Fix z.set() field values now properly displaying in subject table and export - #1544
Merged
joshunrau merged 4 commits intoSep 15, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Show
z.set()record fields correctly in the subject table and its exportsProblem
Instrument records with a
z.set()field showed the value as[object Set]in the subject table(Data Hub → subject → Table), and every download from that page wrote it as
{}.The stored data was fine. The API saves a Set in libjs's serialized form, and
useInstrumentRecordsparses the response with libjs's
reviver, so the web client gets a realSetback. The bug was inhow the page turned that value into text:
String(value), which gives"[object Set]".JSON.stringify, which writes aSetas{}.The
reviveris deliberately unchanged. The API and react-core need it to rebuild a realSet,because
z.set()validation rejects anything else.Changes
apps/websrc/utils/record-value.ts(new)formatRecordValue(value): a Set becomes its values joined with", "; anything else still goes throughString(value).src/routes/_app/datahub/$subjectId/table/index.tsxformatRecordValueinstead ofString.src/hooks/useInstrumentVisualization.tsdlbuilds the export rows, it converts Set values withformatRecordValue, so every download option writes them as the table shows them.Example: a Set of
MONEYandFRIENDSnow shows asMONEY, FRIENDSin the table and in everydownload option (CSV, TSV, Excel, their "Long" versions, and JSON). CSV and TSV quote it because it
contains a comma. In JSON it is a string, not an array.
Tests
Unit (
apps/web)src/utils/__tests__/record-value.test.ts(new): covers a Set, a Set revived from the API'sstored form, an empty Set, and other values.
src/hooks/__tests__/useInstrumentVisualization.test.ts: newset fieldstests for the wide,long and JSON exports. The mock records are now built by a small factory and reset in
beforeEach.End-to-end (
testing)src/pages/_app/instruments/render/$id.page.ts:completeHappinessQuestionnaireDissatisfied(causes): answers "No", fills in the requiredreason, and ticks the given causes in
causesOfDissatisfaction, the questionnaire'sz.set()field.
setHappinessSlidersshared withcompleteHappinessQuestionnaire, which behaves as before.src/specs/instrument-completion.spec.ts: newz.set() fieldsgroup whose setup completes thequestionnaire through the UI. That takes the Set through the form, the API and the database, and
back into the web client.
MONEY, FRIENDS."MONEY, FRIENDS".The new unit and end-to-end tests fail without the fix. The table e2e test received
[object Set], and the export tests received{}.Verification
pnpm lint: passes.pnpm test: 143 files, 1167 tests pass.pnpm test:e2e: 175 tests pass.Known gaps (not in this branch)
InstrumentSummaryGroupinpackages/react-corestill shows a Set as{}.InstrumentRecordsService.updateByIdinapps/apisaves the parsed datawithout the serializer, so editing a record that has a Set field probably stores it wrongly.
testing/src/specs/subject-detail.spec.tstimed out onceunder a full-suite run. It passed in Firefox and on 3 Chromium retries, and it is unrelated to
this change.
Closes issue #1543