Skip to content

Redirects UI#7433

Merged
laritakr merged 5 commits intomainfrom
redirects-ui
May 6, 2026
Merged

Redirects UI#7433
laritakr merged 5 commits intomainfrom
redirects-ui

Conversation

@laritakr
Copy link
Copy Markdown
Contributor

@laritakr laritakr commented May 4, 2026

Summary

Adds the Aliases tab to the work and collection edit forms when the redirects feature is active, and wires the validator into the form's validation chain so collisions and invalid paths are caught before save.

Also documents the Field Behavior pattern this work follows, with BasedNearFieldBehavior and RedirectsFieldBehavior as worked examples.

Refs:

A refactor to make BasedNearFieldBehavior more composable with other
Field Behaviors, and to fix a bug in validates_with.

Two related form-layer fixes:

1. BasedNearFieldBehavior used to handle its own deserialize step
   end-to-end. That made it impossible for a second Field Behavior on
   the same form to take part in deserialization. The module now lets
   Reform handle the standard rename pass first, removes its own key,
   and passes control along. Multiple Field Behaviors can now coexist
   on one form without conflict.

2. ResourceForm declared its redirects validator with `validates_with`
   and a list of attributes. Reform and ActiveModel together end up
   sharing one options hash across every form subclass at load time.
   ActiveModel empties that hash the first time through, so the second
   subclass to load crashed with "attributes cannot be blank." Wiring
   the same validator through a `validation { ... }` block instead
   gives each subclass its own copy of the options.

This comment was marked as outdated.

Stores redirects as plain hashes on the parent work or collection,
mirroring how based_near stores plain URI strings. The previous shape
(a set of nested resources) round-tripped badly through Postgres —
sub-fields were stripped on save and unrelated parent fields leaked
into each entry, leaving the work unloadable.

Hyrax::Redirect is kept as a thin presenter the form view uses; other
code reads the hash directly. Hyrax.config.redirects_active? becomes
the single source of truth for "is the feature in use right now?",
combining the config and Flipflop gates. The catch-all redirect route
moves to the host application so it no longer intercepts engine
routes like /concern/...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@laritakr laritakr force-pushed the redirects-data-model branch from 3de53ac to adc28d1 Compare May 4, 2026 22:44
laritakr and others added 2 commits May 4, 2026 18:55
Adds the Aliases tab to work and collection edit forms when the
redirects feature is active. Wires the validator into the form's
validation chain so collisions and invalid paths are caught before save.
Bridges the form layer to the persisted hash shape via a populator and
prepopulator on the resource form.
Adds documentation/forms/field_behaviors.md covering the Field Behavior
pattern Hyrax uses for nested-attribute form properties. Explains the
contract every behavior must satisfy (registration, deserialize! strip,
populator, prepopulator, prepend wiring), the decision points when
adding a new one, and uses BasedNearFieldBehavior and
RedirectsFieldBehavior as worked examples.

Cross-links from documentation/redirects.md and updates the
Hyrax::Redirect description there (now a presenter, not a
Valkyrie::Resource).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 4, 2026

Test Results

    17 files      17 suites   3h 25m 53s ⏱️
 7 336 tests  7 030 ✅ 306 💤 0 ❌
24 686 runs  24 095 ✅ 591 💤 0 ❌

Results for commit 6c73a4e.

♻️ This comment has been updated with latest results.

@laritakr laritakr added the notes-minor Release Notes: Non-breaking features label May 5, 2026
Base automatically changed from redirects-data-model to main May 6, 2026 04:33
Copy link
Copy Markdown
Member

@orangewolf orangewolf left a comment

Choose a reason for hiding this comment

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

onclick for JS in the view isn't my favorite thing, but its small here and the rest of this work is very very good, so I'll let it slide ;-)

@laritakr laritakr merged commit cae6920 into main May 6, 2026
20 checks passed
@laritakr laritakr deleted the redirects-ui branch May 6, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes-minor Release Notes: Non-breaking features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants