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

Admins can view submission history #3441

Merged
merged 7 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions frontend-react/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import GlobalContextProvider from "./components/GlobalContextProvider";
import { logout } from "./utils/UserUtils";
import TermsOfServiceForm from "./pages/tos-sign/TermsOfServiceForm";
import Spinner from "./components/Spinner";
import Submissions from "./pages/Submissions";

const OKTA_AUTH = new OktaAuth(oktaAuthConfig);

Expand Down Expand Up @@ -128,6 +129,11 @@ const App = () => {
authorize={PERMISSIONS.SENDER}
component={Upload}
/>
<AuthorizedRoute
path="/submissions"
authorize={PERMISSIONS.PRIME_ADMIN}
component={Submissions}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated but somewhat related, it appears that nav links aren't styled differently when active anymore. This might be solved when we're able to go to react-router 6.x.x since I know they deprecated activeClassName in favor of a new way of styling active links.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the react-router6 issue was related to okta's plugin that we use?
okta/okta-react#178

<SecureRoute
path="/report-details"
component={Details}
Expand Down
16 changes: 16 additions & 0 deletions frontend-react/src/components/header/ReportStreamHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ export const ReportStreamHeader = () => {
</NavLink>
);
}

if (permissionCheck(PERMISSIONS.PRIME_ADMIN, authState)) {
itemsMenu.splice(
1,
0,
<NavLink
to="/submissions"
key="submissions"
data-attribute="hidden"
hidden={true}
className="usa-nav__link"
>
<span>Submissions</span>
</NavLink>
);
}
}

return (
Expand Down
103 changes: 103 additions & 0 deletions frontend-react/src/pages/Submissions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { useState, Suspense } from "react";
import { Helmet } from "react-helmet";
import { NetworkErrorBoundary } from "rest-hooks";
import { useOktaAuth } from "@okta/okta-react";
import moment from "moment";

import { useOrgName } from "../utils/OrganizationUtils";
import { GLOBAL_STORAGE_KEYS } from "../components/GlobalContextProvider";

import { ErrorPage } from "./error/ErrorPage";

const OrgName = () => {
const orgName: string = useOrgName();
return (
<span id="orgName" className="text-normal text-base">
{orgName}
</span>
);
};

function Submissions() {
const { authState } = useOktaAuth();
const organization = localStorage.getItem(GLOBAL_STORAGE_KEYS.GLOBAL_ORG);
const [submissions, setSubmissions] = useState([]);

fetch(
`${process.env.REACT_APP_BACKEND_URL}/api/history/${organization}/submissions`,
{
headers: {
Authorization: `Bearer ${authState?.accessToken?.accessToken}`,
},
}
)
.then((res) => res.json())
.then((submissionJson) => {
setSubmissions(JSON.parse(submissionJson));
});

return (
<NetworkErrorBoundary
fallbackComponent={() => <ErrorPage type="page" />}
>
<Helmet>
<title>Submissions | {process.env.REACT_APP_TITLE}</title>
</Helmet>
<section className="grid-container margin-top-5">
<h3 className="margin-bottom-0">
<Suspense
fallback={
<span className="text-normal text-base">
Loading Info...
</span>
}
>
<OrgName />
</Suspense>
</h3>
<h1 className="margin-top-0 margin-bottom-0">COVID-19</h1>
</section>
<div className="grid-container usa-section margin-bottom-10">
<div className="grid-col-12">
<h2>Submissions</h2>
<table
className="usa-table usa-table--borderless prime-table"
aria-label="Submission history from the last 30 days"
Copy link
Contributor

Choose a reason for hiding this comment

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

nice aria-label

>
<thead>
<tr>
<th scope="col">Date/time submitted</th>
<th scope="col">File</th>
<th scope="col">Records</th>
<th scope="col">Report ID</th>
<th scope="col">Warnings</th>
</tr>
</thead>
<tbody id="tBody" className="font-mono-2xs">
{submissions.map((s, i) => {
return (
<tr key={"submission_" + i}>
<th scope="row">
{moment
.utc(s["createdAt"])
Copy link
Contributor

Choose a reason for hiding this comment

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

I have a general dislike of the moment library. It can be a bit heavy weight for what it does.

For example, this can be done like this with standard javascript:

console.log(new Intl.DateTimeFormat('en-US', {
  year: 'numeric', month: 'numeric', day: 'numeric',
  hour: 'numeric', minute: 'numeric', second: 'numeric',
}).format(new Date())); // 12/14/2021, 7:56:30 AM

But it's fine to leave it, just adding this comment for awareness.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like this. I used moment since that is what we use on the /daily-data page. I'll create a ticket to clean up uses of moment

.local()
.format("YYYY-MM-DD HH:mm")}
</th>
<th scope="row"></th> {/* File name */}
<th scope="row">
{s["reportItemCount"]}
</th>
<th scope="row">{s["id"]}</th>
<th scope="row">{s["warningCount"]}</th>
</tr>
);
})}
</tbody>
</table>
</div>
</div>
</NetworkErrorBoundary>
);
}

export default Submissions;