55 */
66
77import React , { useState } from 'react' ;
8- import { useRouteMatch , Switch , Route } from 'react-router-dom' ;
8+ import { useRouteMatch , Switch , Route , useLocation , useHistory } from 'react-router-dom' ;
99import { Props as EuiTabProps } from '@elastic/eui/src/components/tabs/tab' ;
1010import { i18n } from '@kbn/i18n' ;
1111import { PAGE_ROUTING_PATHS } from '../../../../constants' ;
@@ -114,7 +114,11 @@ function InstalledPackages() {
114114
115115function AvailablePackages ( ) {
116116 useBreadcrumbs ( 'integrations_all' ) ;
117- const [ selectedCategory , setSelectedCategory ] = useState ( '' ) ;
117+ const history = useHistory ( ) ;
118+ const queryParams = new URLSearchParams ( useLocation ( ) . search ) ;
119+ const initialCategory =
120+ queryParams . get ( 'category' ) !== null ? ( queryParams . get ( 'category' ) as string ) : '' ;
121+ const [ selectedCategory , setSelectedCategory ] = useState ( initialCategory ) ;
118122 const { data : categoryPackagesRes , isLoading : isLoadingPackages } = useGetPackages ( {
119123 category : selectedCategory ,
120124 } ) ;
@@ -141,7 +145,13 @@ function AvailablePackages() {
141145 isLoading = { isLoadingCategories }
142146 categories = { categories }
143147 selectedCategory = { selectedCategory }
144- onCategoryChange = { ( { id } : CategorySummaryItem ) => setSelectedCategory ( id ) }
148+ onCategoryChange = { ( { id } : CategorySummaryItem ) => {
149+ // clear category query param in the url
150+ if ( queryParams . get ( 'category' ) !== null ) {
151+ history . push ( { } ) ;
152+ }
153+ setSelectedCategory ( id ) ;
154+ } }
145155 />
146156 ) : null ;
147157
0 commit comments