Skip to content

Commit

Permalink
Plan and Pop inbox fix (#1881)
Browse files Browse the repository at this point in the history
* fixed pop inbox boundary getting empty issue

* fixed back button issue

* updated search juridiction component

* fixed facility pop up boundary refresh

* removed pending for approval from status filter

---------

Co-authored-by: rachana-egov <rachana.singh@egovernment.org>
  • Loading branch information
rachana-egov and rachana-egov authored Nov 22, 2024
1 parent 0343381 commit cfda909
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ConfirmationPopUp = ({ onClose, alertHeading, alertMessage, submitLabel, u
className="campaign-type-alert-button"
type="button"
size="large"
variation="secondary"
variation="primary"
label={t(cancelLabel)}
onClick={onClose}
isDisabled={isSubmitting} // Disable button during submission
Expand All @@ -65,7 +65,7 @@ const ConfirmationPopUp = ({ onClose, alertHeading, alertMessage, submitLabel, u
className="campaign-type-alert-button"
type="button"
size="large"
variation="primary"
variation="secondary"
label={t(submitLabel)}
onClick={handleSave}
isDisabled={isSubmitting} // Disable button during submission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
const [rowsPerPage, setRowsPerPage] = useState(10);
const [disabledAction, setDisabledAction] = useState(false);
const [boundaryData, setBoundaryData] = useState([]);
const [defaultHierarchy, setDefaultSelectedHierarchy] = useState(null);
const [defaultBoundaries, setDefaultBoundaries] = useState([]);
const VillageHierarchyTooltipWrapper = Digit.ComponentRegistryService.getComponent("VillageHierarchyTooltipWrapper");
const [kpiParams, setKpiParams] = useState([]);
const configNavItem = [
Expand Down Expand Up @@ -383,6 +385,25 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
},
];

const onSearch = (selectedBoundaries, selectedHierarchy) => {

if (selectedBoundaries.length === 0) {
setShowToast({ key: "warning", label: t("MICROPLAN_BOUNDARY_IS_EMPTY_WARNING"), transitionTime: 5000 });
} else {

setDefaultSelectedHierarchy(selectedHierarchy);
setDefaultBoundaries(selectedBoundaries);
censusSearch(selectedBoundaries);
}

};

const onClear = () => {
setDefaultBoundaries([]);
setDefaultSelectedHierarchy(null);
censusSearch([]);
};

useEffect(() => {
if (details) {
setKpiParams([
Expand Down Expand Up @@ -446,10 +467,12 @@ const FacilityPopUp = ({ details, onClose, updateDetails }) => {
<SearchJurisdiction
key={searchKey} // Use key to force re-render
boundaries={boundaries}
defaultBoundaries={defaultBoundaries}
defaultHierarchy={defaultHierarchy}
jurisdiction={jurisdiction}
onSubmit={censusSearch}
onSubmit={onSearch}
style={{ padding: "0px" }}
onClear={() => censusSearch([])}
onClear={onClear}
/>
</Card>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { LabelFieldPair, CardLabel, SubmitBar, LinkLabel, InfoCard } from "@egovernments/digit-ui-components";
import React, { useEffect, Fragment, useState } from "react";
import React, { useEffect, Fragment, useState, useRef } from "react";
import { useTranslation } from "react-i18next";
import { useMyContext } from "../utils/context";
import { Dropdown, MultiSelectDropdown } from "@egovernments/digit-ui-components";

const SearchJurisdiction = ({ boundaries, jurisdiction, onSubmit = () => { }, onClear = () => { }, style = {},showInstruction=false }) => {
const SearchJurisdiction = ({ boundaries, jurisdiction, onSubmit = () => { }, onClear = () => { }, style = {},showInstruction=false,
defaultHierarchy = null,
defaultBoundaries = [],
}) => {
const { t } = useTranslation();
const {
state: { hierarchyType, boundaryHierarchy },
Expand All @@ -15,10 +18,13 @@ const SearchJurisdiction = ({ boundaries, jurisdiction, onSubmit = () => { }, on
const hierarchy = Digit.Utils.microplanv1.getFilteredHierarchy(boundaryHierarchy, jurisdiction.boundaryType, hierarchyType);
const [boundaryOptions, setBoundaryOptions] = useState([]);

const [selectedBoundaries, setSelectedBoundaries] = useState([]);
const [selectedHierarchy, setSelectedHierarchy] = useState(null);
const [selectedBoundaries, setSelectedBoundaries] = useState(defaultBoundaries);
const [selectedHierarchy, setSelectedHierarchy] = useState(defaultHierarchy);
const MultiSelectWrapper = Digit.ComponentRegistryService.getComponent("MultiSelectDropdownBoundary");

// Ref to track if the component has mounted
const isInitialLoad = useRef(true);

useEffect(() => {
if (!selectedHierarchy) {
setBoundaryOptions([]);
Expand All @@ -29,8 +35,12 @@ const SearchJurisdiction = ({ boundaries, jurisdiction, onSubmit = () => { }, on
const filteredBoundaries = userBoundaries.filter((row) => row.type === selectedHierarchy.boundaryType);
const filteredBoundariesGroupedByParent = Digit.Utils.microplanv1.groupByParent(filteredBoundaries);
setBoundaryOptions(filteredBoundariesGroupedByParent);
//reset selected
setSelectedBoundaries([])
// Reset selected boundaries only after the initial load
if (!isInitialLoad.current) {
setSelectedBoundaries([]);
} else {
isInitialLoad.current = false;
}
//based on the select hierarchy filter from userBoundaries and form options object
}, [selectedHierarchy]);

Expand Down Expand Up @@ -99,7 +109,7 @@ const SearchJurisdiction = ({ boundaries, jurisdiction, onSubmit = () => { }, on
>
{t("CLEAR")}
</LinkLabel>
<SubmitBar label={t("SEARCH")} onSubmit={() => onSubmit(selectedBoundaries)} />
<SubmitBar label={t("SEARCH")} onSubmit={() => onSubmit(selectedBoundaries, selectedHierarchy)} />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const PlanInbox = () => {
const [selectedBoundaryCode, setSelectedBoundaryCode] = useState(null);
const [selectedBusinessId, setSelectedBusinessId] = useState(null);
const [assigneeUuids, setAssigneeUuids] = useState([]);
const [totalStatusCount, setTotalStatusCount] = useState({});
const [employeeNameMap, setEmployeeNameMap] = useState({});

const [defaultHierarchy, setDefaultSelectedHierarchy] = useState(null);
const [defaultBoundaries, setDefaultBoundaries] = useState([]);
const userRoles = user?.info?.roles?.map((roleData) => roleData?.code);

// Check if the user has the 'rootapprover' role
Expand All @@ -74,6 +76,45 @@ const PlanInbox = () => {
}
);

const mutation = Digit.Hooks.useCustomAPIMutationHook({
url: "/plan-service/plan/_search",
});


useEffect(() => {
fetchStatusCount();
}, [planObject]);

const fetchStatusCount = async () => {
if (planObject) {
try {
await mutation.mutateAsync(
{
body: {
PlanSearchCriteria: {
tenantId: tenantId,
planConfigurationId: microplanId,
...(isRootApprover
? {}
: { jurisdiction: jurisdiction }),
},
}
},
{
onSuccess: (data) => {
setTotalStatusCount(data?.StatusCount);
},
onError: (error) => {
setShowToast({ key: "error", label: t(error?.response?.data?.Errors?.[0]?.code) });
}
}
);
} catch (error) {
setShowToast({ key: "error", label: t(error?.response?.data?.Errors?.[0]?.code) });
}
}
};

useEffect(() => {
if (selectedFilter === "VALIDATED") {
setActiveLink({ code: "", name: "" });
Expand Down Expand Up @@ -116,6 +157,7 @@ const PlanInbox = () => {
data: planWithCensus,
error: planWithCensusError,
refetch: refetchPlanWithCensus,
isFetching,
} = Digit.Hooks.microplanv1.usePlanSearchWithCensus({
tenantId: tenantId,
microplanId: microplanId,
Expand Down Expand Up @@ -182,7 +224,7 @@ const PlanInbox = () => {
},
});

const onSearch = (selectedBoundaries) => {
const onSearch = (selectedBoundaries, selectedHierarchy) => {
if (selectedBoundaries.length === 0) {
setShowToast({ key: "warning", label: t("MICROPLAN_BOUNDARY_IS_EMPTY_WARNING"), transitionTime: 5000 });
} else {
Expand All @@ -191,7 +233,10 @@ const PlanInbox = () => {
code: "ASSIGNED_TO_ME",
name: "ASSIGNED_TO_ME"
});


setDefaultSelectedHierarchy(selectedHierarchy);
setDefaultBoundaries(selectedBoundaries);
// Extract the list of codes from the selectedBoundaries array
const boundaryCodes = selectedBoundaries.map((boundary) => boundary.code);

Expand Down Expand Up @@ -257,6 +302,8 @@ const PlanInbox = () => {
}, [planEmployee]);

const onClear = () => {
setDefaultBoundaries([]);
setDefaultSelectedHierarchy(null);
setCensusJurisdiction(planEmployee?.planData?.[0]?.jurisdiction);
};

Expand Down Expand Up @@ -298,11 +345,15 @@ const PlanInbox = () => {
setCensusData(planWithCensus?.censusData);
setTotalRows(planWithCensus?.TotalCount);
const reorderedStatusCount = Object.fromEntries(
Object.entries(planWithCensus?.StatusCount || {}).sort(([keyA], [keyB]) => {
if (keyA === "PENDING_FOR_VALIDATION") return -1;
if (keyB === "PENDING_FOR_VALIDATION") return 1;
return 0;
})
Object.entries(planWithCensus?.StatusCount || {})
// Filter out the PENDING_FOR_APPROVAL status /// need to revisit as this is hardcoded to remove from workflow ///
.filter(([key]) => key !== "PENDING_FOR_APPROVAL")
// Sort the statuses, prioritizing PENDING_FOR_VALIDATION
.sort(([keyA], [keyB]) => {
if (keyA === "PENDING_FOR_VALIDATION") return -1;
if (keyB === "PENDING_FOR_VALIDATION") return 1;
return 0;
})
);
setActiveFilter(reorderedStatusCount);
const activeFilterKeys = Object.keys(reorderedStatusCount || {});
Expand Down Expand Up @@ -630,7 +681,7 @@ const PlanInbox = () => {
return false;
};

if (isLoadingPlanObject || isPlanEmpSearchLoading || isLoadingCampaignObject || isWorkflowLoading || isProcessLoading) {
if (isLoadingPlanObject || isPlanEmpSearchLoading || isLoadingCampaignObject || isWorkflowLoading || isProcessLoading || mutation.isLoading || isPlanWithCensusLoading) {
return <Loader />;
}
// campaignObject?.campaignName
Expand Down Expand Up @@ -679,6 +730,8 @@ const PlanInbox = () => {
</div>
<SearchJurisdiction
boundaries={boundaries}
defaultHierarchy={defaultHierarchy}
defaultBoundaries={defaultBoundaries}
jurisdiction={{
boundaryType: hierarchyLevel,
boundaryCodes: jurisdiction,
Expand All @@ -687,16 +740,12 @@ const PlanInbox = () => {
onClear={onClear}
/>

<div className="pop-inbox-wrapper-filter-table-wrapper" style={{ marginBottom: (isRootApprover && isStatusConditionMet(activeFilter) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS") || (!isRootApprover && isStatusConditionMet(activeFilter) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS") || disabledAction? "2.5rem" : "0rem" }}>
<div className="pop-inbox-wrapper-filter-table-wrapper" style={{ marginBottom: (isRootApprover && isStatusConditionMet(totalStatusCount) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS") || (!isRootApprover && isStatusConditionMet(totalStatusCount)) || disabledAction? "2.5rem" : "0rem" }}>
<InboxFilterWrapper
options={activeFilter}
onApplyFilters={onFilter}
clearFilters={clearFilters}
defaultValue={
selectedFilter === Object.entries(activeFilter)?.[0]?.[0]
? { [Object.entries(activeFilter)?.[0]?.[0]]: Object.entries(activeFilter)?.[0]?.[1] }
: null
}
defaultValue={ { [selectedFilter]: activeFilter[selectedFilter]} }
></InboxFilterWrapper>

<div className={"pop-inbox-table-wrapper"}>
Expand Down Expand Up @@ -790,6 +839,7 @@ const PlanInbox = () => {
closePopUp();
setShowToast({ key: "success", label: t(`PLAN_INBOX_WORKFLOW_FOR_${workFlowPopUp}_UPDATE_SUCCESS`), transitionTime: 5000 });
refetchPlanWithCensus();
fetchStatusCount();
}}
onError={(data) => {
closePopUp();
Expand All @@ -799,7 +849,7 @@ const PlanInbox = () => {
)}
</div>
)}
{isPlanWithCensusLoading ? (
{isFetching ? (
<Loader />
) : planWithCensus?.tableData?.length===0 ? <NoResultsFound style={{height:selectedFilter === "VALIDATED" ? "472px" : "408px"}} text={t(`HCM_MICROPLAN_NO_DATA_FOUND_FOR_PLAN_INBOX_PLAN`)} /> : (
<DataTable
Expand Down Expand Up @@ -829,7 +879,7 @@ const PlanInbox = () => {
</div>
</div>

{isRootApprover && isStatusConditionMet(activeFilter) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS" && (
{isRootApprover && isStatusConditionMet(totalStatusCount) && (
<ActionBar
actionFields={[
<Button
Expand All @@ -848,7 +898,7 @@ const PlanInbox = () => {
/>
)}

{(!isRootApprover && isStatusConditionMet(activeFilter) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS") || disabledAction && (
{(!isRootApprover && isStatusConditionMet(totalStatusCount) && planObject?.status === "RESOURCE_ESTIMATION_IN_PROGRESS") || disabledAction && (
<ActionBar
actionFields={[
<Button label={t(`HCM_MICROPLAN_PLAN_INBOX_BACK_BUTTON`)} onClick={()=> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const PopInbox = () => {
const [updatedCensus, setUpdatedCensus] = useState(null);
const [triggerTotalCensus, setTriggerTotalCensus] = useState(false);
const [totalStatusCount, setTotalStatusCount] = useState({});
const [defaultHierarchy, setDefaultSelectedHierarchy] = useState(null);
const [defaultBoundaries, setDefaultBoundaries] = useState([]);
const [limitAndOffset, setLimitAndOffset] = useState({ limit: rowsPerPage, offset: (currentPage - 1) * rowsPerPage });
const [activeLink, setActiveLink] = useState({
code: "ASSIGNED_TO_ME",
Expand All @@ -64,7 +66,7 @@ const PopInbox = () => {
},
},
{
enabled: isRootApprover ? true : false,
enabled: true,
// queryKey: currentKey,
}
);
Expand Down Expand Up @@ -153,7 +155,7 @@ const PopInbox = () => {
setactionBarPopUp(true);
};

const onSearch = (selectedBoundaries) => {
const onSearch = (selectedBoundaries, selectedHierarchy) => {

if (selectedBoundaries.length === 0) {
setShowToast({ key: "warning", label: t("MICROPLAN_BOUNDARY_IS_EMPTY_WARNING"), transitionTime: 5000 });
Expand All @@ -162,6 +164,9 @@ const PopInbox = () => {
code: "ASSIGNED_TO_ME",
name: "ASSIGNED_TO_ME"
});

setDefaultSelectedHierarchy(selectedHierarchy);
setDefaultBoundaries(selectedBoundaries);
// Extract the list of codes from the selectedBoundaries array
const boundaryCodes = selectedBoundaries.map((boundary) => boundary.code);

Expand Down Expand Up @@ -237,6 +242,8 @@ const PopInbox = () => {
}, [planEmployee]);

const onClear = () => {
setDefaultBoundaries([]);
setDefaultSelectedHierarchy(null);
setCensusJurisdiction(planEmployee?.planData?.[0]?.jurisdiction);
};

Expand Down Expand Up @@ -518,7 +525,7 @@ const PopInbox = () => {
},
];

if (isPlanEmpSearchLoading || isLoadingCampaignObject || isLoading || isWorkflowLoading || isEmployeeLoading || mutation.isLoading || isFetching) {
if (isPlanEmpSearchLoading || isLoadingCampaignObject || isLoading || isWorkflowLoading || isEmployeeLoading || mutation.isLoading) {
return <Loader />;
}

Expand Down Expand Up @@ -551,10 +558,12 @@ const PopInbox = () => {
</div>
<SearchJurisdiction
boundaries={boundaries}
defaultHierarchy={defaultHierarchy}
jurisdiction={{
boundaryType: hierarchyLevel,
boundaryCodes: jurisdiction,
}}
defaultBoundaries={defaultBoundaries}
onSubmit={onSearch}
onClear={onClear}
/>
Expand Down

0 comments on commit cfda909

Please sign in to comment.