Skip to content

Render relation fields as labels with a selector (#3) - #12

Merged
darwvin-dev merged 2 commits into
mainfrom
feat/relation-field-rendering
Jun 16, 2026
Merged

Render relation fields as labels with a selector (#3)#12
darwvin-dev merged 2 commits into
mainfrom
feat/relation-field-rendering

Conversation

@darwvin-dev

Copy link
Copy Markdown
Owner

Closes #3. Renders belongs-to relation fields in the Next.js template instead of raw foreign-key ids.

  • FieldMeta.relation type in lib/api.ts.
  • relation-field.tsx: useRelationOptions (dedup React Query fetch of the target resource), relationLabel (display_field -> name/title/label/email -> id), RelationLabel (list cell), and a controlled RelationSelect that survives async option + async record-value loading.
  • Wired into the data-grid cell and the resource form.
  • Demo API emits relation metadata for invoices.customer_id and tickets.customer_id.
  • Playwright spec tests/e2e/relations.spec.ts; README roadmap ticked.

Verified on the live demo: Invoices "Customer" column shows customer names (Acme Robotics / Northstar Labs / Kite Systems) not cus_00x ids, and the edit form renders a customer . 🤖 Generated with Claude Code

darwvin-dev and others added 2 commits June 16, 2026 19:01
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Go backend already serializes relation fields (type "relation" with a
relation descriptor), but the Next.js template rendered them as raw
foreign-key ids in lists and a plain text input in forms.

- lib/api.ts: add RelationMeta and FieldMeta.relation
- components/admin/relation-field.tsx: shared client-side resolution —
  useRelationOptions fetches the target resource once (deduped by React
  Query), relationLabel picks display_field then name/title/label/email
  then the id; RelationLabel renders the readable label in cells,
  RelationSelect is a controlled native select for forms (keeps the
  current value selected while the async options load)
- data-grid Cell + resource-form FieldInput: branch on type "relation"
- demo API: field() passes through relation metadata; invoices.customer_id
  and tickets.customer_id declare a belongs_to relation to customers
- tests/e2e/relations.spec.ts: list shows label not id; form select lists
  related labels and submits the related id
- README: check off the relation-field roadmap item

Closes #3

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@darwvin-dev
darwvin-dev merged commit f1a3824 into main Jun 16, 2026
2 checks passed
@darwvin-dev
darwvin-dev deleted the feat/relation-field-rendering branch June 16, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add relation field rendering in the frontend template

1 participant