Skip to content

Commit

Permalink
added the Workbench module patches into develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Swathi-eGov committed Dec 30, 2024
1 parent 5e2fe14 commit 817ba82
Show file tree
Hide file tree
Showing 21 changed files with 489 additions and 71 deletions.
2 changes: 1 addition & 1 deletion micro-ui/web/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@egovernments/digit-ui-module-open-payment":"0.0.1",
"@egovernments/digit-ui-module-hrms": "1.8.10",
"@egovernments/digit-ui-module-pgr": "1.8.10",
"@egovernments/digit-ui-react-components": "1.8.13",
"@egovernments/digit-ui-react-components": "1.8.14",
"babel-loader": "8.1.0",
"react": "17.0.2",
"react-dom": "17.0.2",
Expand Down
4 changes: 2 additions & 2 deletions micro-ui/web/micro-ui-internals/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"devDependencies": {
"@egovernments/digit-ui-libraries": "1.8.7",
"@egovernments/digit-ui-module-workbench": "1.0.11",
"@egovernments/digit-ui-module-workbench": "1.0.12",
"@egovernments/digit-ui-module-pgr": "1.8.10",
"@egovernments/digit-ui-module-dss": "1.8.10",
"@egovernments/digit-ui-module-core": "1.8.14",
Expand All @@ -20,7 +20,7 @@
"@egovernments/digit-ui-module-open-payment":"0.0.1",
"@egovernments/digit-ui-module-engagement": "1.5.20",
"@egovernments/digit-ui-components":"0.0.2-beta.58",
"@egovernments/digit-ui-react-components": "1.8.13",
"@egovernments/digit-ui-react-components": "1.8.14",
"@egovernments/digit-ui-module-sandbox": "0.0.1",
"http-proxy-middleware": "^1.0.5",
"react": "17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion micro-ui/web/micro-ui-internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"lodash": "4.17.21",
"microbundle-crl": "0.13.11",
"@egovernments/digit-ui-components":"0.0.2-beta.58",
"@egovernments/digit-ui-react-components": "1.8.13",
"@egovernments/digit-ui-react-components": "1.8.14",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-hook-form": "6.15.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@egovernments/digit-ui-components":"0.0.2-beta.58",
"@egovernments/digit-ui-react-components": "1.8.13",
"@egovernments/digit-ui-react-components": "1.8.14",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-i18next": "11.16.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-module-workbench",
"version": "1.0.11",
"version": "1.0.12",
"description": "Workbench",
"main": "dist/index.js",
"module": "dist/index.modern.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function CustomFieldTemplate(props) {
{/* <span >{label}</span> */}
<span className={`tooltip`}>
{t(titleCode)} {additionalCode}
<span className="tooltiptext">
<span className="tooltiptext" style={{maxWidth:"540px"}}>
<span className="tooltiptextvalue">{t(`TIP_${titleCode}`)}</span>
</span>
</span>
Expand Down Expand Up @@ -279,6 +279,8 @@ const DigitJSONForm = ({
};
const person = { t: t };

const formDisabled = screenType === "view" ? true : disabled;

return (
<React.Fragment>
<Header className="digit-form-composer-header">
Expand Down Expand Up @@ -312,7 +314,7 @@ const DigitJSONForm = ({
transformErrors={transformErrors.bind(person)}
uiSchema={{ ...uiSchema, ...inputUiSchema }}
onError={onError}
disabled={disabled}
disabled={formDisabled}
// disabled the error onload
// focusOnFirstError={true}
/* added logic to show live validations after form submit is clicked */
Expand All @@ -331,7 +333,7 @@ const DigitJSONForm = ({
{/* <LinkButton style={props?.skipStyle} label={t(`CS_SKIP_CONTINUE`)} /> */}
</ActionBar>
)}
{screenType === "view" && (
{screenType === "view" && viewActions && viewActions.length > 0 && (
<ActionBar>
{displayMenu ? (
<Menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,17 @@ const CustomSelectWidget = (props) => {
/*
logic added to fetch data of schemas in each component itself
*/

const limit = schemaCode === "WORKS-SOR.SOR" ? 1000 : 100;

const reqCriteriaForData = {
url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`,
params: {},
body: {
MdmsCriteria: {
tenantId: tenantId,
schemaCode: schemaCode,
limit: 100,
limit: limit,
offset: 0
},
},
Expand Down Expand Up @@ -85,12 +88,31 @@ const CustomSelectWidget = (props) => {
() => optionsList.map((e) => ({ label: t(Digit.Utils.locale.getTransformedLocale(`${schemaCode}_${e?.label}`)), value: e.value })),
[optionsList, schemaCode, data]
);
const [formattedOptions2, setFormattedOptions2] = useState([]);
const [limitedOptions, setLimitedOptions] = useState([]);
const [selectedDetails, setSelectedDetails] = useState(null);
const [showDetails, setShowDetails] = useState(null);
const [isSelect, setIsSelect] = useState(false);
const [showModal, setShowModal] = useState(false);
const [isSeeAll, setIsSeeAll] = useState(false);

const fetchDetailsForSelectedOption = async (value) => {
const response = await Digit.CustomService.getResponse({
url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`,
body: JSON.stringify({
MdmsCriteria: {
tenantId,
schemaCode,
filters: { "id": value },
},
}),
params: {},
});
const result = await response.json();
setSelectedDetails([result?.mdms?.[0]]);
setShowDetails([result?.mdms?.[0]]);
};

const handleSeeAll = () => {
setShowModal(true);
}
Expand All @@ -111,7 +133,7 @@ const CustomSelectWidget = (props) => {
</div>
)
}
const selectedOption = formattedOptions?.filter((obj) => (multiple ? value?.includes(obj.value) : obj.value == value));
const selectedOption = formattedOptions2?.filter((obj) => (multiple ? value?.includes(obj.value) : obj.value == value));
const handleChange = (selectedValue) => {
setShowTooltipFlag(true);
setIsSelect(true);
Expand All @@ -130,7 +152,18 @@ const CustomSelectWidget = (props) => {
setIsSeeAll(true);
}
setSelectedDetails(mainData?.filter((obj) => (multiple ? value?.includes(obj.uniqueIdentifier) : obj.uniqueIdentifier == value)));
}, [formattedOptions, optionsLimit]);
// Update formattedOptions2
let newFormattedOptions2 = [...formattedOptions];
if (value && value !== "") {
const existingOption = formattedOptions.find((option) => option.value === value);
if (!existingOption) {
const formattedLabel = `${schemaCode}_${value}`.replace(/[-.]/g, "_");
newFormattedOptions2.push({ value, label: formattedLabel });
fetchDetailsForSelectedOption(value);
}
}
setFormattedOptions2(newFormattedOptions2);
}, [formattedOptions, optionsLimit, value]);
const onClickSelect = (selectedValue) => {
selectedValue = { ...selectedValue, "value": selectedValue.uniqueIdentifier, "label": selectedValue.description };
onChange(selectedValue.uniqueIdentifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Link, useHistory } from "react-router-dom";
import _ from "lodash";
import React from 'react';
import { Button } from "@egovernments/digit-ui-react-components";
import axios from "axios";

//create functions here based on module name set in mdms(eg->SearchProjectConfig)
//how to call these -> Digit?.Customizations?.[masterName]?.[moduleName]
Expand All @@ -16,6 +17,28 @@ const inboxModuleNameMap = {
"muster-roll-approval": "muster-roll-service",
};

const convertDateToEpoch = (dateString) => {
if (!dateString) {
return "NA";
}
const [day, month, year] = dateString.split('/');
const dateObject = new Date(`${year}-${month}-${day}T00:00:00`);
const options = { timeZone: 'Asia/Kolkata' };
const istDateObject = new Date(dateObject.toLocaleString('en-US', options));
return istDateObject.getTime();
};

const convertEpochToDate = (dateEpoch) => {
if (!dateEpoch || dateEpoch == null || dateEpoch == undefined || dateEpoch == "") {
return "NA";
}
const dateObject = new Date(dateEpoch);
const day = String(dateObject.getDate()).padStart(2, '0');
const month = String(dateObject.getMonth() + 1).padStart(2, '0');
const year = dateObject.getFullYear();
return `${day}/${month}/${year}`;
};

export const UICustomizations = {
businessServiceMap,
updatePayload: (applicationDetails, data, action, businessService) => {
Expand Down Expand Up @@ -505,6 +528,11 @@ export const UICustomizations = {
//like if a cell is link then we return link
//first we can identify which column it belongs to then we can return relevant result
switch (key) {
case "WORKS_SOR_RATES_VALIDFROM":
case "WORKS_SOR_COMPOSITION_EFFECTIVEFROM":
case "WORKS_SOR_RATES_VALIDTO":
case "WORKS_SOR_COMPOSITION_EFFECTIVETO":
return value ? convertEpochToDate(Number(value)) : t("ES_COMMON_NA");
case "WBH_UNIQUE_IDENTIFIER":
const [moduleName, masterName] = row.schemaCode.split(".")
return (
Expand Down Expand Up @@ -809,5 +837,167 @@ export const UICustomizations = {
return defaultData

}
}
},
ViewMdmsConfig: {
fetchActionItems: (data, props) => {
let hostname = window.location.hostname;

let roleActions = {
ADD_SOR_COMPOSITION: ["MDMS_STATE_ADMIN"],
VIEW_RATE_ANALYSIS: ["MDMS_STATE_ADMIN", "MDMS_CITY_ADMIN"],
};
const getUserRoles = Digit.SessionStorage.get("User")?.info?.roles;

const roles = getUserRoles?.map((role) => {
return role.code;
});
const hasRoleAccess = (action) => {
const allowedRoles = roleActions[action] || [];
return roles.some((role) => allowedRoles.includes(role));
};

let actionItems = [
{
action: "EDIT",
label: "Edit Master",
},
];

const isActive = data?.isActive;
if (isActive)
actionItems.push({
action: "DISABLE",
label: "Disable Master",
});
else
actionItems.push({
action: "ENABLE",
label: "Enable Master",
});

switch (true) {
case hostname.includes("mukta-uat") || hostname.includes("localhost") || hostname.includes("mukta.odisha"): {
if (data?.data?.sorType?.includes("W")) {
if (isActive && hasRoleAccess("ADD_SOR_COMPOSITION"))
actionItems?.push({
action: "ADD_SOR_COMPOSITION",
label: "Add SOR Composition",
});
if (hasRoleAccess("VIEW_RATE_ANALYSIS")) {
actionItems.push({
action: "VIEW_RATE_ANALYSIS",
label: "View Rate Analysis",
});
}
}
if (props?.masterName === "Rates") {
actionItems = actionItems.filter((ac) => ac?.action !== "DISABLE");
}

if (props?.masterName === "Rates" && props?.sorData?.data?.sorType === "W") {
actionItems = actionItems.filter((ac) => ac?.action !== "EDIT");
}
}
}
return actionItems;
},
onActionSelect: (action, props) => {
const { action: actionSelected } = action;
//to ADD SOR Composition
if (actionSelected === "ADD_SOR_COMPOSITION") {
window.location.href = `/works-ui/employee/rateanalysis/create-rate-analysis?sorid=${props?.uniqueIdentifier}`;
} else if (actionSelected === "VIEW_RATE_ANALYSIS") {
window.location.href = `/works-ui/employee/rateanalysis/view-rate-analysis?sorId=${
props?.masterName === "Composition" ? props?.data?.data?.sorId : props?.uniqueIdentifier
}&fromeffective=${props?.masterName === "Composition" ? props?.data?.data?.effectiveFrom : Date.now()}`;
}
//action===EDIT go to edit screen
else if (actionSelected === "EDIT") {
props?.history.push(
`/${window?.contextPath}/employee/workbench/mdms-edit?moduleName=${props?.moduleName}&masterName=${props?.masterName}&uniqueIdentifier=${props?.uniqueIdentifier}`
);
}
//action===DISABLE || ENABLE call update api and show toast respectively
else {
//call update mutation
props?.handleEnableDisable(actionSelected);
}
},
},
AddMdmsConfig: {
"WORKS-SOR.Rates": {
getTrasformedData: async (formData, data) => {
return { ...formData, validFrom: data?.data?.validFrom };
},
validateForm: async (data, props) => {
try {
const response = await axios.post("/mdms-v2/v2/_search", {
MdmsCriteria: {
tenantId: props?.tenantId?.split(".")[0],
uniqueIdentifiers: [data.sorId],
schemaCode: "WORKS-SOR.SOR",
},
});

const validFrom = data?.validFrom;
const validTo = data?.validTo;

if (validFrom > validTo) {
return { isValid: false, message: "RA_DATE_RANGE_ERROR" };
}

if (response?.data?.mdms?.[0]?.data?.sorType !== "W") {
return { isValid: true };
} else {
return { isValid: false, message: "RATE_NOT_ALLOWED_FOR_W_TYPE" };
}
} catch (error) {
return { isValid: false, message: "VALIDATION_ERROR" };
}
},
},
"WORKS-SOR.Composition": {
getTrasformedData: async (formData, data) => {
return { ...formData, effectiveFrom: data?.data?.effectiveFrom };
},
},
},
SearchMDMSv2Config: {
"WORKS-SOR.Rates": {
sortValidDatesFirst: (arr) => {
const validFrom = arr.find((item) => item.name === "validFrom");
const validTo = arr.find((item) => item.name === "validTo");

if (validFrom && validTo) {
const validFromIndex = arr.indexOf(validFrom);
const validToIndex = arr.indexOf(validTo);

if (validFromIndex > validToIndex) {
arr.splice(validFromIndex, 1);
arr.splice(validToIndex, 0, validFrom);
}
}

return arr;
},
},
"WORKS-SOR.Composition": {
sortValidDatesFirst: (arr) => {
const validFrom = arr.find((item) => item.name === "effectiveFrom");
const validTo = arr.find((item) => item.name === "effectiveTo");

if (validFrom && validTo) {
const validFromIndex = arr.indexOf(validFrom);
const validToIndex = arr.indexOf(validTo);

if (validFromIndex > validToIndex) {
arr.splice(validFromIndex, 1);
arr.splice(validToIndex, 0, validFrom);
}
}

return arr;
},
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const Config = {
filterFormJsonPath: "requestBody.MdmsCriteria.custom",
searchFormJsonPath: "requestBody.MdmsCriteria.custom"
},
customHook:"useMDMSPopupSearch",
sections: {
search: {
uiConfig: {
Expand Down
Loading

0 comments on commit 817ba82

Please sign in to comment.