This repository has been archived by the owner on Jul 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
46 additions
and
35 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
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,34 @@ | ||
import Cookies from "js-cookie"; | ||
import { useLocation } from "react-router-dom"; | ||
import { INCLUDE_HIDDEN_PATCHES } from "constants/cookies"; | ||
import { PatchesInput } from "gql/generated/types"; | ||
import { useQueryParam } from "hooks/useQueryParam"; | ||
import { PatchPageQueryParams, ALL_PATCH_STATUS } from "types/patch"; | ||
import { getLimitFromSearch, getPageFromSearch } from "utils/url"; | ||
|
||
/** | ||
* usePatchesQueryParams is used alongside the Patches Page to transform URL state | ||
* to the input value to the patches field for the User and Project GQL type. | ||
* @returns - An object with all input values for the patches field except includeCommitQueue | ||
* and onlyCommitQueue | ||
*/ | ||
export const usePatchesQueryParams = (): Omit< | ||
Required<PatchesInput>, | ||
"includeCommitQueue" | "onlyCommitQueue" | ||
> => { | ||
const { search } = useLocation(); | ||
const [patchName] = useQueryParam<string>(PatchPageQueryParams.PatchName, ""); | ||
const [rawStatuses] = useQueryParam<string[]>( | ||
PatchPageQueryParams.Statuses, | ||
[] | ||
); | ||
const [hidden] = useQueryParam(PatchPageQueryParams.Hidden, false); | ||
const statuses = rawStatuses.filter((v) => v && v !== ALL_PATCH_STATUS); | ||
return { | ||
limit: getLimitFromSearch(search), | ||
includeHidden: hidden || Cookies.get(INCLUDE_HIDDEN_PATCHES) === "true", | ||
page: getPageFromSearch(search), | ||
patchName: `${patchName}`, | ||
statuses, | ||
}; | ||
}; |
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