Skip to content

Fix Policies automations filter disappearing for the Unassigned fleet#49224

Merged
nulmete merged 2 commits into
mainfrom
44624-policies-page-unexpected-automations-filter
Jul 13, 2026
Merged

Fix Policies automations filter disappearing for the Unassigned fleet#49224
nulmete merged 2 commits into
mainfrom
44624-policies-page-unexpected-automations-filter

Conversation

@nulmete

@nulmete nulmete commented Jul 13, 2026

Copy link
Copy Markdown
Member

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 file added for user-visible changes in changes/, orbit/changes/ or ee/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

  • Bug Fixes
    • Fixed the automations filter on the Policies page so it remains visible when viewing the Unassigned fleet.
    • Preserved the selected automation filter when switching views.
    • Updated available options for Unassigned fleets by excluding Calendar while retaining supported automation types.
    • Improved the empty-state experience when no policies match the selected filters.

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.
@nulmete nulmete marked this pull request as ready for review July 13, 2026 17:24
@nulmete nulmete requested a review from a team as a code owner July 13, 2026 17:24
Copilot AI review requested due to automatic review settings July 13, 2026 17:24
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 68.07%. Comparing base (65caf18) to head (d4cd5f2).
⚠️ Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
...policies/ManagePoliciesPage/ManagePoliciesPage.tsx 92.30% 1 Missing ⚠️
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              
Flag Coverage Δ
frontend 59.94% <92.30%> (+0.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 PolicyAutomationsFields behavior).
  • 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.

Comment on lines +23 to +27
const getFleetHandler = () =>
http.get(baseUrl("/fleets/:id"), ({ params }) => {
const fleet = { ...createMockConfig(), id: Number(params.id) };
return HttpResponse.json({ team: fleet, fleet });
});
Comment on lines +126 to +130
// 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();
});
Comment on lines +149 to +152
const control = document.querySelector(
".manage-policies-page__filter-automation-dropdown .react-select__control"
) as HTMLElement;
await user.click(control);
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

Walkthrough

The 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)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix for the Unassigned fleet automations filter bug.
Description check ✅ Passed The description includes the related issue, problem summary, checklist items, and testing notes.
Linked Issues check ✅ Passed [#44624] The UI logic and tests address the filter disappearing with a query param and the Unassigned fleet options.
Out of Scope Changes check ✅ Passed The changes stay focused on the policies filter fix, test coverage, and a changes file with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 44624-policies-page-unexpected-automations-filter

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 win

Exclude calendar from the Unassigned initial filter frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tsx:187-201
initialAutomationFilter still accepts automation_type=calendar for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 93fa75e and b07ac35.

📒 Files selected for processing (3)
  • changes/44624-policies-automations-filter-unassigned
  • frontend/pages/policies/ManagePoliciesPage/ManagePoliciesPage.tests.tsx
  • frontend/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)
@nulmete nulmete merged commit bfb0f29 into main Jul 13, 2026
25 checks passed
@nulmete nulmete deleted the 44624-policies-page-unexpected-automations-filter branch July 13, 2026 18:58
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.

Policies page: Unexpected automations filter behavior when there are no policies in a fleet

3 participants