Fix Policies automations filter disappearing for the Unassigned fleet#49224
Conversation
The automations filter's option list incorrectly restricted the "Unassigned" fleet (team ID 0) to the same webhook/ticket-only subset used for "All fleets" (team ID undefined), since 0 is falsy. Unassigned supports every automation type except calendar events, so the filter now offers the full set (minus calendar) for it.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #49224 +/- ##
==========================================
+ Coverage 67.99% 68.07% +0.08%
==========================================
Files 3768 3779 +11
Lines 239064 239090 +26
Branches 12615 12609 -6
==========================================
+ Hits 162554 162772 +218
+ Misses 61746 61554 -192
Partials 14764 14764
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Warning
- Copilot's review of this pull request may be incomplete because some of the changed files are excluded by your Copilot content exclusion settings. See Excluding content from Copilot for details.
Pull request overview
Fixes an edge case on the Policies > Manage page where switching to the Unassigned fleet (API team ID 0) could cause the automations filter dropdown to collapse to the restricted “All fleets” option set because 0 was treated as falsy, making the selected filter appear to disappear.
Changes:
- Update automations filter option filtering to distinguish All fleets (
teamIdForApi === undefined) from Unassigned (teamIdForApi === API_NO_TEAM_ID). - For Unassigned, allow all automation types except Calendar (consistent with
PolicyAutomationsFieldsbehavior). - Add frontend tests covering “sticky” automation filter behavior and Unassigned option availability.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx | Fixes option filtering logic so Unassigned (0) isn’t treated like All fleets (undefined), preventing the dropdown from collapsing incorrectly. |
| frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tests.tsx | Adds regression tests for sticky filter visibility and Unassigned option set (excluding Calendar). |
| changes/44624-policies-automations-filter-unassigned | Changes entry for release notes (content excluded from review by policy). |
Files excluded by content exclusion policy (1)
- changes/44624-policies-automations-filter-unassigned
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const getFleetHandler = () => | ||
| http.get(baseUrl("/fleets/:id"), ({ params }) => { | ||
| const fleet = { ...createMockConfig(), id: Number(params.id) }; | ||
| return HttpResponse.json({ team: fleet, fleet }); | ||
| }); |
| // Per the fix for #44624: when a filter is present in the query params, | ||
| // the automations filter dropdown must remain visible (and reflect the | ||
| // selected filter) even though this fleet has zero policies. | ||
| expect(screen.getByText("Software")).toBeInTheDocument(); | ||
| }); |
| const control = document.querySelector( | ||
| ".manage-policies-page__filter-automation-dropdown .react-select__control" | ||
| ) as HTMLElement; | ||
| await user.click(control); |
|
Caution Review failedAn error occurred during the review process. Please try again later. WalkthroughThe Policies page automation filter now handles three fleet contexts: all fleets, the unassigned fleet, and specific fleets. All fleets show only “All” and “Other” options, the unassigned fleet excludes “Calendar,” and specific fleets retain the full option set. Tests cover empty fleets with URL-selected filters and unassigned fleets with filter persistence and option availability. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx (1)
187-201: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winExclude
calendarfrom the Unassigned initial filterfrontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx:187-201
initialAutomationFilterstill acceptsautomation_type=calendarfor Unassigned, but that option is removed from the dropdown there. Since fleet changes keep the query param, the page can land on a selected value that no longer exists in the option list. Match the initial validation to the Unassigned option set.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx` around lines 187 - 201, Update initialAutomationFilter validation to use the Unassigned automation option set that excludes calendar when isAllTeamsSelected is false. Preserve GLOBAL_AUTOMATION_TYPES for all-teams selection and return null for calendar or any other value absent from the active dropdown options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx`:
- Around line 187-201: Update initialAutomationFilter validation to use the
Unassigned automation option set that excludes calendar when isAllTeamsSelected
is false. Preserve GLOBAL_AUTOMATION_TYPES for all-teams selection and return
null for calendar or any other value absent from the active dropdown options.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 251ea4ad-9756-44d5-b47f-e7083d0d9982
📒 Files selected for processing (3)
changes/44624-policies-automations-filter-unassignedfrontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tests.tsxfrontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx
- Mocked fleet response now includes a name field to match ILoadTeamResponse - Test asserts the filter control isn't left disabled, not just that its label renders - Replace an unsafe querySelector cast with a helper that throws on a missing element - Extract getValidAutomationTypesForTeam() as the single source of truth for which automation types are valid per fleet, shared by both the initial query param validation and the dropdown's option list, so they can't drift out of sync (calendar was excluded from the dropdown but still accepted by validation)
Related issue: Resolves #44624
Switching to the "Unassigned" fleet with an automation filter already set kept the filter's value in the URL, but the filter dropdown's option list silently collapsed to only "All automations" and "Webhooks or tickets" — the same restricted set used for "All fleets" — because the "Unassigned" fleet's team ID (0) is falsy and was treated the same as the undefined team ID used for "All fleets". This made the filter appear to disappear from the UI.
Checklist for submitter
changes/,orbit/changes/oree/fleetd-chrome/changes.See Changes files for more information.
Testing
Added/updated automated tests
QA'd all new/changed functionality manually
Before (issue's video)
586646286-440cb26e-4fa7-4c5e-9050-cb5fd755431b.mov
After
Screen.Recording.2026-07-13.at.2.23.10.PM.mov
Summary by CodeRabbit