Skip to content

Commit

Permalink
fix: Add isNoReform function and check for falsy values (#2003)
Browse files Browse the repository at this point in the history
Co-authored-by: PolicyEngine[bot] <[email protected]>
  • Loading branch information
anth-volk and PolicyEngine[bot] authored Sep 4, 2024
1 parent 5a48767 commit 8f341ba
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/pages/policy/PolicyRightSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,26 @@ export default function PolicyRightSidebar(props) {
(option) => option.value === stateAbbreviation,
)?.value;

const baselineData = policy.baseline.data;
const reformData = policy.reform.data;

// Convenience function for determining if baseline and reform
// are both current law, and thus, there is no reform
function isNoReform(baselineData, reformData) {
if (!baselineData || !reformData) {
return true;
}

if (
Object.keys(baselineData).length === 0 &&
Object.keys(reformData).length === 0
) {
return true;
}

return false;
}

const confirmEconomicImpact = () => {
let message = "";
if (validatedStateAbbreviation && stateAbbreviation !== region) {
Expand Down Expand Up @@ -782,10 +802,7 @@ export default function PolicyRightSidebar(props) {
<SearchParamNavButton
type={
// Disable output if both baseline and reform are current law
Object.keys(policy.reform.data).length === 0 &&
Object.keys(policy.baseline.data).length === 0
? "disabled"
: "primary"
isNoReform(baselineData, reformData) ? "disabled" : "primary"
}
text="Calculate economic impact"
onClick={confirmEconomicImpact}
Expand Down

0 comments on commit 8f341ba

Please sign in to comment.