Skip to content

Commit

Permalink
Fix incorrect type query param types
Browse files Browse the repository at this point in the history
  • Loading branch information
karuhanga committed May 16, 2020
1 parent b081470 commit 8499d39
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
9 changes: 7 additions & 2 deletions src/apps/concepts/pages/CreateOrEditConceptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
ProgressOverlay,
useAnchor,
usePrevious,
useQuery
useQueryParams
} from "../../../utils";
import { CONTEXT } from "../constants";
import {
Expand All @@ -48,6 +48,11 @@ interface Props {
progress?: string;
}

interface ConceptPageQueryParams {
conceptClass: string;
linkedDictionary: string;
}

const CreateOrEditConceptPage: React.FC<Props> = ({
retrieveConcept,
concept,
Expand All @@ -62,7 +67,7 @@ const CreateOrEditConceptPage: React.FC<Props> = ({
}) => {
const { pathname: url } = useLocation();
const { concept: conceptId } = useParams();
const { conceptClass, linkedDictionary } = useQuery();
const { conceptClass, linkedDictionary } = useQueryParams<ConceptPageQueryParams>();
const previouslyLoading = usePrevious(loading);
const [menuAnchor, handleMenuClick, handleMenuClose] = useAnchor();

Expand Down
4 changes: 2 additions & 2 deletions src/apps/concepts/pages/ViewConceptPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "../../authentication";
import { orgsSelector } from "../../authentication/redux/reducer";
import { CONTEXT } from "../constants";
import { ProgressOverlay, useQuery } from "../../../utils";
import { ProgressOverlay, useQueryParams } from "../../../utils";

interface Props {
loading: boolean;
Expand All @@ -48,7 +48,7 @@ const ViewConceptPage: React.FC<Props> = ({
ownerType: string;
owner: string;
}>();
const { linkedDictionary, linkedSource } = useQuery();
const { linkedDictionary, linkedSource } = useQueryParams();

// we can modify the concept and it lives in our dictionary's linked source
const showEditButton =
Expand Down
6 changes: 3 additions & 3 deletions src/apps/concepts/pages/ViewConceptsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
CONCEPT_CLASSES,
PREFERRED_SOURCES,
useAnchor,
useQuery
useQueryParams
} from "../../../utils";
import qs from "qs";
import { ProgressOverlay } from "../../../utils/components";
Expand Down Expand Up @@ -115,7 +115,7 @@ const ViewConceptsPage: React.FC<Props> = ({
ownerType: string;
owner: string;
}>();
const { linkedSource, preferredSource } = useQuery(); // only relevant when using collection container
const { linkedSource, preferredSource } = useQueryParams(); // only relevant when using collection container

const [addNewAnchor, handleAddNewClick, handleAddNewClose] = useAnchor();
const [customAnchor, handleCustomClick, handleCustomClose] = useAnchor();
Expand All @@ -130,7 +130,7 @@ const ViewConceptsPage: React.FC<Props> = ({
handleSwitchSourceClose
] = useAnchor();

const queryParams: QueryParams = useQuery();
const queryParams: QueryParams = useQueryParams();
const {
page = 1,
sortDirection = "sortAsc",
Expand Down
4 changes: 2 additions & 2 deletions src/apps/dictionaries/components/ViewDictionariesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from "react";
import { APIDictionary } from "../types";
import { ProgressOverlay } from "../../../utils/components";
import { useQuery } from "../../../utils";
import { useQueryParams } from "../../../utils";
import { useHistory, useLocation } from "react-router";
import qs from "qs";
import ViewDictionaries from "../components/ViewDictionaries";
Expand Down Expand Up @@ -32,7 +32,7 @@ const ViewPublicDictionariesPage: React.FC<Props> = ({
const { pathname: url } = useLocation();
const { num_found: numFound = dictionaries.length } = meta;

const queryParams: { page?: number; q?: string } = useQuery();
const queryParams: { page?: number; q?: string } = useQueryParams();
const { page = 1, q: initialQ = "" } = queryParams;

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/apps/dictionaries/pages/AddBulkConceptsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { recursivelyAddConceptsToDictionaryAction } from "../redux";
import { useLocation } from "react-router";
import { connect } from "react-redux";
import { PREFERRED_SOURCES, useAnchor, useQuery } from "../../../utils";
import { PREFERRED_SOURCES, useAnchor, useQueryParams } from "../../../utils";
import Header from "../../../components/Header";
import { Link } from "react-router-dom";

Expand All @@ -38,7 +38,7 @@ interface Props {
const AddBulkConceptsPage: React.FC<Props> = ({ addConceptsToDictionary }) => {
const classes = useStyles();
const { pathname: url } = useLocation();
const { fromSource } = useQuery();
const { fromSource } = useQueryParams();

const [
switchSourceAnchor,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export function usePrevious(value: any) {
return ref.current;
}

export function useQuery() {
return qs.parse(useLocation().search, { ignoreQueryPrefix: true });
export function useQueryParams<QueryParamsType>(): QueryParamsType {
return qs.parse(useLocation().search, {ignoreQueryPrefix: true}) as unknown as QueryParamsType;
}

export function useAnchor(): [
Expand Down

0 comments on commit 8499d39

Please sign in to comment.