Skip to content

Commit

Permalink
use queryparam initially, navigate to correct url
Browse files Browse the repository at this point in the history
  • Loading branch information
parkiino committed Jun 30, 2020
1 parent 1c078cf commit 604316a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { useState } from 'react';
import { useRouteMatch, Switch, Route } from 'react-router-dom';
import { useRouteMatch, Switch, Route, useLocation, useHistory } from 'react-router-dom';
import { Props as EuiTabProps } from '@elastic/eui/src/components/tabs/tab';
import { i18n } from '@kbn/i18n';
import { PAGE_ROUTING_PATHS } from '../../../../constants';
Expand Down Expand Up @@ -114,7 +114,11 @@ function InstalledPackages() {

function AvailablePackages() {
useBreadcrumbs('integrations_all');
const [selectedCategory, setSelectedCategory] = useState('');
const history = useHistory();
const queryParams = new URLSearchParams(useLocation().search);
const initialCategory =
queryParams.get('category') !== null ? (queryParams.get('category') as string) : '';
const [selectedCategory, setSelectedCategory] = useState(initialCategory);
const { data: categoryPackagesRes, isLoading: isLoadingPackages } = useGetPackages({
category: selectedCategory,
});
Expand All @@ -141,7 +145,13 @@ function AvailablePackages() {
isLoading={isLoadingCategories}
categories={categories}
selectedCategory={selectedCategory}
onCategoryChange={({ id }: CategorySummaryItem) => setSelectedCategory(id)}
onCategoryChange={({ id }: CategorySummaryItem) => {
// clear category query param in the url
if (queryParams.get('category') !== null) {
history.push({});
}
setSelectedCategory(id);
}}
/>
) : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const OverviewEmptyComponent: React.FC = () => {
const { http, docLinks } = useKibana().services;
const basePath = http.basePath.get();
const { appId: ingestAppId, appPath: ingestPath, url: ingestUrl } = useHostIngestUrl(
'integrations'
'integrations?category=security'
);
const handleOnClick = useNavigateToAppEventHandler(ingestAppId, { path: ingestPath });

Expand Down

0 comments on commit 604316a

Please sign in to comment.