Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade react-router to v6 #3337

Merged
merged 38 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
3c977e2
Upgrade react-router to v6
nickclyde Jan 21, 2022
1f24239
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 21, 2022
0cda207
Fix tests
nickclyde Jan 21, 2022
5007567
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 21, 2022
86e9268
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 24, 2022
6bb30ac
Code smells
nickclyde Jan 24, 2022
7997852
Fix various TypeScript errors
nickclyde Jan 24, 2022
b57c3c4
Add missing useEffect dependency
nickclyde Jan 24, 2022
3daf66c
Fix QueueItem storybook story
nickclyde Jan 24, 2022
4fe9c77
Undo stupid change where I confused path params with URL search params
nickclyde Jan 24, 2022
713319f
Forgot a few wildcards
nickclyde Jan 24, 2022
b60ef2d
Add test for Prompt
nickclyde Jan 24, 2022
45db92a
Fix <Navigate> to props in AccountCreationApp
nickclyde Jan 25, 2022
3a5e30c
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 25, 2022
414ab98
Make all navigation relative
nickclyde Jan 25, 2022
93a2988
Fix tests
nickclyde Jan 25, 2022
d0ad467
Use absolute paths in places where it makes more sense
nickclyde Jan 25, 2022
ce65cdc
A few navigation bugfixes
nickclyde Jan 25, 2022
66a434d
Code smells
nickclyde Jan 25, 2022
a2e0772
Add /reload-app path for reloading whoami query for TenantDataAccess
nickclyde Jan 25, 2022
33c7d5f
A little more test coverage for <Prompt>
nickclyde Jan 26, 2022
20256f8
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 26, 2022
6a3a4ab
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 27, 2022
fda9951
DRY up App component
nickclyde Jan 27, 2022
294d217
Apply style to active-nav-item class instead of using style prop
nickclyde Jan 27, 2022
594b6b6
Revert App changes
nickclyde Jan 27, 2022
7d43416
Merge branch 'main' into nick/upgrade-react-router
nickclyde Jan 28, 2022
008ed0e
Merge branch 'main' into nick/upgrade-react-router
nickclyde Feb 1, 2022
67789de
Merge branch 'main' into nick/upgrade-react-router
nickclyde Feb 2, 2022
090742e
Fix self-reg link bug
nickclyde Feb 2, 2022
f1be9fc
Fix patients pagination bug
nickclyde Feb 4, 2022
c4e0aa4
Fix facility form bug
nickclyde Feb 4, 2022
dbc6dea
Fix tests
nickclyde Feb 4, 2022
de4ded2
Add test for pagination on patients view
nickclyde Feb 4, 2022
2090d00
Move FacilityForm.test.tsx to proper directory
nickclyde Feb 4, 2022
093a59c
Merge branch 'main' into nick/upgrade-react-router
nickclyde Feb 4, 2022
1afbec1
Fix settings nav bug
nickclyde Feb 4, 2022
7ab6b91
Merge branch 'main' into nick/upgrade-react-router
nickclyde Feb 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions frontend/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,26 +173,28 @@ const App = () => {
/>
}
/>
<Route
path="patients/:pageNumber"
element={
<ProtectedRoute
requiredPermissions={canViewPeople}
userPermissions={data.whoami.permissions}
element={<ManagePatientsContainer />}
/>
}
/>
<Route
path="patients"
element={
<ProtectedRoute
requiredPermissions={canViewPeople}
userPermissions={data.whoami.permissions}
element={<ManagePatientsContainer />}
/>
}
/>
<Route path="patients">
<Route
path=":pageNumber"
element={
<ProtectedRoute
requiredPermissions={canViewPeople}
userPermissions={data.whoami.permissions}
element={<ManagePatientsContainer />}
/>
}
/>
<Route
path=""
element={
<ProtectedRoute
requiredPermissions={canViewPeople}
userPermissions={data.whoami.permissions}
element={<ManagePatientsContainer />}
/>
}
/>
</Route>
<Route
path="patient/:patientId"
element={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { ToastContainer } from "react-toastify";

import * as clia from "../utils/clia";
import * as state from "../utils/state";
import * as smartyStreets from "../utils/smartyStreets";
import * as clia from "../../utils/clia";
import * as state from "../../utils/state";
import * as smartyStreets from "../../utils/smartyStreets";

import FacilityForm from "./Facility/FacilityForm";
import FacilityForm from "./FacilityForm";

import "../../i18n";
import "../../../i18n";

let saveFacility: jest.Mock;

Expand Down
21 changes: 13 additions & 8 deletions frontend/src/app/Settings/Facility/FacilityFormContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import userEvent from "@testing-library/user-event";
import { MockedProvider } from "@apollo/client/testing";
import { Provider } from "react-redux";
import { MemoryRouter } from "react-router-dom";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import configureStore from "redux-mock-store";

import { getAppInsights } from "../../TelemetryService";
Expand Down Expand Up @@ -185,13 +185,18 @@ describe("FacilityFormContainer", () => {
trackEvent: trackEventMock,
}));
render(
<MemoryRouter>
<Provider store={store}>
<MockedProvider mocks={mocks}>
<FacilityFormContainer facilityId={mockFacility.id} />
</MockedProvider>
</Provider>
</MemoryRouter>
<Provider store={store}>
<MockedProvider mocks={mocks}>
<MemoryRouter initialEntries={[`/facility/${mockFacility.id}`]}>
<Routes>
<Route
path="facility/:facilityId"
element={<FacilityFormContainer />}
/>
</Routes>
</MemoryRouter>
</MockedProvider>
</Provider>
);
});

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/app/Settings/Facility/FacilityFormContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from "react";
import { gql, useQuery, useMutation } from "@apollo/client";
import { Navigate } from "react-router-dom";
import { Navigate, useParams } from "react-router-dom";
import { useDispatch } from "react-redux";

import { updateFacility } from "../../store";
Expand Down Expand Up @@ -158,11 +158,11 @@ export const ADD_FACILITY_MUTATION = gql`
`;

interface Props {
facilityId: string;
newOrg?: boolean;
}

const FacilityFormContainer: any = (props: Props) => {
const { facilityId } = useParams();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason why is this being grabed from query params and not the props

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So in that case, the uuid after /facility is the id of the facility being edited in the form, whereas the facility query param refers to the currently selected facility in the nav bar. We want the id from the url params because that's the one we actually want to edit in the form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, I wish it was a bit clearer which facility is which, but that could be addressed in a future refactor.

const { data, loading, error } = useQuery<FacilityData, {}>(
GET_FACILITY_QUERY,
{
Expand Down Expand Up @@ -199,12 +199,12 @@ const FacilityFormContainer: any = (props: Props) => {
appInsights.trackEvent({ name: "Save Settings" });
}
const provider = facility.orderingProvider;
const saveFacilityMutation = props.facilityId
const saveFacilityMutation = facilityId
? updateFacilityMutation
: addFacilityMutation;
const savedFacility = await saveFacilityMutation({
variables: {
facilityId: props.facilityId,
facilityId,
testingFacilityName: facility.name,
cliaNumber: facility.cliaNumber,
street: facility.street,
Expand Down Expand Up @@ -249,7 +249,7 @@ const FacilityFormContainer: any = (props: Props) => {

const getFacilityData = (): Facility => {
const facility = data.organization.testingFacility.find(
(f) => f.id === props.facilityId
(f) => f.id === facilityId
);
if (facility) {
return facility;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { render, screen, act } from "@testing-library/react";
import { MockedProvider } from "@apollo/client/testing";
import { Provider } from "react-redux";
import { MemoryRouter } from "react-router-dom";
import { MemoryRouter, Route, Routes } from "react-router-dom";
import configureStore from "redux-mock-store";

import { GetManagedFacilitiesDocument } from "../../../generated/graphql";
Expand Down Expand Up @@ -130,13 +130,18 @@ const mock = [
describe("ManageFacilitiesContainer", () => {
beforeEach(() => {
render(
<MemoryRouter>
<Provider store={store}>
<MockedProvider mocks={mock}>
<ManageFacilitiesContainer />
</MockedProvider>
</Provider>
</MemoryRouter>
<Provider store={store}>
<MockedProvider mocks={mock}>
<MemoryRouter initialEntries={["/facilities"]}>
<Routes>
<Route
path="facilities"
element={<ManageFacilitiesContainer />}
/>
</Routes>
</MemoryRouter>
</MockedProvider>
</Provider>
);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { useQuery, gql } from "@apollo/client";

import { getUrl } from "../utils/url";

import { ManageSelfRegistrationLinks } from "./ManageSelfRegistrationLinks";

type Data = {
Expand Down Expand Up @@ -55,7 +57,7 @@ export const ManageSelfRegistrationLinksContainer = () => {

return (
<ManageSelfRegistrationLinks
baseUrl={process.env.REACT_APP_BASE_URL || ""}
baseUrl={getUrl() || ""}
organizationSlug={organizationSlug}
facilitySlugs={facilitySlugs}
howItWorksPath="/using-simplereport/manage-people-you-test/self-registration"
Expand Down
10 changes: 3 additions & 7 deletions frontend/src/app/Settings/Settings.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route, Routes, useParams } from "react-router-dom";
import { Route, Routes } from "react-router-dom";

import { useDocumentTitle } from "../utils/hooks";

Expand All @@ -11,7 +11,6 @@ import { ManageSelfRegistrationLinksContainer } from "./ManageSelfRegistrationLi

const Settings = () => {
useDocumentTitle("Settings");
const { facilityId } = useParams();

return (
<main className="prime-home">
Expand All @@ -21,12 +20,9 @@ const Settings = () => {
<Route path="facilities" element={<ManageFacilitiesContainer />} />
<Route
path="facility/:facilityId"
element={<FacilityFormContainer facilityId={facilityId} />}
/>
<Route
path="add-facility/"
element={<FacilityFormContainer facilityId={facilityId} />}
element={<FacilityFormContainer />}
/>
<Route path="add-facility" element={<FacilityFormContainer />} />
<Route
path="organization"
element={<ManageOrganizationContainer />}
Expand Down
Loading