Skip to content

Fix dropdown lookup state normalization for attribute edit forms#2447

Merged
alecritson merged 2 commits intolunarphp:1.xfrom
tazzytazzy:fix/dropdown-lookup-format-state
Apr 14, 2026
Merged

Fix dropdown lookup state normalization for attribute edit forms#2447
alecritson merged 2 commits intolunarphp:1.xfrom
tazzytazzy:fix/dropdown-lookup-format-state

Conversation

@tazzytazzy
Copy link
Copy Markdown
Contributor

Summary

This fixes dropdown attribute lookup hydration when editing attributes in the admin panel. This should resolve PR #2443 too.

Dropdown lookups are stored as an array of { label, value } pairs, but the edit form expects keyed state for the KeyValue component. That mismatch caused lookup state to hydrate incorrectly in attribute edit flows.

What changed

  • add configuration normalization support for field types
  • normalize dropdown lookup configuration for edit-form state
  • normalize attribute relation-manager configuration state during hydration
  • add focused regression coverage for:
    • dropdown lookup normalization
    • editing dropdown attribute lookups in the relation manager

Why

The admin attribute edit flow needs dropdown lookup state in keyed form like:

[
    'lookups' => [
        'Foo' => 'bar',
    ],
]

but persisted configuration is stored like:

[
    'lookups' => [
        ['label' => 'Foo', 'value' => 'bar'],
    ],
]

Without normalization, the edit form mounts with the wrong shape and the lookup field does not hydrate correctly.

Tests

  • tests/admin/Feature/Filament/Resources/AttributeGroupResource/RelationManagers/AttributesRelationManagerTest.php
  • tests/admin/Unit/Support/Forms/AttributeConverters/DropdownConverterTest.php

@tazzytazzy
Copy link
Copy Markdown
Contributor Author

I slimmed down the changes in #2443 to be just the PR. Some reason, i added fixes for other things that should have been seperated PRs. I'll start creating those now.

@alecritson
Copy link
Copy Markdown
Collaborator

Thanks @tazzytazzy

I noticed on the attribute editing screen that if you try and edit a dropdown attribute the options appear as empty

image

Not sure if related to this PR specifically however I feel like it might be useful to investigate as part of this PR.

@tazzytazzy
Copy link
Copy Markdown
Contributor Author

tazzytazzy commented Apr 14, 2026

Yea. I had a patch to that, but then when i cleaned up my other PR, i think it was lost. I'll poke around and try to dig it up again. The issue when away from my side. I'll dig around my past local commits.

@tazzytazzy
Copy link
Copy Markdown
Contributor Author

Found it. Tested by adding, removing, trying to add duplicate rows, removing rows in the middle, etc.

I think a future feature would be nice to re-order the values. :-)

Also updated the tests, I'm hoping the updated test is valid.

Tests: 1 skipped, 769 passed (2815 assertions)
Duration: 193.48s

@alecritson alecritson merged commit 2e9d2e2 into lunarphp:1.x Apr 14, 2026
44 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in Roadmap Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants