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

Add filter to allow viewing replaced plans #1129

Merged
merged 3 commits into from
Jun 13, 2024
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
6 changes: 6 additions & 0 deletions src/components/selectRangeUsePlanPage/ExtensionColumn.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>District Manager Rejected</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACED_WITH_REPLACEMENT_PLAN:
return <div>Replaced</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.AWAITING_EXTENSION:
Expand Down Expand Up @@ -260,6 +262,8 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>Awaiting Extension</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACED_WITH_REPLACEMENT_PLAN:
return <div>Replaced</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.EXTENDED:
Expand Down Expand Up @@ -330,6 +334,8 @@ export default function ExtensionColumn({ user, currentPage, agreement }) {
return <div>Awaiting Extension</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED:
return <div>Replacement Plan Created</div>;
case PLAN_EXTENSION_STATUS.REPLACED_WITH_REPLACEMENT_PLAN:
return <div>Replaced</div>;
case PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_ACTIVE:
return <div>Active Replacement Plan</div>;
case PLAN_EXTENSION_STATUS.EXTENDED:
Expand Down
7 changes: 4 additions & 3 deletions src/components/selectRangeUsePlanPage/PlanActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ export default function PlanActions({
].includes(agreement.plan?.extensionStatus) && (
<CreateReplacementPlan planId={planId} />
)}
{[PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED].includes(
agreement.plan?.extensionStatus,
) && (
{[
PLAN_EXTENSION_STATUS.REPLACEMENT_PLAN_CREATED,
PLAN_EXTENSION_STATUS.REPLACED_WITH_REPLACEMENT_PLAN,
].includes(agreement.plan?.extensionStatus) && (
<ViewPlanMenuItem
planId={agreement.plan?.replacementPlanId}
currentPage={currentPage}
Expand Down
94 changes: 57 additions & 37 deletions src/components/selectRangeUsePlanPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
isUserAgrologist,
isUserAdmin,
getDataFromLocalStorage,
saveDataInLocalStorage
saveDataInLocalStorage,
} from '../../utils';
import useDebounce from '../../utils/hooks/useDebounce';
import Error from './Error';
Expand Down Expand Up @@ -70,7 +70,7 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
const debouncedOrderBy = useDebounce(orderBy, 500);
const [order = 'asc', setOrder] = useQueryParam('order', StringParam);
const debouncedOrder = useDebounce(order, 500);
const filterInfo = getDataFromLocalStorage("filter-info");
const filterInfo = getDataFromLocalStorage('filter-info');
const [filters = { agreementCheck: 'true' }, setFilters] = useQueryParam(
'filters',
NewObjectParam,
Expand All @@ -80,30 +80,32 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
// startup
useEffect(() => {
// Set initial page info from localstorage
const pageInfo = getDataFromLocalStorage("page-info");
const pageInfo = getDataFromLocalStorage('page-info');
if (pageInfo) {
if (pageInfo.pageNumber) setPage(pageInfo.pageNumber);
if (pageInfo.pageLimit) setLimit(pageInfo.pageLimit);
}
// Initialize filters
setFilters({
setFilters({
...filterInfo,
agreementCheck: 'true',
});
setFiltersInitialized(true); // Workaround flag for checkbox racing the filter initialization
setFiltersInitialized(true); // Workaround flag for checkbox racing the filter initialization
}, []);
const [planCheck = filterInfo?.planCheck || false, setPlanCheck] = useQueryParam(
'planCheck',
BooleanParam,
);
const [agreementCheck = filterInfo?.agreementCheck !== undefined ? filterInfo.agreementCheck : true, setAgreementCheck] = useQueryParam(
'agreementCheck',
BooleanParam,
);
const [activeCheck = filterInfo?.activeCheck || false, setActiveCheck] = useQueryParam(
'activeCheck',
BooleanParam,
);
const [planCheck = filterInfo?.planCheck || false, setPlanCheck] =
useQueryParam('planCheck', BooleanParam);
const [
agreementCheck = filterInfo?.agreementCheck !== undefined
? filterInfo.agreementCheck
: true,
setAgreementCheck,
] = useQueryParam('agreementCheck', BooleanParam);
const [activeCheck = filterInfo?.activeCheck || false, setActiveCheck] =
useQueryParam('activeCheck', BooleanParam);
const [
showReplacedPlans = filterInfo?.showReplacedPlans || false,
setShowReplacedPlans,
] = useQueryParam('showReplacedPlans', BooleanParam);
useEffect(() => {
if (filtersInitialized) addToFilters('planCheck', planCheck);
}, [planCheck]);
Expand All @@ -113,6 +115,10 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
useEffect(() => {
if (filtersInitialized) addToFilters('activeCheck', activeCheck);
}, [activeCheck]);
useEffect(() => {
if (filtersInitialized)
addToFilters('showReplacedPlans', showReplacedPlans);
}, [showReplacedPlans]);

const { warningToast, removeToast, errorToast } = useToast();

Expand Down Expand Up @@ -155,38 +161,38 @@ const SelectRangeUsePlanPage = ({ match, history }) => {

const setPage = (page) => {
history.replace(`/home/${page}/${history.location.search}`);
}
};

const setPageAndSave = (page) => {
history.replace(`/home/${page}/${history.location.search}`);
const currPageInfo = getDataFromLocalStorage("page-info");
const currPageInfo = getDataFromLocalStorage('page-info');
const pageInfo = {
...currPageInfo,
pageNumber: page
}
saveDataInLocalStorage("page-info", pageInfo);
}
pageNumber: page,
};
saveDataInLocalStorage('page-info', pageInfo);
};

const setPageLimitAndSave = (limit) => {
const currPageInfo = getDataFromLocalStorage("page-info");
const currPageInfo = getDataFromLocalStorage('page-info');
const pageInfo = {
...currPageInfo,
pageLimit: limit
}
saveDataInLocalStorage("page-info", pageInfo);
pageLimit: limit,
};
saveDataInLocalStorage('page-info', pageInfo);
setLimit(limit);
}
};

const setSaveFilterInfo = (filterCol, value) => {
if (!filtersInitialized) return; // Avoid empty update

const currFilterInfo = getDataFromLocalStorage("filter-info");
const currFilterInfo = getDataFromLocalStorage('filter-info');
const filterInfo = {
...currFilterInfo
}
...currFilterInfo,
};
filterInfo[filterCol] = value;
saveDataInLocalStorage("filter-info", filterInfo);
}
saveDataInLocalStorage('filter-info', filterInfo);
};

const { agreements, totalPages, currentPage = page, totalItems } = data || {};
const classes = useStyles();
Expand All @@ -204,7 +210,7 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
checked={planCheck}
onChange={() => {
setPlanCheck(!planCheck);
setSaveFilterInfo("planCheck", !planCheck);
setSaveFilterInfo('planCheck', !planCheck);
}}
name="planCheck"
color="primary"
Expand All @@ -218,7 +224,7 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
checked={agreementCheck}
onChange={() => {
setAgreementCheck(!agreementCheck);
setSaveFilterInfo("agreementCheck", !agreementCheck);
setSaveFilterInfo('agreementCheck', !agreementCheck);
}}
name="agreementCheck"
color="primary"
Expand All @@ -232,14 +238,28 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
checked={activeCheck}
onChange={() => {
setActiveCheck(!activeCheck);
setSaveFilterInfo("activeCheck", !activeCheck);
setSaveFilterInfo('activeCheck', !activeCheck);
}}
name="activeCheck"
color="primary"
/>
}
label="Active RUP"
/>
<FormControlLabel
control={
<Checkbox
checked={showReplacedPlans}
onChange={() => {
setShowReplacedPlans(!showReplacedPlans);
setSaveFilterInfo('showReplacedPlans', !showReplacedPlans);
}}
name="shwoReplacedPlans"
color="primary"
/>
}
label="Replaced Plans"
/>
</div>
{isUserAgrologist(user) && (
<ZoneSelect
Expand All @@ -250,7 +270,7 @@ const SelectRangeUsePlanPage = ({ match, history }) => {
setSearchSelectedZones={setSearchSelectedZones}
/>
)}
{(isUserAdmin(user)) && (
{isUserAdmin(user) && (
<ZoneSelectAll
zones={zones}
zoneUsers={zoneUsers}
Expand Down
1 change: 1 addition & 0 deletions src/constants/variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,5 @@ export const PLAN_EXTENSION_STATUS = {
REPLACEMENT_PLAN_CREATED: 8,
REPLACEMENT_PLAN_INACTIVE: 9,
REPLACEMENT_PLAN_ACTIVE: 10,
REPLACED_WITH_REPLACEMENT_PLAN: 11,
};
Loading