fix(ui): relationship filter duplicate options when switching operators#16029
fix(ui): relationship filter duplicate options when switching operators#16029howwohmm wants to merge 3 commits into
Conversation
The `reduceToIDs` helper in the relationship filter's optionsReducer read `option.id`, but options are created with `value` (not `id`). This meant deduplication never worked — `loadedIDs` was always an array of `undefined` values. When switching from `equals` to `is_in`, the second useEffect called `addOptionByID` for the already-loaded value, and because dedup was broken the same option was appended again. Fix: read `option.value` instead of `option.id` so existing options are correctly recognised and skipped. Fixes payloadcms#15947 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
themavik
left a comment
There was a problem hiding this comment.
Clean fix. The root cause makes sense — option.id was always undefined since options are created with { label, value }, so deduplication via indexOf never matched anything. Switching to option.value should handle that correctly.
themavik
left a comment
There was a problem hiding this comment.
nit: if any relationship option objects still only populate id and leave value unset, dedupe will silently skip them after this change—worth matching whatever shape Option guarantees.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
good catch @themavik — pushed a fix to use |
|
@howwohmm I think we should add an e2e test that fails without this fix and then passes when this fix is implemented. Can you do this? |
Tests verify that ADD correctly deduplicates options by value — both for
single-relation flat lists and multi-relation grouped options.
The dedup test would fail with the original `option.id` read (always
undefined on `{ label, value }` options) and passes with `option.value ?? option.id`.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
added a vitest unit test in
the dedup test fails with the original |
|
@howwohmm Looks like you archived the fork. Do you want to revive it? I opened another PR that included your fixes and some changes I had. Let me know! |
…rs (#16204) Fixes #15947 ## Summary - Fixes duplicate options appearing in relationship filter dropdowns when switching operators - The `reduceToIDs` function was incorrectly using `option.id` (which doesn't exist on the Option type) instead of `option.value` for deduplication ## Test plan - [x] Unit tests added for optionsReducer deduplication logic - [x] E2E test added that verifies no duplicate options when switching operators Continuation from #16029 which was from a fork of payload that was archived. Co-authored-by: https://github.com/howwohmm --------- Co-authored-by: OM MISHRA <152969928+howwohmm@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|
Closing, merged in #16204 |
…rs (payloadcms#16204) Fixes payloadcms#15947 ## Summary - Fixes duplicate options appearing in relationship filter dropdowns when switching operators - The `reduceToIDs` function was incorrectly using `option.id` (which doesn't exist on the Option type) instead of `option.value` for deduplication ## Test plan - [x] Unit tests added for optionsReducer deduplication logic - [x] E2E test added that verifies no duplicate options when switching operators Continuation from payloadcms#16029 which was from a fork of payload that was archived. Co-authored-by: https://github.com/howwohmm --------- Co-authored-by: OM MISHRA <152969928+howwohmm@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Summary
equalstois in)reduceToIDsinoptionsReducer.tsreadoption.id, but options are created with{ label, value }— there is noidproperty. This meant deduplication never worked:loadedIDswas always[undefined, undefined, ...], soindexOf(doc.id)always returned-1.option.idtooption.valueinreduceToIDsso existing options are correctly recognised and skipped.Fixes #15947
Test plan
equalsoperator and pick a valueis inhasMultipleRelations(polymorphic relationship) to verify grouped options also deduplicate correctly🤖 Generated with Claude Code