Skip to content

Issue #1429: feat: honor association cardinality in the MDR frontend - #1507

Merged
bjagg merged 2 commits into
mainfrom
feat/1429/honor-cardinality-fe
Nov 12, 2026
Merged

bjagg merged 2 commits into
mainfrom
feat/1429/honor-cardinality-fe

Conversation

@cbeach47

@cbeach47 cbeach47 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
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's Array as "No", so the UI disagreed with the generated schema.

The UI now follows the generated schema's rule:

  • Root: a list only when its own Array is Yes. A NULL root is now single.
  • Embedded child: follows its association's Array. It falls back to the child's own Array while the association's is NULL, which is the same fallback the server uses.
  • Reference: always a single object, whatever its Array, as add_ref writes it.

How it's done:

  • getModelDetailsWithTree sets a new EntityTreeNode.IsArray for each node where it sits. A shared child such as Identifier can be a list under Person and single under Organization.
  • generateJsonSchema and generateSampleRecords read IsArray, replacing their two isArrayEntity copies.
  • ChildEntityDTO gains AssociationArray, which the backend already sends.

Behaviour changes, which are intended and not regressions:

  • A root with no Array is single. A reference node is single. An embedded child follows its association.
  • Saved expressions are unchanged; only new default expressions differ. A saved expression built under the old rule can now be flagged by Bulk Transformations validation, for example Person.Identifier must be array (see Testing).

Limitations:

Merging deploys the MDR frontend to dev (lif_mdr_frontend.yml watches frontends/mdr-frontend/**).

Related Issues

Closes #1429
Refs #1502

Type of Change
  • New feature (non-breaking change which adds functionality)
Project Area(s) Affected
  • frontends/

Checklist
  • commit message follows commit guidelines (see commitlint.config.mjs)
  • tests are included (unit and/or integration tests)
  • pre-commit hooks have been run successfully (except pytest; see Testing)
  • CHANGELOG.md entry added (MDR UI)
Testing
  • Manual testing performed
  • Automated tests added/updated

Automated:

  • New modelService.test.ts (4 tests) covers:
    • the IsArray flags, including a shared child, a NULL association falling back to its child, a reference, and a NULL root;
    • the JSON Schema types;
    • sample records, which validate against that schema;
    • the default JSONata expression under each parent.
  • All 4 fail against main's modelService.ts.
  • npx vitest run: 58 passed (7 files). tsc -b: clean. ESLint: 0 errors, and 56 warnings in modelService.ts against 62 on main.
  • The commit skipped the pre-commit pytest hook. Two tests in test_clone_datamodel_sql.py fail locally and also fail on main locally: the clone reads value-set values without an ORDER BY, so an enum can come out in a different order. They're unrelated to this frontend change.

Manual: dev (main frontend) vs. local (this branch). Both backends include #1498, and the same model file was imported on both, so only the frontend differs. The model is test 1429 FE: #1498's test 1429 BE with Organization given root Array: true and Organization.name given Required: true, so the references under Course are lists on main and have an attribute to map.

Mappings default expressions, with source LIF Assessment.revisionDate and target test 1429 FE:

Target dev (main) local (branch)
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:

  • Expression Editor: evaluating each mapping over the generated sample gave the shapes in the table on each environment.
  • Bulk Transformations: no issues with the three branch mappings. Editing Person.Identifier back to main's single-object shape is flagged must be array on local.
  • LIF source sample (dev only): the reference children (offeredByRefOrganization, demonstratesRefCompetency, …) are lists, as main's rule predicts. The branch's LIF sample wasn't compared.
Additional Notes

Unchanged between main and this branch, as expected:

  • Organization → Identifier is single under both rules.
  • Competency and Organization are list roots that map from the source list (Assessment.{ … }).
  • No embedded association in local LIF (model 1) differs between the two rules.

🤖 Generated with Claude Code

@cbeach47 cbeach47 changed the title Issue #1429: FE changes to honor cardinality Issue #1429: feat: honor association cardinality in the MDR frontend Nov 11, 2026
@cbeach47

Copy link
Copy Markdown
Contributor Author

Test data model file:
test_1429_FE.lif-mdr-model.json

@bjagg bjagg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Chris. I checked it at 511987b.

  • Same rule as the server: isListUnderParent matches _get_array in schema_generation_service.py. The association's Array wins when it's set; the child's own Array is used while it's NULL, and a NULL child is single. A root is a list only when its own Array is Yes, as generate_openapi_schema writes it. A reference is single, as add_ref writes it (ref_data["type"] = "object").
  • The data is there: ChildEntities comes from get_filtered_entity_children, which sets AssociationArray from the association row since #1498.
  • Tests: npx vitest run passes (58), and tsc -b is clean. All 4 new tests in modelService.test.ts fail with main's modelService.ts and types.ts.
  • Nothing left on the old rule: the two isArrayEntity copies were the only entity-level list checks. The attribute check in generateSampleRecords is still the old one, which is #1502, as the body says.

Approving.

@bjagg
bjagg merged commit 77bbbc0 into main Nov 12, 2026
4 checks passed
@bjagg
bjagg deleted the feat/1429/honor-cardinality-fe branch November 12, 2026 00:10
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Current Community Efforts 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MDR portability: generate an element's cardinality from its association's Array

2 participants