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

[Justice Counts] Fix data entry form bug when navigating back from publish confirm page #148

Merged
merged 2 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 0 additions & 5 deletions publisher/src/components/Reports/DataEntryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,6 @@ const DataEntryForm: React.FC<{
[]
);

useEffect(() => {
/** Runs validation of previously saved inputs on load */
formStore.validatePreviouslySavedInputs(reportID);
}, [formStore, reportID]);

const saveUpdatedMetrics = async (metricKey?: string | undefined) => {
const updatedMetrics = formStore.reportUpdatedValuesForBackend(
reportID,
Expand Down
5 changes: 2 additions & 3 deletions publisher/src/components/Reports/PublishConfirmation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { useNavigate } from "react-router-dom";

import { trackReportPublished } from "../../analytics";
import { useStore } from "../../stores";
import FormStore from "../../stores/FormStore";
import { printReportTitle } from "../../utils";
import logoImg from "../assets/jc-logo-vector.png";
import errorIcon from "../assets/status-error-icon.png";
Expand Down Expand Up @@ -169,7 +168,7 @@ const MetricsDisplay: React.FC<{

const PublishConfirmation: React.FC<{
reportID: number;
checkMetricForErrors: (metricKey: string, formStore: FormStore) => boolean;
checkMetricForErrors: (metricKey: string) => boolean;
toggleConfirmationDialogue: () => void;
}> = ({ reportID, checkMetricForErrors, toggleConfirmationDialogue }) => {
const [isPublishable, setIsPublishable] = useState(false);
Expand Down Expand Up @@ -275,7 +274,7 @@ const PublishConfirmation: React.FC<{
<MetricsDisplay
key={metric.key}
metric={metric}
metricHasError={checkMetricForErrors(metric.key, formStore)}
metricHasError={checkMetricForErrors(metric.key)}
index={i}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { observer } from "mobx-react-lite";
import React from "react";

import { useStore } from "../../stores";
import FormStore from "../../stores/FormStore";
import checkIcon from "../assets/check-icon.svg";
import errorIcon from "../assets/status-error-icon.png";
import { MetricsSectionTitle } from "../Forms";
Expand Down Expand Up @@ -61,7 +60,7 @@ const ReportStatusIconComponent: React.FC<{

const PublishConfirmationSummaryPanel: React.FC<{
reportID: number;
checkMetricForErrors: (metricKey: string, formStore: FormStore) => boolean;
checkMetricForErrors: (metricKey: string) => boolean;
}> = ({ reportID, checkMetricForErrors }) => {
const { formStore, reportStore } = useStore();

Expand All @@ -80,7 +79,7 @@ const PublishConfirmationSummaryPanel: React.FC<{
<MetricsSectionTitle>{system}</MetricsSectionTitle>
)}
{enabledMetrics.map((metric) => {
const foundErrors = checkMetricForErrors(metric.key, formStore);
const foundErrors = checkMetricForErrors(metric.key);

return (
<ReportStatusIconComponent
Expand Down
12 changes: 9 additions & 3 deletions publisher/src/components/Reports/ReportDataEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import styled from "styled-components/macro";

import { trackReportUnpublished } from "../../analytics";
import { useStore } from "../../stores";
import FormStore from "../../stores/FormStore";
import { printReportTitle } from "../../utils";
import { PageWrapper } from "../Forms";
import { Loading } from "../Loading";
Expand Down Expand Up @@ -62,7 +61,7 @@ const ReportDataEntry = () => {
>(undefined);
const [showConfirmation, setShowConfirmation] = useState(false);
const [showDataEntryHelpPage, setShowDataEntryHelpPage] = useState(false);
const { reportStore, userStore } = useStore();
const { formStore, reportStore, userStore } = useStore();
const params = useParams();
const reportID = Number(params.id);
const reportOverview = reportStore.reportOverviews[reportID] as Report;
Expand Down Expand Up @@ -103,7 +102,7 @@ const ReportDataEntry = () => {
}
};

const checkMetricForErrors = (metricKey: string, formStore: FormStore) => {
const checkMetricForErrors = (metricKey: string) => {
let foundErrors = false;

if (formStore.metricsValues[reportID]?.[metricKey]?.error) {
Expand Down Expand Up @@ -155,6 +154,13 @@ const ReportDataEntry = () => {
[]
);

useEffect(() => {
/** Runs validation of previously saved inputs on load */
if (reportMetrics) {
formStore.validatePreviouslySavedInputs(reportID);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, we could also call this whenever a report is fetched? It could just be part of the process of fetching a report, storing it in the report store, and also storing inputs + validation in the form store?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That makes a lot of sense actually! I don't have strong feelings though -- if you feel that this solution is robust enough for now @terryttsai , I'm fine to merge this in as-is. Up to you.

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong feelings either - both make a lot of sense! I'm good with your solution here!

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'll go with this for now!

}
}, [reportMetrics]);

const updateActiveMetric = (metricKey: string) => setActiveMetric(metricKey);
const updateFieldDescription = (title?: string, description?: string) => {
if (title && description) {
Expand Down
5 changes: 2 additions & 3 deletions publisher/src/components/Reports/ReportSummaryPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import React from "react";
import styled from "styled-components/macro";

import { useStore } from "../../stores";
import FormStore from "../../stores/FormStore";
import {
printCommaSeparatedList,
printDateRangeFromMonthYear,
Expand Down Expand Up @@ -226,7 +225,7 @@ const ReportStatusIconComponent: React.FC<{
const ReportSummaryPanel: React.FC<{
reportID: number;
activeMetric: string;
checkMetricForErrors: (metricKey: string, formStore: FormStore) => boolean;
checkMetricForErrors: (metricKey: string) => boolean;
showDataEntryHelpPage: boolean;
fieldDescription?: FieldDescriptionProps;
}> = ({
Expand Down Expand Up @@ -262,7 +261,7 @@ const ReportSummaryPanel: React.FC<{
<MetricsSectionTitle>{system}</MetricsSectionTitle>
) : null}
{enabledMetrics.map((metric) => {
const foundErrors = checkMetricForErrors(metric.key, formStore);
const foundErrors = checkMetricForErrors(metric.key);

return (
<ReportStatusIconComponent
Expand Down