Render relation fields as labels with a selector (#3) - #12
Merged
Conversation
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>
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.
Closes #3. Renders belongs-to relation fields in the Next.js template instead of raw foreign-key ids.
FieldMeta.relationtype inlib/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 controlledRelationSelectthat survives async option + async record-value loading.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