Skip to content

Commit

Permalink
Role access table (#1593)
Browse files Browse the repository at this point in the history
* removed iterator

* changes

* EOD checkopoint

* validation for user role

* Response and user-employee validation working

* Pull from console

* console.log and debuggers removed

* index path for response

* Making some changes

* console removed

* random

* user access roles working

* localizations added

* Removed debuggera dn console

* Localizations

* Changes

* Delete package-lock.json

---------

Co-authored-by: nabeelmd-eGov <nabeel.md@egovernments.org>
  • Loading branch information
abishekTa-egov and nabeelmd-eGov authored Oct 21, 2024
1 parent 1def20d commit db1ff78
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,60 +1,55 @@
import React from 'react'
import React from 'react';
import { Card } from '@egovernments/digit-ui-components';
import HeaderComp from './HeaderComp';
import { useTranslation } from 'react-i18next';

const AssumptionsList = ({ customProps }) => {
const {t}=useTranslation();
const assumptionValues= customProps?.sessionData?.HYPOTHESIS.Assumptions?.assumptionValues
const { t } = useTranslation();

// Safely access assumptionValues using optional chaining
const assumptionValues = customProps?.sessionData?.HYPOTHESIS?.Assumptions?.assumptionValues || [];

let dic = {};

// Iterate through assumptionValues and build the dictionary
for (const ob of assumptionValues) {
if (!(ob?.category in dic)) {
dic[ob.category] = [{ [ob?.key]: ob.value }]
}else{
dic[ob.category].push({ [ob?.key]: ob.value })
const category = ob?.category || 'NA';
const key = ob?.key || 'NA';
const value = ob?.value || 'NA';

if (!(category in dic)) {
dic[category] = [{ [key]: value }];
} else {
dic[category].push({ [key]: value });
}
}








return (
<div>
{
Object.keys(dic).map((item, ind) => {

return (
< Card key={`card_${ind}`} style={{ padding: '20px', marginBottom: '15px' }}>
<HeaderComp title={String(item)}/>
<div className="as-table-like">
{dic[item].map((item1, index) => {
// Since each item1 is an object with a single key-value pair
const [key, value] = Object.entries(item1)[0]; // Destructure the first and only key-value pair
return (
<div key={`pair_${index}`} className="as-table-row">
<span className="as-table-cell as-key-cell">
<strong>{t(key)}</strong> {/* Display key as label */}
</span>
<span className="as-table-cell as-value-cell">
{t(value)} {/* Display value */}
</span>
</div>
);
})}
</div>
</Card>
);
})
}


</div >
)
}

export default AssumptionsList
{Object.keys(dic).map((item, ind) => (
<Card key={`card_${ind}`} style={{ padding: '20px', marginBottom: '15px' }}>
<HeaderComp title={String(item)} />
<div className="as-table-like">
{dic[item].map((item1, index) => {
// Safely destructure the key-value pair, with fallbacks for missing data
const [key, value] = Object.entries(item1)[0] || ['NA', 'NA'];

return (
<div key={`pair_${index}`} className="as-table-row">
<span className="as-table-cell as-key-cell">
<strong>{t(key)}</strong> {/* Display key as label */}
</span>
<span className="as-table-cell as-value-cell">
{t(value)} {/* Display value */}
</span>
</div>
);
})}
</div>
</Card>
))}
</div>
);
};

export default AssumptionsList;
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ import React, { useState, Fragment } from "react";
import { Link, useHistory, useLocation } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { ActionBar, SubmitBar, ArrowLeft, ArrowForward } from "@egovernments/digit-ui-react-components";
import { Button } from "@egovernments/digit-ui-components";
import { PanelCard } from "@egovernments/digit-ui-components";
import { Button } from "@egovernments/digit-ui-react-components";
const Response = () => {

const { t } = useTranslation();
const history = useHistory();
const queryStrings = Digit.Hooks.useQueryParams();
Expand All @@ -14,6 +13,8 @@ const Response = () => {
queryStrings?.isSuccess === "true" ? true : queryStrings?.isSuccess === "false" ? false : true
);
const { state } = useLocation();
const back=(state?.back)?state?.back:"BACK";
const backlink=(state?.backlink)?(state.backlink):"employee";
return (
<>
<PanelCard
Expand All @@ -25,7 +26,7 @@ const Response = () => {
cardStyles={{}}
className=""
customIcon=""
description="The user data uploaded will be available in your microplan user assignment section"
description={t(state.description)}
// footerChildren={[
// <Button label="OK" onClick={function noRefCheck() { }} type="button" />
// ]}
Expand All @@ -36,21 +37,21 @@ const Response = () => {
message={t(state?.message)}
multipleResponses={[]}
props={{}}
response={state?.fileName}
response={t(state?.fileName)}
sortFooterButtons
style={{}}
type="success"
>

</PanelCard>
<ActionBar className="mc_back">
<Link to={`/${window.contextPath}/employee/microplan/user-management`}>
<Link to={`/${window.contextPath}${backlink}`}>
<Button
style={{ margin: "0.5rem", minWidth: "12rem", marginLeft: "6rem" }}
style={{ margin: "0.5rem", minWidth: "10rem", marginLeft: "6rem" }}
className="previous-button"
variation="secondary"
label={t("BACK")}
icon="ArrowBack"
label={t(back)}
icon={"ArrowBack"}
/>
</Link>
</ActionBar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import { useUserAccessContext } from "./UserAccessWrapper";
import { useMyContext } from "../utils/context";
import { useQueryClient } from "react-query";

function RoleTableComposer() {
function RoleTableComposer({ nationalRoles }) {
const { t } = useTranslation();
const queryClient = useQueryClient();
const tenantId = Digit.ULBService.getCurrentTenantId();
const totalFormData = Digit.SessionStorage.get("MICROPLAN_DATA");
const selectedData = totalFormData?.BOUNDARY?.boundarySelection?.selectedData ? totalFormData?.BOUNDARY?.boundarySelection?.selectedData : [];
const selectedData = totalFormData?.BOUNDARY?.boundarySelection?.selectedData || [];
const { hierarchyData, category } = useUserAccessContext();
const { state } = useMyContext();
const [rowData, setRowData] = useState([]);
Expand All @@ -27,6 +27,7 @@ function RoleTableComposer() {
const { mutate: planEmployeeCreate } = Digit.Hooks.microplanv1.usePlanEmployeeCreate();
const { mutate: planEmployeeUpdate } = Digit.Hooks.microplanv1.usePlanEmployeeUpdate();

const topBoundary = state?.boundaryHierarchy.find(boundary => boundary.parentBoundaryType === null);
const { isLoading: isHrmsLoading, data: HrmsData, error: hrmsError, refetch: refetchHrms } = Digit.Hooks.microplanv1.useSearchHRMSEmployee({
tenantId: tenantId,
microplanId: microplanId,
Expand All @@ -46,9 +47,10 @@ function RoleTableComposer() {
number: item?.user?.mobileNumber,
employeeId: item?.user?.userServiceUuid,
user: item?.user,
selectedHierarchy: state?.boundaryHierarchy?.find(
(j) => j.boundaryType === data?.planData?.find((i) => i.employeeId === item?.user?.userServiceUuid)?.hierarchyLevel
),
selectedHierarchy: nationalRoles?.includes(category) ? topBoundary :
state?.boundaryHierarchy?.find(
(j) => j.boundaryType === data?.planData?.find((i) => i.employeeId === item?.user?.userServiceUuid)?.hierarchyLevel
),
selectedBoundaries: data?.planData?.find((i) => i.employeeId === item?.user?.userServiceUuid)?.jurisdiction,
userServiceUuid: item?.user?.userServiceUuid,
planData: data?.planData?.find((i) => i.employeeId === item?.user?.userServiceUuid),
Expand Down Expand Up @@ -78,7 +80,7 @@ function RoleTableComposer() {
userServiceUuid: employee?.userServiceUuid,
selectedHierarchy: employee?.selectedHierarchy || null,
boundaryOptions: boundaryOptions || [],
selectedBoundaries: filteredBoundary.filter((item) => employee?.selectedBoundaries.includes(item.code)) || [],
selectedBoundaries: filteredBoundary.filter((item) => employee?.selectedBoundaries?.includes(item?.code)) || [],
};
});

Expand Down Expand Up @@ -119,11 +121,11 @@ function RoleTableComposer() {
return prev.map((i) =>
i.rowIndex === row.rowIndex
? {
...i,
selectedHierarchy: value,
boundaryOptions,
selectedBoundaries: i.selectedBoundaries || [], // Keep existing selected boundaries
}
...i,
selectedHierarchy: value,
boundaryOptions,
selectedBoundaries: i.selectedBoundaries || [], // Keep existing selected boundaries
}
: i
);
} else {
Expand Down Expand Up @@ -177,9 +179,9 @@ function RoleTableComposer() {
return prev.map((i) =>
i.rowIndex === row.rowIndex
? {
...i,
selectedBoundaries: [], // Clear selected boundaries
}
...i,
selectedBoundaries: [], // Clear selected boundaries
}
: i
);
} else {
Expand Down Expand Up @@ -208,9 +210,9 @@ function RoleTableComposer() {
return prev.map((i) =>
i.rowIndex === row.rowIndex
? {
...i,
selectedBoundaries: boundariesInEvent, // Update boundaries
}
...i,
selectedBoundaries: boundariesInEvent, // Update boundaries
}
: i
);
} else {
Expand Down Expand Up @@ -271,46 +273,45 @@ function RoleTableComposer() {

const columns = [
{
name: "Name",
name: t("NAME"),
selector: (row) => {
return row.name;
},
sortable: true,
},
{
name: "Email",
name: t("EMAIL"),
selector: (row) => row.email,
sortable: true,
},
{
name: "Contact Number",
name:t("CONTACT_NUMBER"),
selector: (row) => {
return row.number;
},
sortable: true,
},
{
name: "Hierarchy",
name: t("HIERARCHY"),
cell: (row) => {
return (
<Dropdown
className="roleTableCell"
selected={rowData?.find((item) => item?.rowIndex === row?.rowIndex)?.selectedHierarchy || null}
disable={false}
isMandatory={true}
option={state?.boundaryHierarchy}
select={(value) => {
row.selectedHeirarchy = value;
handleHierarchyChange(value, row);
}}
optionKey="boundaryType"
t={t}
/>
);
},
return <Dropdown
className="roleTableCell"
selected={rowData?.find((item) => item?.rowIndex === row?.rowIndex)?.selectedHierarchy || null}
disabled={nationalRoles?.includes(category) ? true : false}
isMandatory={true}
option={state?.boundaryHierarchy}
select={(value) => {
row.selectedHeirarchy = value;
handleHierarchyChange(value, row);
}}
optionKey="boundaryType"
t={t}
/>;
}
},

{
name: "Selected Boundary",
name: t("SELECTED_BOUNDARY"),
cell: (row) => (
<MultiSelectDropdown
props={{ className: "roleTableCell" }}
Expand All @@ -326,12 +327,12 @@ function RoleTableComposer() {
),
},
{
name: "Action",
name: t("ACTION"),
cell: (row) => {
const isUserAlreadyAssigned = HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 ? true : false;
const isUserAlreadyAssignedActive =
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.length > 0 &&
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.[0]?.active
HrmsData?.planSearchData?.filter((i) => i.employeeId === row.employeeId)?.[0]?.active
? true
: false;
return (
Expand Down Expand Up @@ -371,7 +372,9 @@ function RoleTableComposer() {
const closeToast = () => {
setShowToast(null);
};
if (isHrmsLoading) return <Loader />;
if (isHrmsLoading) {
return <Loader />
};
return (
<>
<Card>
Expand Down
Loading

0 comments on commit db1ff78

Please sign in to comment.