feat(spa): form-spec-driven change form + legacy-iframe fallback (#659) + 1.9.0#663
Merged
Merged
Conversation
ccc81db to
da74a14
Compare
… + 1.9.0 The change form is now driven by the rest-api form-spec endpoint (GET <app>/<model>/<pk>/form-spec/, django-admin-rest-api 1.4.0+ #59) instead of discovering fields client-side from the model serializer, so the SPA honours the ModelAdmin layer: request-aware get_form / get_fieldsets / get_readonly_fields, formfield_overrides, custom Form classes, and the admin relation widgets — resolved server-side and mapped through the closed widget.kind enum. - The original change-form querystring is forwarded, so a get_form that swaps the Form on ?variant=… renders the legacy admin's fields. - A change_form_template / add_form_template override returns renderer: "legacy-iframe"; the SPA embeds the legacy admin page in an iframe inside the SPA shell (closes part of #624) rather than silently dropping the customisation. - A spec-fetch failure (older backend) degrades gracefully to the previous detail-payload-driven form. Implementation reuses the battle-tested FieldInput/EditForm: a small adapter maps each FormSpecField onto the existing FieldDescriptor (the backend reuses the detail serializer for `initial`, so value shapes line up). New: FormSpecResponse/WidgetKind wire types, client.formSpec(), useFormSpec hook, adaptFormSpec, LegacyIframe, ChangeForm. i18n strings for es/fr/pt. 11 new tests (adapter mapping + ChangeForm branches: iframe, form-spec fields, custom-widget fallback, graceful degradation). Raises the django-admin-rest-api floor to ^1.4.0 (the endpoint) and the django-admin-mcp-api floor to >=1.2.0 (the parity tool, #70). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
da74a14 to
2d3b804
Compare
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 #659. Completes the three-repo form-spec feature (rest-api #59 → mcp #70 → this).
What
The change form is now driven by the rest-api form-spec endpoint (
GET <app>/<model>/<pk>/form-spec/, django-admin-rest-api 1.4.0+) instead of discovering fields client-side from the model serializer. The SPA now honours the ModelAdmin layer:get_form(request, obj)/get_fieldsets(request, obj)/get_readonly_fields(request, obj)formfield_overrides, customFormclasses, admin relation widgetswidget.kindenumThe original change-form querystring is forwarded, so a
get_formthat swaps theFormon?variant=…renders the same fields the legacy/admin/does.Legacy-iframe escape hatch
When the admin overrides
change_form_template/add_form_template, the backend returns{renderer: "legacy-iframe", legacy_url}and the SPA embeds the legacy admin page in an iframe inside the SPA shell (breadcrumb / sidebar / toolbar stay SPA-rendered) — closing part of #624 instead of silently dropping the customisation.Graceful degradation
A spec-fetch failure (older backend without the endpoint) falls back to the previous detail-payload-driven form, so editing never breaks.
Design (per the issue's principle)
No SPA-specific customisation API. The SPA renders whatever the backend resolves from documented ModelAdmin hooks — and reuses the battle-tested
FieldInput/EditFormvia a small adapter that maps eachFormSpecFieldonto the existingFieldDescriptor(the backend reuses the detail serializer forinitial, so value shapes line up exactly — one control set, no drift).Acceptance criteria (#659)
fieldsets/readonly/formfield_overrides/get_form/get_fieldsetsrender from the resolved speckind: "custom"(+widget_class, dispatched via the [audit] formfield_overrides custom widgets are ignored — no React extension point for non-stock controls #625 registry, textarea fallback when unregistered)change_form_templateoverridescollapse, request-awareget_formvariant, readonly, custom→fallback,change_form_template→iframeChanges
New wire types (
FormSpecResponse/WidgetKind/…),client.formSpec(),useFormSpechook,adaptFormSpec,LegacyIframe,ChangeForm; i18n strings (es/fr/pt). Raises the rest-api floor to^1.4.0and the mcp-api floor to>=1.2.0.Tests / gate
11 new tests (adapter + ChangeForm branches). Full frontend suite green (233), typecheck + eslint + stylelint + dark-mode all clean,
pnpm buildproduces the bundle; backend pytest green (66).🤖 Generated with Claude Code