-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds selected filters in the url as a query parameter
This patch updates url based on the selected filters, search query and sort by Signed-off-by: Shiv Verma <shverma@redhat.com>
- Loading branch information
1 parent
c302526
commit 9125fa3
Showing
14 changed files
with
279 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export enum Params { | ||
Query = 'query', | ||
SortBY = 'sortBy', | ||
Category = 'category', | ||
Kind = 'kind', | ||
Catalog = 'catalog' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { when } from 'mobx'; | ||
import { FakeHub } from '../../api/testutil'; | ||
import { createProviderAndStore } from '../../store/root'; | ||
|
||
const TESTDATA_DIR = `src/store/testdata`; | ||
const api = new FakeHub(TESTDATA_DIR); | ||
const { root } = createProviderAndStore(api); | ||
|
||
describe('ParseUrl component', () => { | ||
it('it can set url params to resource store', (done) => { | ||
const { resources } = root; | ||
when( | ||
() => { | ||
return !resources.isLoading; | ||
}, | ||
() => { | ||
resources.setURLParams('?/query=ansible'); | ||
expect(resources.urlParams).toBe('?/query=ansible'); | ||
|
||
done(); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React from 'react'; | ||
import { useMst } from '../../store/root'; | ||
import { Params } from '../../common/params'; | ||
|
||
const ParseUrl: React.FC = () => { | ||
const { resources } = useMst(); | ||
|
||
if (window.location.search) { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
if (searchParams.has(Params.Query)) { | ||
resources.setSearch(searchParams.get(Params.Query)); | ||
} | ||
if (searchParams.has(Params.SortBY)) { | ||
resources.setSortBy(searchParams.get(Params.SortBY)); | ||
} | ||
|
||
// Storing url params to store inorder to parse the url only after successfully resource load | ||
resources.setURLParams(window.location.search); | ||
} | ||
|
||
return <> </>; | ||
}; | ||
export default ParseUrl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.