From 817ba827f14b53abeb223d1ec6598408783d8d24 Mon Sep 17 00:00:00 2001 From: Swathi-eGov Date: Mon, 30 Dec 2024 18:01:22 +0530 Subject: [PATCH] added the Workbench module patches into develop branch --- micro-ui/web/core/package.json | 2 +- .../micro-ui-internals/example/package.json | 4 +- micro-ui/web/micro-ui-internals/package.json | 2 +- .../packages/modules/core/package.json | 2 +- .../packages/modules/workbench/package.json | 2 +- .../workbench/src/components/DigitJSONForm.js | 8 +- .../workbench/src/components/MultiSelect.js | 39 +++- .../workbench/src/configs/UICustomizations.js | 192 +++++++++++++++++- .../src/configs/searchMDMSConfigPopup.js | 1 + .../modules/workbench/src/hooks/inbox.js | 116 +++++++++++ .../modules/workbench/src/hooks/index.js | 4 + .../workbench/src/pages/employee/MDMSAddV2.js | 14 +- .../workbench/src/pages/employee/MDMSEdit.js | 37 +++- .../src/pages/employee/MDMSSearchv2.js | 20 +- .../workbench/src/pages/employee/MDMSView.js | 74 ++++--- .../modules/workbench/src/utils/index.js | 23 ++- .../packages/react-components/package.json | 2 +- .../react-components/src/atoms/BreadCrumb.js | 8 +- micro-ui/web/package.json | 4 +- micro-ui/web/sandbox/package.json | 4 +- micro-ui/web/workbench/package.json | 2 +- 21 files changed, 489 insertions(+), 71 deletions(-) create mode 100644 micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/inbox.js diff --git a/micro-ui/web/core/package.json b/micro-ui/web/core/package.json index 2b742ce7c25..3bec0d41c74 100644 --- a/micro-ui/web/core/package.json +++ b/micro-ui/web/core/package.json @@ -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", diff --git a/micro-ui/web/micro-ui-internals/example/package.json b/micro-ui/web/micro-ui-internals/example/package.json index 11aede3eb0a..3ddff393f1d 100644 --- a/micro-ui/web/micro-ui-internals/example/package.json +++ b/micro-ui/web/micro-ui-internals/example/package.json @@ -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", @@ -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", diff --git a/micro-ui/web/micro-ui-internals/package.json b/micro-ui/web/micro-ui-internals/package.json index f8f56d67ac2..354e9a47438 100644 --- a/micro-ui/web/micro-ui-internals/package.json +++ b/micro-ui/web/micro-ui-internals/package.json @@ -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", diff --git a/micro-ui/web/micro-ui-internals/packages/modules/core/package.json b/micro-ui/web/micro-ui-internals/packages/modules/core/package.json index 4925528cbef..b8f3d076dee 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/core/package.json +++ b/micro-ui/web/micro-ui-internals/packages/modules/core/package.json @@ -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", diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/package.json b/micro-ui/web/micro-ui-internals/packages/modules/workbench/package.json index da02e619f16..1be40d6581f 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/package.json +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/package.json @@ -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", diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/DigitJSONForm.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/DigitJSONForm.js index 8f4101875b9..dffd99e85d6 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/DigitJSONForm.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/components/DigitJSONForm.js @@ -218,7 +218,7 @@ function CustomFieldTemplate(props) { {/* {label} */} {t(titleCode)} {additionalCode} - + {t(`TIP_${titleCode}`)} @@ -279,6 +279,8 @@ const DigitJSONForm = ({ }; const person = { t: t }; + const formDisabled = screenType === "view" ? true : disabled; + return (
@@ -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 */ @@ -331,7 +333,7 @@ const DigitJSONForm = ({ {/* */} )} - {screenType === "view" && ( + {screenType === "view" && viewActions && viewActions.length > 0 && ( {displayMenu ? ( { /* 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: {}, @@ -56,7 +59,7 @@ const CustomSelectWidget = (props) => { MdmsCriteria: { tenantId: tenantId, schemaCode: schemaCode, - limit: 100, + limit: limit, offset: 0 }, }, @@ -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); } @@ -111,7 +133,7 @@ const CustomSelectWidget = (props) => { ) } - 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); @@ -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); diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/UICustomizations.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/UICustomizations.js index c02b9ed31fc..32468e01b14 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/UICustomizations.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/UICustomizations.js @@ -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] @@ -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) => { @@ -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 ( @@ -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; + }, + }, + }, }; diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/searchMDMSConfigPopup.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/searchMDMSConfigPopup.js index 81a81bd1633..35aa6065ef8 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/searchMDMSConfigPopup.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/configs/searchMDMSConfigPopup.js @@ -18,6 +18,7 @@ export const Config = { filterFormJsonPath: "requestBody.MdmsCriteria.custom", searchFormJsonPath: "requestBody.MdmsCriteria.custom" }, + customHook:"useMDMSPopupSearch", sections: { search: { uiConfig: { diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/inbox.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/inbox.js new file mode 100644 index 00000000000..53118ff980a --- /dev/null +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/inbox.js @@ -0,0 +1,116 @@ +import { useQuery, useQueryClient } from "react-query"; +import axios from "axios"; + +const useMDMSPopupSearch = (criteria) => { + const [moduleName, masterName] = criteria?.body?.MdmsCriteria?.schemaCode?.split("."); + + const reqCriteriaForSchema = { + url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`, + params: {}, + body: { + SchemaDefCriteria: { + tenantId: criteria?.body?.MdmsCriteria?.tenantId, + codes: [criteria?.body?.MdmsCriteria?.schemaCode], + }, + }, + config: { + enabled: moduleName && masterName && true, + select: (data) => { + if (data?.SchemaDefinitions?.length == 0) { + setNoSchema(true); + } + if (data?.SchemaDefinitions?.[0]?.definition?.["x-ui-schema"]?.["ui-apidetails"]) { + setAPI(data?.SchemaDefinitions?.[0]?.definition?.["x-ui-schema"]?.["ui-apidetails"]); + } + return data?.SchemaDefinitions?.[0] || {}; + }, + }, + changeQueryName: "schema", + }; + + const { isSchemaLoading, data: schema } = Digit.Hooks.useCustomAPIHook(reqCriteriaForSchema); + + const updatedCriteria = { ...criteria }; + + // Update filters + if (updatedCriteria.state?.searchForm) { + const { field, value } = updatedCriteria.state.searchForm; + if (field && value !== undefined) { + updatedCriteria.body.MdmsCriteria = { + ...updatedCriteria.body.MdmsCriteria, + tenantId: updatedCriteria.body.MdmsCriteria.tenantId, + filters: { + ...(updatedCriteria.body.MdmsCriteria.filters || {}), + [field.code]: value, + }, + }; + } + } + // Update limit and offset + if (updatedCriteria.state?.tableForm) { + const { limit, offset } = updatedCriteria.state.tableForm; + updatedCriteria.body.MdmsCriteria = { + ...updatedCriteria.body.MdmsCriteria, + limit, + offset, + }; + } + + const { url, params, body, config = {}, changeQueryName = "Random" } = updatedCriteria; + const client = useQueryClient(); + + const fetchData = async () => { + try { + const response = await axios.post(url, body, { params }, config); + return response.data; + } catch (error) { + throw new Error("Error fetching data"); + } + }; + + const { isLoading, data, isFetching, refetch, error } = useQuery( + [url, params, body, "popup"].filter((e) => e), + fetchData, + { + cacheTime: 0, + ...config, + select: (data) => { + const respData = data?.mdms?.map((e) => ({ label: e?.uniqueIdentifier, value: e?.uniqueIdentifier })); + + if (schema?.definition?.["x-ref-schema"]?.length > 0) { + schema?.definition?.["x-ref-schema"]?.map((dependent) => { + if (dependent?.fieldPath) { + let updatedPath = Digit.Utils.workbench.getUpdatedPath(dependent?.fieldPath); + const property = _.get(schema?.definition?.properties, updatedPath); + if (property) { + const existingEnum = property.enum || []; + const newValues = respData?.map((e) => e.value).filter((value) => !existingEnum.includes(value)); + if (newValues && newValues.length > 0) { + const updatedEnum = [...existingEnum, ...newValues]; + _.set(schema?.definition?.properties, updatedPath, { + ...property, + enum: updatedEnum, + }); + } + } + } + }); + } + return data; + }, + } + ); + + return { + isLoading, + data, + isFetching, + revalidate: () => { + data && client.invalidateQueries([url].filter((e) => e)); + }, + refetch, + error, + }; +}; + +export default useMDMSPopupSearch; \ No newline at end of file diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/index.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/index.js index 6057e073507..99a5e133852 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/hooks/index.js @@ -4,6 +4,7 @@ import utils from "../utils"; import useLocalisationSearch from "./useLocalisationSearch"; import {useWorkbenchFormContext} from "./useWorkbenchFormContext"; import usePureSchemaDefinition from "./fetchPureSchemaDefinition"; +import useMDMSPopupSearch from "./inbox"; const UserService = { logoutV1, @@ -27,6 +28,9 @@ const Hooks = { }, workbench, contracts, + inbox:{ + useMDMSPopupSearch, + } }; const Utils = { diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js index af26816e77d..487dbd0da87 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSAddV2.js @@ -93,14 +93,22 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie } const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaAdd); - const onSubmit = (data) => { + const schemaCodeToValidate = `${moduleName}.${masterName}`; + const onSubmit = async (data) => { + const validation = await Digit?.Customizations?.["commonUiConfig"]?.["AddMdmsConfig"]?.[schemaCodeToValidate]?.validateForm(data, { tenantId: tenantId }); + if (validation && !validation?.isValid) { + setShowToast(t(validation.message)); + setShowErrorToast(true); + toggleSpinner(false); + return; + } toggleSpinner(true); const onSuccess = (resp) => { toggleSpinner(false); setSessionFormData({}); setSession({}); setShowErrorToast(false); - const jsonPath = api?.responseJson ? api?.responseJson : "mdms[0].id"; + const jsonPath = masterName==="SOR" ? api?.responseJson ? api?.responseJson : "mdms[0].uniqueIdentifier" : api?.responseJson ? api?.responseJson : "mdms[0].id" ; setShowToast(`${t("WBH_SUCCESS_MDMS_MSG")} ${_.get(resp, jsonPath, "NA")}`); closeToast(); gotoView(); @@ -109,7 +117,7 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie }; const onError = (resp) => { toggleSpinner(false); - setShowToast(`${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`); + setShowToast(`${t("WBH_ERROR_MDMS_DATA")}! ${t(resp?.response?.data?.Errors?.[0]?.code)}`); setShowErrorToast(true); closeToast(); }; diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js index 09153c53941..a8e37c1d965 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSEdit.js @@ -32,7 +32,7 @@ const MDMSEdit = ({...props}) => { }; const reqCriteriaSchema = { - url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`, + url: Digit.Utils.workbench.getMDMSActionURL(moduleName,masterName,"update"), params: {}, body: { SchemaDefCriteria: { @@ -82,6 +82,18 @@ const MDMSEdit = ({...props}) => { const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate); const handleUpdate = async (formData) => { + const schemaCodeToValidate = `${moduleName}.${masterName}`; + let transformedData = await Digit?.Customizations?.["commonUiConfig"]?.["AddMdmsConfig"]?.[schemaCodeToValidate]?.getTrasformedData(formData, data) ; + transformedData = transformedData && transformedData !== undefined && transformedData !== "undefined" ? transformedData : formData; + const validation = await Digit?.Customizations?.["commonUiConfig"]?.["AddMdmsConfig"]?.[schemaCodeToValidate]?.validateForm(transformedData, { tenantId: stateId }); + + if (validation && !validation?.isValid) { + setShowToast({ + label: `${t("RA_DATE_RANGE_ERROR")}`, + isError: true + }); + return; + } const onSuccess = (resp) => { @@ -109,7 +121,7 @@ const MDMSEdit = ({...props}) => { body: { Mdms:{ ...data, - data:formData + data:transformedData }, }, }, @@ -121,11 +133,30 @@ const MDMSEdit = ({...props}) => { } + 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}`; + }; + + const formattedData = data?.data + ? { + ...data?.data, + validFrom: convertEpochToDate(Number(data?.data?.validFrom)), + } + : null; + + if(isLoading || isLoadingSchema || renderLoader ) return return ( - + {showToast && setShowToast(null)} >} ) diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSSearchv2.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSSearchv2.js index 32c1b68ec11..9ff84b83058 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSSearchv2.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSSearchv2.js @@ -109,11 +109,11 @@ const MDMSSearchv2 = () => { useEffect(() => { if (currentSchema) { - const dropDownOptions = []; + let dropDownOptions = []; const { definition: { properties }, } = currentSchema; - + const schemaCodeToValidate = `${master}.${modulee}`; Object.keys(properties)?.forEach((key) => { if (properties[key].type === "string" && !properties[key].format) { dropDownOptions.push({ @@ -124,7 +124,11 @@ const MDMSSearchv2 = () => { }); } }); - + dropDownOptions = + dropDownOptions?.length > 0 && + Digit?.Customizations?.["commonUiConfig"]?.["SearchMDMSv2Config"]?.[schemaCodeToValidate]?.sortValidDatesFirst(dropDownOptions) + ? Digit?.Customizations?.["commonUiConfig"]?.["SearchMDMSv2Config"]?.[schemaCodeToValidate]?.sortValidDatesFirst(dropDownOptions) + : dropDownOptions; Config.sections.search.uiConfig.fields[0].populators.options = dropDownOptions; Config.actionLink=Config.actionLink+`?moduleName=${masterName?.name}&masterName=${moduleName?.name}`; // Config.apiDetails.serviceName = `/mdms-v2/v2/_search/${currentSchema.code}` @@ -153,7 +157,8 @@ const MDMSSearchv2 = () => { label:option.i18nKey, i18nKey:option.i18nKey, jsonPath:`data.${option.code}`, - dontShowNA:true + dontShowNA:true, + additionalCustomization: currentSchema?.definition?.["x-ui-schema"]?.[option?.name]?.formatType === "EPOC" ? true : false } }),{ label:"WBH_ISACTIVE", @@ -180,7 +185,10 @@ const MDMSSearchv2 = () => { const onClickRow = ({original:row}) => { const [moduleName,masterName] = row.schemaCode.split(".") const additionalParamString = new URLSearchParams(additionalParams).toString(); - history.push(`/${window.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${row.uniqueIdentifier}${additionalParamString ? "&"+additionalParamString : ""}`) + if(window.location.href.includes("mukta") && master === "WORKS-SOR" && modulee === "Composition") + window.location.href = `/works-ui/employee/rateanalysis/view-rate-analysis?sorId=${row?.data?.sorId}&fromeffective=${row?.data?.effectiveFrom}` + else + history.push(`/${window.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${row.uniqueIdentifier}${additionalParamString ? "&"+additionalParamString : ""}`) } if (isLoading) return ; @@ -188,7 +196,7 @@ const MDMSSearchv2 = () => {
{t(Digit.Utils.workbench.getMDMSLabel(`SCHEMA_` + currentSchema?.code))}
{ - updatedConfig && Digit.Utils.didEmployeeHasAtleastOneRole(updatedConfig?.actionRoles) && + updatedConfig && Digit.Utils.didEmployeeHasAtleastOneRole(updatedConfig?.actionRoles) && Digit.Utils.didEmployeeisAllowed(master,modulee) && diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSView.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSView.js index 597bce22a2a..32168b05515 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSView.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/pages/employee/MDMSView.js @@ -4,6 +4,7 @@ import { Loader,Toast } from '@egovernments/digit-ui-react-components'; import { useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; import { Button } from '@egovernments/digit-ui-components'; +import { transform } from "lodash"; const MDMSView = ({...props}) => { const history = useHistory() @@ -25,24 +26,6 @@ const MDMSView = ({...props}) => { }); // const stateId = Digit.ULBService.getStateId(); tenantId = Digit.ULBService.getCurrentTenantId(); - const fetchActionItems = (data) => { - 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" - }) - - return actionItems - } @@ -73,6 +56,35 @@ const MDMSView = ({...props}) => { const { isLoading, data, isFetching,refetch,revalidate } = Digit.Hooks.useCustomAPIHook(reqCriteria); + const reqCriteriaSorSearch = { + url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`, + params: {}, + body: { + MdmsCriteria: { + tenantId: tenantId?.split(".")[0], + uniqueIdentifiers: [uniqueIdentifier?.split(".")[0]], + schemaCode: `${moduleName}.${"SOR"}`, + }, + }, + config: { + enabled: data?.data?.sorId ? true : false, + select: (response) => { + return response?.mdms?.[0]; + }, + }, + changeQueryName: uniqueIdentifier?.split(".")[0], + }; + const { isLoading: isSORLoading, data: sorData } = Digit.Hooks.useCustomAPIHook(reqCriteriaSorSearch); + + let propsToSendButtons = { + moduleName, + masterName, + sorData, + }; + + const fetchActionItems = (data) => Digit?.Customizations?.["commonUiConfig"]?.["ViewMdmsConfig"]?.fetchActionItems(data, propsToSendButtons); + + const reqCriteriaUpdate = { url: Digit.Utils.workbench.getMDMSActionURL(moduleName,masterName,"update"), params: {}, @@ -124,21 +136,19 @@ const MDMSView = ({...props}) => { ); } - const onActionSelect = (action) => { - const {action:actionSelected} = action - //action===EDIT go to edit screen - if(actionSelected==="EDIT") { - const additionalParamString = new URLSearchParams(additionalParams).toString(); - history.push(`/${window?.contextPath}/employee/workbench/mdms-edit?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${uniqueIdentifier}${additionalParamString ? "&"+additionalParamString : ""}`) - } - //action===DISABLE || ENABLE call update api and show toast respectively - else{ - //call update mutation - handleEnableDisable(actionSelected) - } - } + let propsToSend = { + moduleName, + masterName, + tenantId, + uniqueIdentifier, + data, + history, + handleEnableDisable, + }; + + const onActionSelect = (action) => Digit?.Customizations?.["commonUiConfig"]?.["ViewMdmsConfig"]?.onActionSelect(action, propsToSend); - if(isLoading) return + if(isLoading || isSORLoading) return return ( diff --git a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/utils/index.js b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/utils/index.js index 76dc1315b82..ec335368568 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/utils/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/workbench/src/utils/index.js @@ -191,17 +191,26 @@ const updateTitleToLocalisationCodeForObject = (definition, schemaCode) => { }); return definition; }; -const formatDates = (value, type) => { +const formatDates = (value, type, key) => { if (type != "EPOC" && (!value || Number.isNaN(value))) { value = new Date(); } switch (type) { case "date": - return new Date(value)?.toISOString?.()?.split?.("T")?.[0]; + const options = { timeZone: 'Asia/Kolkata', year: 'numeric', month: '2-digit', day: '2-digit' }; + const indianDate = new Date(value).toLocaleDateString('en-CA', options); + return indianDate; case "datetime": return new Date(value).toISOString(); case "EPOC": - return String(new Date(value)?.getTime()); + const date = new Date(value); + if(key==="validTo" || key==="effectiveTo") { + date.setHours(23, 59, 59, 999); + } + else{ + date.setHours(0, 0, 0, 0); + } + return String(date?.getTime()); } }; @@ -221,10 +230,10 @@ const generateId = async (format, tenantId = Digit.ULBService.getCurrentTenantId return response?.idResponses?.[0]?.id; }; -const formatData = (value, type, schema) => { +const formatData = (value, type, schema, key) => { switch (type) { case "EPOC": - return formatDates(value, type); + return formatDates(value, type, key); case "REVERT-EPOC": return formatDates(typeof value == "string" && value?.endsWith?.("Z") ? value : parseInt(value), schema?.["ui:widget"]); case "REVERT-EPOC": @@ -245,7 +254,7 @@ const preProcessData = async (data = {}, schema = {}) => { autoGenerateFormat = schema?.[key]?.autogenerate; fieldKey = key; } else { - data[key] = formatData(data?.[key], schema?.[key]?.formatType, schema?.[key]); + data[key] = formatData(data?.[key], schema?.[key]?.formatType, schema?.[key],key); } } }); @@ -267,7 +276,7 @@ const postProcessData = (data = {}, schema = {}) => { schema?.[key]?.formatType && data[key] ) { - data[key] = formatData(data?.[key], `REVERT-${schema?.[key]?.formatType}`, schema?.[key]); + data[key] = formatData(data?.[key], `REVERT-${schema?.[key]?.formatType}`, schema?.[key], key); } }); return { ...data }; diff --git a/micro-ui/web/micro-ui-internals/packages/react-components/package.json b/micro-ui/web/micro-ui-internals/packages/react-components/package.json index cc6bc119810..22466d4289d 100644 --- a/micro-ui/web/micro-ui-internals/packages/react-components/package.json +++ b/micro-ui/web/micro-ui-internals/packages/react-components/package.json @@ -1,6 +1,6 @@ { "name": "@egovernments/digit-ui-react-components", - "version": "1.8.13", + "version": "1.8.14", "license": "MIT", "main": "dist/index.js", "module": "dist/index.modern.js", diff --git a/micro-ui/web/micro-ui-internals/packages/react-components/src/atoms/BreadCrumb.js b/micro-ui/web/micro-ui-internals/packages/react-components/src/atoms/BreadCrumb.js index f6f939c46e5..a5c37434fcd 100644 --- a/micro-ui/web/micro-ui-internals/packages/react-components/src/atoms/BreadCrumb.js +++ b/micro-ui/web/micro-ui-internals/packages/react-components/src/atoms/BreadCrumb.js @@ -6,6 +6,10 @@ const Breadcrumb = (props) => { function isLast(index) { return index === props.crumbs.length - 1; } + function handleRedirect(path) { + const host = window.location.origin; // Dynamically get the base URL + window.location.href = `${host}${path}`; + } return (
    {props?.crumbs?.map((crumb, ci) => { @@ -23,7 +27,9 @@ const Breadcrumb = (props) => { {isLast(ci) || !crumb?.path ? ( {crumb.content} ) : ( - {crumb.content} + crumb?.externalPath ? ( + handleRedirect(crumb?.path)}>{crumb.content} ) : + ({crumb.content}) )} ); diff --git a/micro-ui/web/package.json b/micro-ui/web/package.json index 0ae16d7304b..b5c4e0d3683 100644 --- a/micro-ui/web/package.json +++ b/micro-ui/web/package.json @@ -15,7 +15,7 @@ "homepage": "/digit-ui", "dependencies": { "@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", @@ -25,7 +25,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", "babel-loader": "8.1.0", "react": "17.0.2", "react-dom": "17.0.2", diff --git a/micro-ui/web/sandbox/package.json b/micro-ui/web/sandbox/package.json index 7fcfff3fa33..c8b90495b68 100644 --- a/micro-ui/web/sandbox/package.json +++ b/micro-ui/web/sandbox/package.json @@ -20,7 +20,7 @@ "homepage": "/sandbox-ui", "dependencies": { "@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", @@ -31,7 +31,7 @@ "@egovernments/digit-ui-module-engagement": "1.5.20", "@egovernments/digit-ui-components":"0.0.2-beta.58", "@egovernments/digit-ui-module-sandbox": "0.0.1", - "@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", diff --git a/micro-ui/web/workbench/package.json b/micro-ui/web/workbench/package.json index ed0d5f7d044..5175ffa7120 100644 --- a/micro-ui/web/workbench/package.json +++ b/micro-ui/web/workbench/package.json @@ -19,7 +19,7 @@ "@egovernments/digit-ui-components":"0.0.2-beta.58", "@egovernments/digit-ui-module-core": "1.8.14", "@egovernments/digit-ui-module-utilities": "1.0.1-beta.41", - "@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",