From d2b7f33af5bd1effbfdafa07629f354137e37ee4 Mon Sep 17 00:00:00 2001 From: RachelElysia <71795832+RachelElysia@users.noreply.github.com> Date: Thu, 18 Dec 2025 12:27:29 -0500 Subject: [PATCH] Fleet UI: Remove unsupported url params when switching to all teams (#37199) --- changes/37973-sw-filters | 1 + frontend/pages/SoftwarePage/SoftwarePage.tsx | 8 +++++++ .../SoftwareTable/SoftwareTable.tsx | 23 ++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 changes/37973-sw-filters diff --git a/changes/37973-sw-filters b/changes/37973-sw-filters new file mode 100644 index 0000000000..83fd0632de --- /dev/null +++ b/changes/37973-sw-filters @@ -0,0 +1 @@ +- Fleet UI: Software table viewing a team and switching to All teams will remove any unsupported url params for the All teams view diff --git a/frontend/pages/SoftwarePage/SoftwarePage.tsx b/frontend/pages/SoftwarePage/SoftwarePage.tsx index 61eccbd46a..83e067d9a3 100644 --- a/frontend/pages/SoftwarePage/SoftwarePage.tsx +++ b/frontend/pages/SoftwarePage/SoftwarePage.tsx @@ -103,6 +103,7 @@ interface ISoftwarePageProps { query: { team_id?: string; available_for_install?: string; + self_service?: string; vulnerable?: string; exploit?: string; min_cvss_score?: string; @@ -190,6 +191,13 @@ const SoftwarePage = ({ children, router, location }: ISoftwarePageProps) => { router, includeAllTeams: true, includeNoTeam: true, + // When switching to "All teams" context, remove any unsupported query params that might be set + overrideParamsOnTeamChange: { + available_for_install: (newTeamId: number | undefined) => + newTeamId === APP_CONTEXT_ALL_TEAMS_ID, + self_service: (newTeamId: number | undefined) => + newTeamId === APP_CONTEXT_ALL_TEAMS_ID, + }, }); // softwareConfig is either the global config or the team config of the diff --git a/frontend/pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTable.tsx b/frontend/pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTable.tsx index 8f5ac26e2e..74f255fc94 100644 --- a/frontend/pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTable.tsx +++ b/frontend/pages/SoftwarePage/SoftwareTitles/SoftwareTable/SoftwareTable.tsx @@ -134,11 +134,14 @@ const SoftwareTable = ({ page: changedParam === "pageIndex" ? newTableQuery.pageIndex : 0, ...buildSoftwareVulnFiltersQueryParams(vulnFilters), }; - if (softwareFilter === "installableSoftware") { - newQueryParam.available_for_install = true.toString(); - } - if (softwareFilter === "selfServiceSoftware") { - newQueryParam.self_service = true.toString(); + // Only include these filters when not on “All teams” + if (teamId !== undefined) { + if (softwareFilter === "installableSoftware") { + newQueryParam.available_for_install = "true"; + } + if (softwareFilter === "selfServiceSoftware") { + newQueryParam.self_service = "true"; + } } return newQueryParam; @@ -153,11 +156,8 @@ const SoftwareTable = ({ // reset the page index to 0 if any other param has changed. const changedParam = determineQueryParamChange(newTableQuery); - // if nothing has changed, don't update the route. this can happen when - // this handler is called on the inital render. Can also happen when - // the filter dropdown is changed. That is handled on the onChange handler - // for the dropdown. - if (changedParam === "") return; + // Note: There may be no changedParam on initial render, but we still may need + // to strip unwanted params with generateNewQueryParams so do NOT early return const newRoute = getNextLocationPath({ pathPrefix: currentPath, @@ -367,7 +367,8 @@ const SoftwareTable = ({ // additionalQueries serves as a trigger for the useDeepEffect hook // to fire onQueryChange for events happening outside of // the TableContainer. - // additionalQueries={softwareFilter} + // This is necessary to remove unwanted query params from the URL + additionalQueries={softwareFilter} customControl={showFilterHeaders ? renderCustomControls : undefined} customFiltersButton={ showFilterHeaders ? renderCustomFiltersButton : undefined