forked from pinpoint-apm/pinpoint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#noissue] Save last application, searchParameters to atom
- Loading branch information
1 parent
dc58c9b
commit a2e7b81
Showing
4 changed files
with
39 additions
and
3 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
12 changes: 12 additions & 0 deletions
12
web-frontend/src/main/v3/packages/ui/src/atoms/searchParameters.ts
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,12 @@ | ||
import { atom } from 'jotai'; | ||
import { ApplicationType } from '@pinpoint-fe/ui/src/constants'; | ||
|
||
export const searchParametersAtom = atom<{ | ||
application: ApplicationType; | ||
searchParameters: { | ||
[k: string]: string; | ||
}; | ||
}>({ | ||
application: {} as ApplicationType, | ||
searchParameters: {}, | ||
}); |
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
10 changes: 9 additions & 1 deletion
10
web-frontend/src/main/v3/packages/ui/src/hooks/searchParameters/useSearchParameters.ts
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import { useLocation } from 'react-router-dom'; | ||
import { getApplicationTypeAndName } from '@pinpoint-fe/ui/src/utils'; | ||
import { useAtomValue } from 'jotai'; | ||
import { searchParametersAtom } from '@pinpoint-fe/ui/src/atoms'; | ||
|
||
export const useSearchParameters = () => { | ||
const props = useLocation(); | ||
const atomSearchParameters = useAtomValue(searchParametersAtom); | ||
|
||
const searchParameters = Object.fromEntries(new URLSearchParams(props.search)); | ||
const application = getApplicationTypeAndName(props.pathname); | ||
|
||
return { ...props, searchParameters, application }; | ||
return { | ||
...props, | ||
searchParameters: application ? searchParameters : atomSearchParameters?.searchParameters, | ||
application: application || atomSearchParameters?.application, | ||
}; | ||
}; |