From 3ba1cf0519846aad86af7488e9304fcf464db145 Mon Sep 17 00:00:00 2001 From: Abhishek Singh <31144719+abhcs@users.noreply.github.com> Date: Sun, 10 Dec 2023 15:52:15 -0600 Subject: [PATCH] fix issue 485 --- src/pages/policy/PolicyRightSidebar.jsx | 18 ++++++--------- src/pages/policy/input/ParameterEditor.jsx | 27 +++++++++++----------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/pages/policy/PolicyRightSidebar.jsx b/src/pages/policy/PolicyRightSidebar.jsx index 3aa46085c..5d3ac5cc2 100644 --- a/src/pages/policy/PolicyRightSidebar.jsx +++ b/src/pages/policy/PolicyRightSidebar.jsx @@ -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 (
{ - 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); + newSearchParams.set("focus", parameterName); + newSearchParams.set("reform", policy.reform.id); + newSearchParams.set("region", region); + newSearchParams.set("timePeriod", timePeriod); + setSearchParams(newSearchParams); hideButtons && closeDrawer(); }} > diff --git a/src/pages/policy/input/ParameterEditor.jsx b/src/pages/policy/input/ParameterEditor.jsx index 01cc30232..9fdae3024 100644 --- a/src/pages/policy/input/ParameterEditor.jsx +++ b/src/pages/policy/input/ParameterEditor.jsx @@ -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) { @@ -69,26 +73,21 @@ export default function ParameterEditor(props) { control = (
onChange(!!value)} />
); - } else if (parameter.unit === "/1") { - let val = getParameterAtInstant(parameter, startDate); - let valInPercentage = formatVariableValue(parameter, val); - control = ( - onChange(parseFloat(value) / 100)} - /> - ); } else { + const isPercent = parameter.unit === "/1"; + const scale = isPercent ? 100 : 1; control = ( onChange(Number(value))} + placeholder={ + isPercent ? formatVariableValue(parameter, startValue) : startValue + } + {...(isPercent ? { pattern: "%" } : {})} + onChange={(value) => onChange(parseFloat(value) / scale)} /> ); } @@ -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.` : ""; let description = parameter.description;