Skip to content

🐛 Fixed second label filter creating duplicate filters on each toggle#27764

Merged
rob-ghost merged 2 commits intomainfrom
fix/ber-3591-adding-a-second-label-filter-does-not-work
May 7, 2026
Merged

🐛 Fixed second label filter creating duplicate filters on each toggle#27764
rob-ghost merged 2 commits intomainfrom
fix/ber-3591-adding-a-second-label-filter-does-not-work

Conversation

@rob-ghost
Copy link
Copy Markdown
Contributor

@rob-ghost rob-ghost commented May 7, 2026

ref https://linear.app/ghost/issue/BER-3591/adding-a-second-label-filter-does-not-work

Problem

In the React members list, opening the filter popover and picking "Label" (or any multiselect field) opened an inline multi-select picker that stayed open after each click and spawned a new filter on every commit. Picking a single value worked correctly, but the picker invited the user to click more — and each additional click left a stranded filter behind with stale single-value selections, while a fresh filter was created with the latest cumulative selection.

The same code path applied to every multiselect field in the members filter: label, tier_id (Membership tier), and offer_redemptions (Offer).

Solution

The add-filter inline picker is now always single-pick: pick one value → commit a new single-value filter → close. Multi-value editing is the responsibility of the filter row's own picker (LabelFilterRenderer for label, non-inline SelectOptionsPopover for tier/offer), which already supports live multi-select with count updates.

While in the area, several allowMultiple branches were either unreachable in production or redundant after the unified picker behaviour, so they were cleaned up:

  • The "update existing filter" branch in addFilterWithOption was unreachable. Audited all three consumers: members uses allowMultiple=true (skips that branch), comments only has select fields (closes after one pick), stats's only multiselect field sets autoCloseOnSelect: true (same effect). Removed.
  • Dropped the closePopover parameter — every commit now closes the popover.
  • Dropped the shouldClosePopover conditional and the dead addFilter pre-populate that read from a hidden field.

After the cleanup, allowMultiple does exactly one thing: gates whether fields with an existing filter are hidden from the "Add filter" field list (members shows them so users can stack same-field filters; comments and stats hide them so users get one filter per field). All other behaviour is uniform across both modes.

Test plan

  • Unit test in apps/shade/test/unit/components/ui/filters.test.tsx covering the add-filter flow with allowMultiple={true}
  • Manual verification in browser for all three multiselect fields:
    • label — pick Blue Consultant, then add second filter Lime Orchestrator → 2 separate filters; chip dropdown adds Magenta to filter 2 in place
    • tier_id — pick Silver, then add second filter Gold → 2 separate filters; chip dropdown adds Bronze to filter 2 in place
    • offer_redemptions — pick Black Friday, then add second filter Free Trial → 2 separate filters
  • Manual verification of allowMultiple={false} consumers:
    • Comments — picking Status → Published commits one filter, picker closes; "Add filter" no longer offers Status
  • pnpm --filter=@tryghost/shade test (213 passing)
  • pnpm --filter=@tryghost/posts test (165 passing)
  • pnpm --filter=@tryghost/shade lint

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5f907265-96a7-433a-a2b4-e0942beee511

📥 Commits

Reviewing files that changed from the base of the PR and between 8b318e3 and 8012348.

📒 Files selected for processing (2)
  • apps/shade/src/components/features/filters/filters.tsx
  • apps/shade/test/unit/components/ui/filters.test.tsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/shade/test/unit/components/ui/filters.test.tsx
  • apps/shade/src/components/features/filters/filters.tsx

Walkthrough

This PR changes Filters so opening the inline options picker for select/multiselect clears temporary selections, the popover renders multiselect fields as single-select, and each option click immediately commits a new Filter entry and closes the popover. Tests add a MultiselectTestFilters wrapper and assert two sequential option selections produce two committed filters and that the picker closes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main fix: preventing duplicate filters when toggling a second label filter in the multiselect flow.
Description check ✅ Passed The description thoroughly explains the problem, solution, and testing approach for the bug fix addressing multiselect field behavior in the add-filter flow.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ber-3591-adding-a-second-label-filter-does-not-work

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@rob-ghost rob-ghost marked this pull request as ready for review May 7, 2026 12:48
rob-ghost added 2 commits May 7, 2026 14:40
ref https://linear.app/ghost/issue/BER-3591/adding-a-second-label-filter-does-not-work

The add-filter inline picker rendered multiselect fields (label, tier_id,
offer_redemptions) as a sticky multi-select that stayed open after each
click. Selecting a single value worked, but the open picker invited extra
clicks, and each additional click left a stranded filter behind with stale
single-value selections while a fresh filter was created with the latest
cumulative selection. In multi-filter mode (allowMultiple={true}) the
picker now treats multiselect fields as single-select: one click commits a
new single-value filter and closes the picker. Multi-value editing of an
existing filter continues through the filter row's own picker, which
already supports live multi-select. Single-filter mode is unchanged.
ref https://linear.app/ghost/issue/BER-3591/adding-a-second-label-filter-does-not-work

After the BER-3591 fix the inline "Add filter" picker is always single-pick
+ close, so several allowMultiple branches were unreachable in production
or made redundant by that unified behaviour.

- Dropped the "update existing filter" branch in addFilterWithOption.
  Audited all three consumers: members uses allowMultiple=true (skips the
  branch), comments only has select fields (closes after one pick), and
  stats's only multiselect field sets autoCloseOnSelect: true (same
  effect). The branch was unreachable.
- Dropped the closePopover parameter — every commit now closes the popover.
- Dropped the shouldClosePopover conditional and the redundant
  `allowMultiple &&` guard on the type-override at the picker call site.
- Removed a dead setTempSelectedValues pre-populate in addFilter that read
  from a field already hidden by the field-list filter.
- Tightened the surrounding comments.

After cleanup, allowMultiple does exactly one thing: gates whether fields
with an existing filter are hidden from the "Add filter" field list.
No behaviour change.
@rob-ghost rob-ghost force-pushed the fix/ber-3591-adding-a-second-label-filter-does-not-work branch from 8b318e3 to 8012348 Compare May 7, 2026 13:41
@rob-ghost rob-ghost merged commit 5f10577 into main May 7, 2026
41 checks passed
@rob-ghost rob-ghost deleted the fix/ber-3591-adding-a-second-label-filter-does-not-work branch May 7, 2026 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant