From f567265cb3ef92294cde5ac0cbb4a3112e7d6d21 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Thu, 11 Jan 2024 13:50:22 -0500 Subject: [PATCH] :bug: Broken search string when navigating from deps page Signed-off-by: ibolton336 --- .../src/app/layout/SidebarApp/SidebarApp.tsx | 15 +++------------ .../applications-table/applications-table.tsx | 10 +++++++++- .../app/pages/dependencies/dependencies.tsx | 18 +++++++++++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/client/src/app/layout/SidebarApp/SidebarApp.tsx b/client/src/app/layout/SidebarApp/SidebarApp.tsx index 699a48c38e..dcabacf316 100644 --- a/client/src/app/layout/SidebarApp/SidebarApp.tsx +++ b/client/src/app/layout/SidebarApp/SidebarApp.tsx @@ -77,26 +77,17 @@ export const SidebarApp: React.FC = () => { {selectedPersona === PersonaKey.MIGRATION ? ( - + {t("sidebar.applicationInventory")} - + {t("sidebar.archetypes")} - + {t("sidebar.reports")} diff --git a/client/src/app/pages/applications/applications-table/applications-table.tsx b/client/src/app/pages/applications/applications-table/applications-table.tsx index 13d6b52ffe..de45d031ae 100644 --- a/client/src/app/pages/applications/applications-table/applications-table.tsx +++ b/client/src/app/pages/applications/applications-table/applications-table.tsx @@ -515,6 +515,14 @@ export const ApplicationsTable: React.FC = () => { selectionState: { selectedItems: selectedRows }, } = tableControls; + const clearFilters = () => { + const currentPath = history.location.pathname; + const newSearch = new URLSearchParams(history.location.search); + newSearch.delete("filters"); + history.push(`${currentPath}`); + filterToolbarProps.setFilterValues({}); + }; + const [ saveApplicationsCredentialsModalState, setSaveApplicationsCredentialsModalState, @@ -732,7 +740,7 @@ export const ApplicationsTable: React.FC = () => { backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", }} > - + {...filterToolbarProps} /> diff --git a/client/src/app/pages/dependencies/dependencies.tsx b/client/src/app/pages/dependencies/dependencies.tsx index 4c4d347656..f05e95c595 100644 --- a/client/src/app/pages/dependencies/dependencies.tsx +++ b/client/src/app/pages/dependencies/dependencies.tsx @@ -17,6 +17,7 @@ import { useTableControlState, useTableControlProps, getHubRequestParams, + deserializeFilterUrlParams, } from "@app/hooks/table-controls"; import { TablePersistenceKeyPrefix, UI_UNIQUE_ID } from "@app/Constants"; import { SimplePagination } from "@app/components/SimplePagination"; @@ -30,6 +31,7 @@ import { useSelectionState } from "@migtools/lib-ui"; import { DependencyAppsDetailDrawer } from "./dependency-apps-detail-drawer"; import { useSharedAffectedApplicationFilterCategories } from "../issues/helpers"; import { getParsedLabel } from "@app/utils/rules-utils"; +import { useHistory } from "react-router-dom"; export const Dependencies: React.FC = () => { const { t } = useTranslation(); @@ -37,6 +39,10 @@ export const Dependencies: React.FC = () => { const allAffectedApplicationsFilterCategories = useSharedAffectedApplicationFilterCategories(); + const urlParams = new URLSearchParams(window.location.search); + const filters = urlParams.get("filters"); + const deserializedFilterValues = deserializeFilterUrlParams({ filters }); + const tableControlState = useTableControlState({ persistTo: "urlParams", persistenceKeyPrefix: TablePersistenceKeyPrefix.dependencies, @@ -46,6 +52,7 @@ export const Dependencies: React.FC = () => { provider: "Language", labels: "Labels", }, + initialFilterValues: deserializedFilterValues, isFilterEnabled: true, isSortEnabled: true, isPaginationEnabled: true, @@ -122,6 +129,15 @@ export const Dependencies: React.FC = () => { activeItemDerivedState: { activeItem, clearActiveItem }, } = tableControls; + const history = useHistory(); + + const clearFilters = () => { + const currentPath = history.location.pathname; + const newSearch = new URLSearchParams(history.location.search); + newSearch.delete("filters"); + history.push(`${currentPath}`); + }; + return ( <> @@ -135,7 +151,7 @@ export const Dependencies: React.FC = () => { backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", }} > - +