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

Do not forget current household when clicking on policy display carousel #947

Merged
merged 1 commit into from
Dec 11, 2023
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
18 changes: 7 additions & 11 deletions src/pages/policy/PolicyRightSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function PolicyDisplay(props) {
const { policy, metadata, region, timePeriod, closeDrawer, hideButtons } =
props;
const reformLength = Object.keys(policy.reform.data).length;
const navigate = useNavigate();
const [searchParams, setSearchParams] = useSearchParams();
return (
<div
style={{
Expand All @@ -161,16 +161,12 @@ function PolicyDisplay(props) {
<Carousel.Item
key={parameterName}
onClick={() => {
const country = metadata.countryId;
const newSearchParams = {};
newSearchParams.focus = parameterName;
newSearchParams.reform = policy.reform.id;
newSearchParams.region = region;
newSearchParams.timePeriod = timePeriod;
const newUrl = `/${country}/policy?${new URLSearchParams(
newSearchParams,
)}`;
navigate(newUrl);
const newSearchParams = copySearchParams(searchParams);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah yep makes sense.

newSearchParams.set("focus", parameterName);
newSearchParams.set("reform", policy.reform.id);
newSearchParams.set("region", region);
newSearchParams.set("timePeriod", timePeriod);
setSearchParams(newSearchParams);
hideButtons && closeDrawer();
}}
>
Expand Down
27 changes: 13 additions & 14 deletions src/pages/policy/input/ParameterEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export default function ParameterEditor(props) {
const currentYear = new Date().getFullYear();
const [startDate, setStartDate] = useState(currentYear + "-01-01");
const [endDate, setEndDate] = useState(currentYear + 5 + "-12-31");
const startValue = getParameterAtInstant(
getReformedParameter(parameter, policy.reform.data),
startDate,
);

// change reform data using value and current startDate and endDate
function newReforms(reforms, value) {
Expand Down Expand Up @@ -69,26 +73,21 @@ export default function ParameterEditor(props) {
control = (
<div style={{ padding: 10 }}>
<Switch
defaultChecked={getParameterAtInstant(parameter, startDate)}
defaultChecked={startValue}
onChange={(value) => onChange(!!value)}
/>
</div>
);
} else if (parameter.unit === "/1") {
let val = getParameterAtInstant(parameter, startDate);
let valInPercentage = formatVariableValue(parameter, val);
control = (
<InputField
placeholder={valInPercentage}
pattern={"%"}
onChange={(value) => onChange(parseFloat(value) / 100)}
/>
);
} else {
const isPercent = parameter.unit === "/1";
const scale = isPercent ? 100 : 1;
control = (
<InputField
placeholder={getParameterAtInstant(parameter, startDate)}
onChange={(value) => onChange(Number(value))}
placeholder={
isPercent ? formatVariableValue(parameter, startValue) : startValue
}
{...(isPercent ? { pattern: "%" } : {})}
onChange={(value) => onChange(parseFloat(value) / scale)}
/>
);
}
Expand Down Expand Up @@ -117,7 +116,7 @@ export default function ParameterEditor(props) {
);

const timePeriodSentence = parameter.period
? `This parameter is ${parameter.period}ly.`
? ` This parameter is ${parameter.period}ly.`
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

: "";

let description = parameter.description;
Expand Down
Loading