Repository navigation
Issue #1429: feat: honor association cardinality in the MDR frontend - #1507
Merged
Merged
Conversation
Contributor
Author
|
Test data model file: |
6 tasks done
bjagg
approved these changes
Nov 12, 2026
bjagg
left a comment
Contributor
There was a problem hiding this comment.
Thanks, Chris. I checked it at 511987b.
- Same rule as the server:
isListUnderParentmatches_get_arrayinschema_generation_service.py. The association'sArraywins when it's set; the child's ownArrayis used while it's NULL, and a NULL child is single. A root is a list only when its ownArrayisYes, asgenerate_openapi_schemawrites it. A reference is single, asadd_refwrites it (ref_data["type"] = "object"). - The data is there:
ChildEntitiescomes fromget_filtered_entity_children, which setsAssociationArrayfrom the association row since #1498. - Tests:
npx vitest runpasses (58), andtsc -bis clean. All 4 new tests inmodelService.test.tsfail withmain'smodelService.tsandtypes.ts. - Nothing left on the old rule: the two
isArrayEntitycopies were the only entity-level list checks. The attribute check ingenerateSampleRecordsis still the old one, which is #1502, as the body says.
Approving.
dereck-symmetry
pushed a commit
that referenced
this pull request
Nov 12, 2026
bjagg
added a commit
that referenced
this pull request
Nov 12, 2026
…#1509) ##### Description of Change **Problem.** PR #1508 (the API half of #1472) lets the MDR API read and set an association's `Name` and `Array`, but the MDR UI can't edit them yet. **Solution.** This is the UI half of #1472. It's stacked on #1508, so the diff shrinks to this PR's commit once that merges. - **Edit Association** (entity and attribute associations) shows **Name** and **List under this parent**. - Only changed fields are sent, as before. - Clearing Name sends `null`, which the API resets to the default key. - A whitespace-only Name is sent as typed, so the API's 400 explains why it was refused in the dialog's error line. Cross-model and `ExtendedByDataModelId` refusals show the same way. - **The dialog title** shows the association's `Name`, the key the child appears under. Before this PR, `handleEditAssoc` overwrote `itemToEdit.Name` with the tree label "for display". With `Name` now a field, that override would make every save send a `Name`. - **+ Existing Entity / Attribute** (create), in a model's own dialog: picking the child starts the switch at the child's own `Array`, or off for a Reference (#1471), so the user sees the list setting and can change it. This follows the decision on #1429/#1472: after #1498, an imported list element is stored as single, so the old default (the rule) is wrong for imported models. - `SelectDialog` gets an optional `onSelected` hook for this. Value sets don't pass it, so they're unchanged. - The create template only copies truthy values it already has, so the switch's value is carried over explicitly (`withCreateArray`). Otherwise an unticked switch would be dropped. - **Overlay models' create dialogs** don't show the switch. Their associations are cross-model or `ExtendedByDataModelId`, which the API refuses to give an `Array`, so sending one would break every plain create there. **Limitations.** - Changing Placement to Reference after picking the child doesn't reset the switch. What's sent is what the switch shows. - `Name` is edit-only, as decided. - An element `Array` edit can still overwrite a value set here (#1478), and a clone recomputes `Name` (#1500). - Pre-existing: every edit-dialog save also sends `ActivationDate`, because of the dialog's minute-precision round trip. That's unchanged here. **Overlap with #1507** (cbeach47, the frontend half of #1429): #1507 makes the UI's own schema and sample records read the association's `Array`, and this PR is where a user sets it. The two share no files (#1507 changes `modelService.ts` and `types.ts`), so either can merge first. Once both are in, a switch flipped here should show up in #1507's schema and samples after the dialog's refetch. ##### Related Issues Closes #1472 (with #1508) Refs #1429, #1471, #1478, #1500, #913 ##### Type of Change - [x] New feature (non-breaking change which adds functionality) ##### Project Area(s) Affected - [x] frontends/ - [x] test/ or e2e/ --- ##### Checklist - [x] commit message follows commit guidelines (see commitlint.config.mjs) - [x] tests are included (unit and/or integration tests) - [x] pre-commit hooks have been run successfully (on the changed files: cspell passed. `ty-check` and `pytest` were skipped, since this diff is frontend-only and the Python tree is #1508's, which ran the full suite) ##### Testing - vitest: 62 passed (8 new, in `associationKeyFields.test.ts`). `npm run build` (tsc -b + vite) passes; eslint reports 0 errors. - **Browser, against the real MDR API** (this branch's code, seeded Postgres), on model 26 (R1 Demo Source Data Model). I checked each step's request body, and read the stored rows once, after the last step: - edit `person → employment`: Name `jobs`, list on → `PUT {"Name":"jobs","Array":true}` (200; reopening shows `jobs`, on); - clear Name → `PUT {"Name":null}`, final row `(employment, t)`; - Name `" "` → 400, and the dialog stays open with "Name can't be blank: …"; - attribute association `preferences.preferred_org_types`, list off → `PUT {"Array":false}`, final row `f`; - + Existing Attribute `preferred_org_types` (a list) on `person`: the switch starts on → `POST … "Array":true`, final row `t`; - + Existing Attribute `id` (single) on `employment`: starts off, ticked → `POST … "Array":true`, final row `t`; - + Existing Entity `preferences` (single) under `person`, untouched → `POST … "Array":false`, final row `f`; - model 17 (overlay): the + Existing Attribute dialog has no list switch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: dereck <dereck.haskins@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Benito J. Gonzalez <bgonzalez@unicon.net>
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.
Description of Change
The frontend half of #1429; the backend half is #1498.
The MDR UI builds its own JSON Schema and sample records, and uses them for the Mappings default expressions and validation, the Expression Editor and Bulk Transformations. It decided list vs. single from the entity's own
Array, with NULL meaning a list. Since #1498, an import stores the list setting on the association and every non-root entity'sArrayas"No", so the UI disagreed with the generated schema.The UI now follows the generated schema's rule:
ArrayisYes. A NULL root is now single.Array. It falls back to the child's ownArraywhile the association's is NULL, which is the same fallback the server uses.Array, asadd_refwrites it.How it's done:
getModelDetailsWithTreesets a newEntityTreeNode.IsArrayfor each node where it sits. A shared child such asIdentifiercan be a list underPersonand single underOrganization.generateJsonSchemaandgenerateSampleRecordsreadIsArray, replacing their twoisArrayEntitycopies.ChildEntityDTOgainsAssociationArray, which the backend already sends.Behaviour changes, which are intended and not regressions:
Arrayis single. A reference node is single. An embedded child follows its association.Person.Identifiermust be array(see Testing).Limitations:
Course→OrganizationasAccreditedByandApprovedBy) share one path and both show asOrganization. That predates this PR; see MDR portability: store mapping paths so that two roles don't share one EntityIdPath (follow-up to #1389) #1434 (issuecomment-6809020718).Merging deploys the MDR frontend to dev (
lif_mdr_frontend.ymlwatchesfrontends/mdr-frontend/**).Related Issues
Closes #1429
Refs #1502
Type of Change
Project Area(s) Affected
Checklist
pytest; see Testing)Testing
Automated:
modelService.test.ts(4 tests) covers:IsArrayflags, including a shared child, a NULL association falling back to its child, a reference, and a NULL root;main'smodelService.ts.npx vitest run: 58 passed (7 files).tsc -b: clean. ESLint: 0 errors, and 56 warnings inmodelService.tsagainst 62 onmain.pytesthook. Two tests intest_clone_datamodel_sql.pyfail locally and also fail onmainlocally: the clone reads value-set values without anORDER BY, so anenumcan come out in a different order. They're unrelated to this frontend change.Manual: dev (
mainfrontend) vs. local (this branch). Both backends include #1498, and the same model file was imported on both, so only the frontend differs. The model istest 1429 FE: #1498'stest 1429 BEwithOrganizationgiven rootArray: trueandOrganization.namegivenRequired: true, so the references underCourseare lists onmainand have an attribute to map.Mappings default expressions, with source LIF
Assessment.revisionDateand targettest 1429 FE:main)Person → Identifier → identifier{ "Person": { "Identifier": { … } } }{ "Person": { "Identifier": [{ … }] } }Person → Contact → Address → city{ "Person": { "Contact": { "Address": { … } } } }{ "Person": { "Contact": [{ "Address": [{ … }] }] } }Course → Organization (reference) → name{ "Course": { "Organization": [{ … }] } }{ "Course": { "Organization": { … } } }Other checks:
Person.Identifierback tomain's single-object shape is flaggedmust be arrayon local.offeredByRefOrganization,demonstratesRefCompetency, …) are lists, asmain's rule predicts. The branch's LIF sample wasn't compared.Additional Notes
Unchanged between
mainand this branch, as expected:Organization → Identifieris single under both rules.CompetencyandOrganizationare list roots that map from the source list (Assessment.{ … }).🤖 Generated with Claude Code