@@ -27,7 +26,7 @@ const Objective = ({ headerRef, objective, objectiveNumber }) => {
{children.map((q) => (
-
+
))}
@@ -38,6 +37,7 @@ Objective.propTypes = {
headerRef: PropTypes.func.isRequired,
objective: PropTypes.object.isRequired,
objectiveNumber: PropTypes.number.isRequired,
+ printView: PropTypes.bool,
};
export { Objective };
diff --git a/services/ui-src/src/components/fields/Objectives.jsx b/services/ui-src/src/components/fields/Objectives.jsx
index 4953ed21f..f80167133 100644
--- a/services/ui-src/src/components/fields/Objectives.jsx
+++ b/services/ui-src/src/components/fields/Objectives.jsx
@@ -16,9 +16,9 @@ const Objectives = ({
disabled,
question,
removeObjectiveFrom,
+ printView,
}) => {
const ref = useRef();
-
const add = () => {
addObjectiveTo(question.id);
@@ -47,7 +47,12 @@ const Objectives = ({
>
{question.questions.map((q, i) => (
-
+
))}
@@ -92,6 +97,7 @@ Objectives.propTypes = {
disabled: PropTypes.bool.isRequired,
question: PropTypes.object.isRequired,
removeObjectiveFrom: PropTypes.func.isRequired,
+ printView: PropTypes.bool,
};
const mapDispatchToProps = {
diff --git a/services/ui-src/src/components/fields/Question.jsx b/services/ui-src/src/components/fields/Question.jsx
index 271024817..88716bebc 100644
--- a/services/ui-src/src/components/fields/Question.jsx
+++ b/services/ui-src/src/components/fields/Question.jsx
@@ -9,7 +9,7 @@ import { DateRange } from "./DateRange";
import { Email } from "./Email";
import { Fieldset } from "./Fieldset";
import UploadComponent from "../layout/UploadComponent";
-import { Integer } from "./Integer";
+import Integer from "./Integer";
import { MailingAddress } from "./MailingAddress";
import { Money } from "./Money";
import { Objectives } from "./Objectives";
@@ -57,7 +57,14 @@ Container.propTypes = {
children: PropTypes.node.isRequired,
};
-const Question = ({ hideNumber, question, prevYear, tableTitle, ...props }) => {
+const Question = ({
+ hideNumber,
+ question,
+ prevYear,
+ tableTitle,
+ printView,
+ ...props
+}) => {
let Component = Text;
if (questionTypes.has(question.type)) {
Component = questionTypes.get(question.type);
@@ -144,6 +151,7 @@ const Question = ({ hideNumber, question, prevYear, tableTitle, ...props }) => {
false
}
prevYear={prevYear}
+ printView={printView}
/>
{/* If there are subquestions, wrap them so they are indented with the
@@ -153,7 +161,12 @@ const Question = ({ hideNumber, question, prevYear, tableTitle, ...props }) => {
{shouldRenderChildren && (
{question.questions.map((q) => (
-
+
))}
)}
@@ -167,6 +180,7 @@ Question.propTypes = {
question: PropTypes.object.isRequired,
prevYear: PropTypes.object,
tableTitle: PropTypes.string,
+ printView: PropTypes.bool,
};
Question.defaultProps = {
hideNumber: false,
diff --git a/services/ui-src/src/components/fields/Repeatable.jsx b/services/ui-src/src/components/fields/Repeatable.jsx
index f32413bf4..644f34a36 100644
--- a/services/ui-src/src/components/fields/Repeatable.jsx
+++ b/services/ui-src/src/components/fields/Repeatable.jsx
@@ -4,7 +4,7 @@ import { AccordionButton, AccordionPanel } from "@reach/accordion";
import Question from "./Question";
-const Repeatable = ({ headerRef, number, question, type }) => {
+const Repeatable = ({ headerRef, number, question, type, printView }) => {
const children = question.questions ? question.questions : [];
const title = type ? `${type} ${number}` : `${number}`;
@@ -20,7 +20,7 @@ const Repeatable = ({ headerRef, number, question, type }) => {
@@ -30,6 +34,7 @@ const Section = ({ subsectionId, sectionId }) => {
Section.propTypes = {
subsectionId: PropTypes.string.isRequired,
sectionId: PropTypes.number.isRequired,
+ printView: PropTypes.bool,
};
export default Section;
diff --git a/services/ui-src/src/components/layout/Subsection.jsx b/services/ui-src/src/components/layout/Subsection.jsx
index 67433a5b5..6417beca6 100644
--- a/services/ui-src/src/components/layout/Subsection.jsx
+++ b/services/ui-src/src/components/layout/Subsection.jsx
@@ -8,7 +8,7 @@ import { selectSubsectionTitleAndPartIDs } from "../../store/selectors";
//types
import PropTypes from "prop-types";
-const Subsection = ({ subsectionId }) => {
+const Subsection = ({ subsectionId, printView }) => {
const formData = useSelector((state) => state.formData);
const subsection = selectSubsectionTitleAndPartIDs(formData, subsectionId);
@@ -31,6 +31,7 @@ const Subsection = ({ subsectionId }) => {
partId={partId}
partNumber={partIds.length > 1 ? index + 1 : null}
nestedSubsectionTitle={!!title}
+ printView={printView}
/>
))}
@@ -38,6 +39,7 @@ const Subsection = ({ subsectionId }) => {
};
Subsection.propTypes = {
subsectionId: PropTypes.string.isRequired,
+ printView: PropTypes.bool,
};
Subsection.defaultProps = {
text: null,
diff --git a/services/ui-src/src/components/sections/Print.jsx b/services/ui-src/src/components/sections/Print.jsx
index e313f5f9b..f7bc26f35 100644
--- a/services/ui-src/src/components/sections/Print.jsx
+++ b/services/ui-src/src/components/sections/Print.jsx
@@ -140,6 +140,7 @@ const Print = () => {
sectionId={sectionId}
subsectionId={subsectionId}
readonly="false"
+ printView="true"
/>
);
} else {
@@ -164,6 +165,7 @@ const Print = () => {
sectionId={sectionId}
subsectionId={subsectionId}
readonly="false"
+ printView="true"
/>
);
}
diff --git a/services/ui-src/src/util/synthesize.js b/services/ui-src/src/util/synthesize.js
index 361d698c7..497eabff0 100644
--- a/services/ui-src/src/util/synthesize.js
+++ b/services/ui-src/src/util/synthesize.js
@@ -215,6 +215,20 @@ const snakeToCamel = (str) =>
group.toUpperCase().replace("-", "").replace("_", "")
);
+// returns the state abbreviation for the associated report
+const getStateAbbr = (stateUserAbbr) => {
+ if (stateUserAbbr) return stateUserAbbr;
+ const windowPathName = window.location.pathname;
+ // if admin, grab the state from the URL
+ const stateFromURL = windowPathName.split("/")[3];
+
+ // if admin and in a print view get state param
+ const urlSearchParams = new URLSearchParams(window.location.search);
+ const stateFromParams = urlSearchParams.get("state");
+
+ return windowPathName.includes("print") ? stateFromParams : stateFromURL;
+};
+
/**
* Retrieve acsSet from state and return for individual state.
*
@@ -230,26 +244,13 @@ const lookupAcs = (allStatesData, stateUserAbbr, { ffy, acsProperty }) => {
? snakeToCamel(acsProperty)
: acsProperty;
- // if allStatesData and stateUser are available
- if (allStatesData && stateUserAbbr) {
- const windowPathName = window.location.pathname;
- // if admin, grab the state from the URL
- const stateFromURL = windowPathName.split("/")[3];
+ // if allStatesData is a populated array
+ if (allStatesData?.length > 0) {
+ const stateAbbr = getStateAbbr(stateUserAbbr);
- // if admin and in a print view get state param
- const urlSearchParams = new URLSearchParams(window.location.search);
- const stateFromParams = urlSearchParams.get("state");
-
- // Get stateUser state or fallback to the URL, if an admin
- const stateAbbr =
- stateUserAbbr ||
- (windowPathName.includes("print") ? stateFromParams : stateFromURL);
-
- // Filter for only matching state
- const stateData = allStatesData.filter((st) => st.code === stateAbbr)[0];
-
- // Filter for matching state from JSON
- const acs = stateData?.acsSet.filter((year) => year.year === +ffy)[0];
+ // Find data for matching state
+ const stateData = allStatesData.find((st) => st.code === stateAbbr);
+ const acs = stateData?.acsSet.find((year) => year.year === +ffy);
// If acs exists, return the value from the object
if (acs) {
@@ -279,20 +280,18 @@ export const compareACS = (
) => {
const percentagePrecision = 2;
let returnValue = "Not Available";
- // if allStatesData and stateUser are available
- if (allStatesData && stateUserAbbr) {
- // Filter for only matching state
- const stateData = allStatesData.filter(
- (st) => st.code === stateUserAbbr
- )[0];
-
- // Filter for the correct year of state data
- const startACS = stateData?.acsSet.filter(
+ // if allStatesData is a populated array
+ if (allStatesData?.length > 0) {
+ const stateAbbr = getStateAbbr(stateUserAbbr);
+ const stateData = allStatesData.find((st) => st.code === stateAbbr);
+
+ // Find the correct year of state data
+ const startACS = stateData?.acsSet.find(
(year) => year.year === parseInt(ffy1, 10)
- )[0];
- const endACS = stateData?.acsSet.filter(
+ );
+ const endACS = stateData?.acsSet.find(
(year) => year.year === parseInt(ffy2, 10)
- )[0];
+ );
// If start year and end year of ACS exist, return the calculated value (percent change) from the objects
if (startACS && endACS) {
diff --git a/services/ui-src/src/util/synthesize.test.js b/services/ui-src/src/util/synthesize.test.js
index a9f17cc45..43aed8a7b 100644
--- a/services/ui-src/src/util/synthesize.test.js
+++ b/services/ui-src/src/util/synthesize.test.js
@@ -128,7 +128,7 @@ const fallbackChipState = {
},
};
-describe("value synthesization utility", () => {
+describe("value synthesis utility", () => {
describe("handles identity", () => {
test("with no values", () => {
// Returns undefined, because there's not a value
@@ -615,6 +615,29 @@ describe("value synthesization utility", () => {
);
expect(out).toEqual({ contents: ["3.70%"] });
});
+
+ it("compares two ffys as admin user", () => {
+ Object.defineProperty(window, "location", {
+ value: {
+ pathname: "/views/sections/AL/2023/02",
+ },
+ });
+ const out = synthesize(
+ {
+ compareACS: {
+ ffy1: 2021,
+ ffy2: 2020,
+ acsProperty: "numberUninsured",
+ },
+ },
+ state.allStatesData,
+ state.global.stateName,
+ undefined, // state user abbreviation
+ state.enrollmentCounts.chipEnrollments,
+ state.formData
+ );
+ expect(out).toEqual({ contents: ["3.70%"] });
+ });
});
describe("handles CHIPS Enrollment Data", () => {