feat(editor): support arrays of relations - #549
Open
nadaamd wants to merge 2 commits into
Open
Conversation
Renders a searchable picker for string fields that reference a document of another collection, instead of leaving editors to type an identifier by hand. Options are read from the existing host bridge (`document.db.list()` filtered by `collection.getByFsPath()`), so no new route is needed. The field keeps storing a plain string: file format and content queries are unaffected, the value stays editable by hand, and a value matching no document is flagged but never rewritten. Refs nuxt-content#219 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A relation set on an array applies to its items: the editor option sits on the array while the value holding the reference is each entry. The array branch of `buildFormTreeFromSchema` dropped that option, so `z.array(z.string())` fell back to free-text badges. Past the object depth limit the editor input also replaced the array type itself, leaving the field with no item form to render. Both paths now keep the array and push the relation down to its item form, and `InputArray` renders one picker per entry alongside the usual reorder and delete controls. Only string items are converted, so an array of objects or numbers keeps the form it had before. Refs nuxt-content#219 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
|
@nadaamd is attempting to deploy a commit to the Nuxt Team on Vercel. A member of the Team first needs to authorize it. |
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.
Extends the
relationinput to arrays, soz.array(z.string())gets one pickerper entry instead of free-text badges.
Important
Stacked on #548. This branch contains that PR's commit as its base, so the
diff below shows both. Review only the second commit, 5afef9c — or the
compare against that branch.
Merge #548 first and this will shrink to the array change alone.
Refs #219, and #307 which was closed in favour of it — that one asked for this
array shape specifically.
Two bugs in the array path
A relation set on an array applies to its items — the editor option sits on
the array, while the value holding the reference is each entry. Neither array
path in
buildFormTreeFromSchemahandled that:The main path dropped the option. The array branch hardcodes
type: 'array'and buildsarrayItemFormfromdef.items, which never seesthe parent's
$content.editor. So the field fell back to string badges.Past the object depth limit the array type was lost entirely. There
typecomes fromeditor.input, so an array withinput: 'relation'becamea
relationitem andtype === 'array'went false — the field ended up withno
arrayItemFormto render at all.Both now keep the array and push the relation down to the item form, via one
shared
applyRelationToArrayItemhelper.Scope
Only string items are converted. An array of objects or numbers keeps exactly
the form it had before, so this cannot change how an existing schema renders.
The propagation is deliberately limited to
relationrather than anyeditor.input. Generalising it would sendinput: 'media'on an array toInputArray'sunsupportedTypebranch, which is a regression for anyonerelying on today's behaviour — worth doing, but as its own change with its own
per-type branch.
Relation to #518
#518 fixes the neighbouring case (arrays of enums) and touches the same file. No
conflict expected: it needs no
form.tschange, because forz.array(z.enum())the enum sits on
def.itemsand already reaches the item form. This branch addsits own
v-else-ifin the same spot and follows #518's row layout — input plusreorder and delete buttons — so whichever lands first, the other is a trivial
rebase. Happy to rebase on top of it if you would rather take that one first.
Test plan
src/app/test/unit/utils/form.test.ts— 3 new cases: array of relations,the deep-nesting path, and a guard that non-string items are left alone.
The first two fail without this change (
expected 'relation' to be 'array'on the deep path), so they are regression tests rather than restatements.
pnpm verifypasses: lint clean,nuxt typecheckandvue-tsc -p src/app/tsconfig.app.jsonclean, 416 tests green,pnpm test:typesclean.
reviewersadded to the docusplayground, the generated Draft-07 in
.nuxt/content/preview.mjscarries$content.editor.relationon the array definition, which is what the formbuilder consumes.
playground/docusnow has both shapes on thedocscollection —author(single) from feat(editor): add relation input to reference another collection #548 and
reviewers(array) here — both pointing at theexisting
authorsdata collection.