diff --git a/micro-ui/web/core/inter-package.json b/micro-ui/web/core/inter-package.json
index af0707eece6..4602f1f42cc 100644
--- a/micro-ui/web/core/inter-package.json
+++ b/micro-ui/web/core/inter-package.json
@@ -50,6 +50,7 @@
"resolutions": {
"**/@babel/runtime": "7.20.1",
"**/babel-preset-react-app": "10.0.0",
+ "**/@babel/traverse":"7.25.9",
"**/ajv": "8.11.2",
"fast-uri":"2.1.0"
},
diff --git a/micro-ui/web/micro-ui-internals/package.json b/micro-ui/web/micro-ui-internals/package.json
index f8f56d67ac2..05b2751ef0e 100644
--- a/micro-ui/web/micro-ui-internals/package.json
+++ b/micro-ui/web/micro-ui-internals/package.json
@@ -57,6 +57,7 @@
"resolutions": {
"**/@babel/runtime": "7.20.1",
"**/babel-preset-react-app": "10.0.0",
+ "**/@babel/traverse":"7.25.9",
"**/styled-components": "5.0.0",
"fast-uri":"2.1.0"
},
diff --git a/micro-ui/web/micro-ui-internals/packages/css/src/digitv2/pages/employee/workbench.scss b/micro-ui/web/micro-ui-internals/packages/css/src/digitv2/pages/employee/workbench.scss
index 8af10232ef1..8936721f46d 100644
--- a/micro-ui/web/micro-ui-internals/packages/css/src/digitv2/pages/employee/workbench.scss
+++ b/micro-ui/web/micro-ui-internals/packages/css/src/digitv2/pages/employee/workbench.scss
@@ -1047,4 +1047,53 @@ user-select: none;
.diff-code-insert {
background-color: #eaffee;
}
-}
\ No newline at end of file
+
+}
+
+
+.code-details {
+ padding: 0.5rem 1.5rem;
+ background-color: #f9f9f9;
+ border: 1px solid #e0e0e0;
+ border-radius: 4px;
+}
+
+.code-row {
+ display: flex;
+ align-items: flex-start;
+ margin-bottom: 0.75rem;
+}
+
+.code-key {
+ flex: 0 0 150px;
+ font-size: 0.9rem;
+ font-weight: bold;
+ color: #444;
+}
+
+.code-value-container {
+ display: flex;
+ flex-direction: column;
+ flex: 1;
+}
+
+.code-value {
+ font-size: 0.9rem;
+ color: #555;
+ margin-bottom: 0.2rem;
+}
+
+.code-row:last-child {
+ margin-bottom: 0;
+}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/UICustomizations.js b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/UICustomizations.js
index 692f65d3d91..26441ac20c2 100644
--- a/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/UICustomizations.js
+++ b/micro-ui/web/micro-ui-internals/packages/modules/sandbox/src/configs/UICustomizations.js
@@ -269,4 +269,4 @@ export const UICustomizations = {
}
},
},
-};
+};
\ No newline at end of file
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 76d8af0b5bc..47744ff2dd6 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
@@ -11,33 +11,20 @@ import {
Menu,
CollapseAndExpandGroups,
} from "@egovernments/digit-ui-react-components";
-import React, { useEffect, useMemo, useState } from "react";
+import React, { createContext, useContext, useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import _ from "lodash";
import Form from "@rjsf/core";
import validator from "@rjsf/validator-ajv8";
-// import { UiSchema } from '@rjsf/utils';
import { titleId } from "@rjsf/utils";
import CustomDropdown from "./MultiSelect";
import CustomDropdownV2 from "./MultiSelectV2";
-
import CustomCheckbox from "./Checbox";
import { BulkModal } from "./BulkModal";
-/*
-
-created the foem using rjfs json form
-
-https://rjsf-team.github.io/react-jsonschema-form/docs/
-
-*/
-
-/*
-The DigitJSONForm component is a custom form component built using the react-jsonschema-form library.
- It takes in a schema, an onSubmit function, an optional uiSchema,
- a showToast and showErrorToast as props.
+const AdditionalPropertiesContext = createContext();
+export const useAdditionalProperties = () => useContext(AdditionalPropertiesContext);
-*/
const uiSchema = {
"ui:title": " ",
"ui:classNames": "my-class",
@@ -56,25 +43,9 @@ const uiSchema = {
},
};
-function transformErrors(errors) {
- const { t } = this;
- console.log(errors, "errors");
- // Custom validation logic for all widgets
- // You can modify or add error messages based on your requirements
- return errors.map((error) => {
- error.message = t(Digit.Utils.workbench.getMDMSLabel(`WBH_ERROR_${error?.name}`));
- if (error?.name === "pattern") {
- error.message += ` : ${error?.params?.pattern}`;
- }
- // if (error.property === '.name' && error.name === 'minLength') {
- // error.message = 'Name must be at least 3 characters';
- // }
- // if (error.property === '.email' && error.name === 'format') {
- // error.message = 'Invalid email format';
- // }
- return error;
- });
-}
+// Removed transformErrors to reduce re-renders
+// Removed Digit references from errors to reduce complexity
+
const getArrayWrapperClassName = (type) => {
switch (type) {
case "array":
@@ -84,50 +55,30 @@ const getArrayWrapperClassName = (type) => {
default:
return "jk-array-of-non-objects";
}
-}
+};
function ArrayFieldItemTemplate(props) {
const { t } = useTranslation();
-
const { children, className, index, onDropIndexClick, schema, disabled } = props;
- const isArrayOfObjects = schema?.type == "object";
+ const isArrayOfObjects = schema?.type === "object";
const newClass = getArrayWrapperClassName(schema?.type);
return (
-
{children}
- {isArrayOfObjects ? (
-
- {props.hasRemove && (
-
- }
- onButtonClick={onDropIndexClick(index)}
- type="button"
- isDisabled={disabled}
- />
-
- )}
-
- ) : (
- props.hasRemove && (
-
- }
- onButtonClick={onDropIndexClick(index)}
- type="button"
- isDisabled={disabled}
- />
-
-
- )
+
{children}
+ {props.hasRemove && (
+
+ }
+ onButtonClick={onDropIndexClick(index)}
+ type="button"
+ isDisabled={disabled}
+ />
+
)}
-
+
);
}
@@ -140,11 +91,13 @@ function TitleFieldTemplate(props) {
);
}
+
function ArrayFieldTitleTemplate(props) {
const { title, idSchema } = props;
const id = titleId(idSchema);
return null;
}
+
function ArrayFieldTemplate(props) {
const { t } = useTranslation();
if (props?.required && !props?.schema?.minItems) {
@@ -153,16 +106,14 @@ function ArrayFieldTemplate(props) {
return (
- {props.items.map((element, index) => {
- return (
-
-
-
- );
- })}
+ {props.items.map((element, index) => (
+
+
+
+ ))}
{props.canAdd && (
}
onButtonClick={props.onAddClick}
@@ -175,24 +126,75 @@ function ArrayFieldTemplate(props) {
}
function ObjectFieldTemplate(props) {
+ const { formData, schema, idSchema, formContext } = props;
+ const { schemaCode, MdmsRes, additionalProperties } = formContext;
+ const isRoot = idSchema["$id"] === "digit_root";
+
+ const localisableFields = MdmsRes?.find((item) => item.schemaCode === schemaCode)?.localisation?.localisableFields || [];
+
const children = props.properties.map((element) => {
+ const fieldName = element.name;
+ const inputValue = formData[fieldName];
+ const isLocalisable = localisableFields.some((field) => field.fieldPath === fieldName);
+
+ if (isLocalisable) {
+ const fieldProps = additionalProperties?.[fieldName];
+ const mdmsCode = fieldProps?.mdmsCode;
+ const localizationCode = fieldProps?.localizationCode;
+ const isMultiRootTenant = Digit.Utils.getMultiRootTenant();
+ if(isMultiRootTenant){
+ return (
+
+ {/* Actual Input Field */}
+
+ {element.content}
+
+
+ {/* MDMS and Localization Codes */}
+
+
+
+
+
+ {mdmsCode || ""}
+
+
+
+
+
+
+
+ {localizationCode || ""}
+
+
+
+
+
+ );
+ }
+
+
+ }
+
return (
-
+
{element.content}
);
});
- const isRoot = props?.["idSchema"]?.["$id"] == "digit_root";
return (
-
- {/* {props.title} */}
- {props.description}
-
+
{isRoot ? (
children
) : (
-
+
+ {children}
+
)}
);
@@ -202,21 +204,25 @@ function CustomFieldTemplate(props) {
const { t } = useTranslation();
const { moduleName, masterName } = Digit.Hooks.useQueryParams();
const { id, classNames, style, label, help, required, description, errors, children } = props;
+
let titleCode = label;
let additionalCode = "";
if (
+ moduleName &&
+ masterName &&
+ typeof Digit?.Utils?.locale?.getTransformedLocale === "function" &&
!label?.includes(Digit.Utils.locale.getTransformedLocale(moduleName)) &&
!label?.includes(Digit.Utils.locale.getTransformedLocale(masterName))
) {
titleCode = Digit.Utils.locale.getTransformedLocale(`${moduleName}.${moduleName}_${label?.slice(0, -2)}`);
additionalCode = label?.slice(-2);
}
+
return (
{description}
-
+
{children}
{errors}
{help}
@@ -235,10 +241,8 @@ function CustomFieldTemplate(props) {
);
}
-const FieldErrorTemplate = (props) => {
- const { errors } = props;
- return errors && errors.length > 0 && errors?.[0] ? {errors?.[0]} : null;
-};
+const FieldErrorTemplate = ({ errors }) =>
+ errors && errors.length > 0 && errors[0] ? {errors[0]} : null;
const DigitJSONForm = ({
schema,
@@ -255,110 +259,206 @@ const DigitJSONForm = ({
disabled = false,
setShowToast,
setShowErrorToast,
- v2 = true
+ v2 = true,
}) => {
const { t } = useTranslation();
- useEffect(() => {
- onFormChange({ formData: Digit.Utils.workbench.postProcessData(formData, inputUiSchema) });
- }, []);
- const onSubmitV2 = async ({ formData }) => {
- const updatedData = await Digit.Utils.workbench.preProcessData(formData, inputUiSchema);
- onSubmit(updatedData);
- };
-
- const customWidgets = { SelectWidget: v2 ? CustomDropdown : CustomDropdownV2, CheckboxWidget: CustomCheckbox };
+ const [additionalProperties, setAdditionalProperties] = useState({});
const [displayMenu, setDisplayMenu] = useState(false);
- const [liveValidate, setLiveValidate] = useState(false);
const [showBulkUploadModal, setShowBulkUploadModal] = useState(false);
const { moduleName, masterName } = Digit.Hooks.useQueryParams();
+ const tenantId = Digit.ULBService.getCurrentTenantId();
+ const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(
+ tenantId,
+ "Workbench",
+ [{ name: "UISchema" }],
+ {
+ select: (data) => data?.["Workbench"]?.["UISchema"],
+ }
+ );
+
+ // Compute additionalProperties whenever formData or MdmsRes changes
+ useEffect(() => {
+ if (schema?.code && MdmsRes && formData) {
+ const localisableFields =
+ MdmsRes?.find((item) => item.schemaCode === schema.code)?.localisation?.localisableFields || [];
+ let newAdditionalProps = {};
+ for (const fieldName in formData) {
+ const inputValue = formData[fieldName];
+ const isLocalisable = localisableFields.some((field) => field.fieldPath === fieldName);
+ if (isLocalisable && inputValue !== undefined) {
+ const mdmsCode = (inputValue || "").replace(/\s+/g, "").toUpperCase();
+ const localizationCode = `${schema.code}_${fieldName}_${mdmsCode}`.toUpperCase();
+ newAdditionalProps[fieldName] = {
+ localizationMessage: inputValue,
+ mdmsCode,
+ localizationCode,
+ };
+ }
+ }
+ setAdditionalProperties(newAdditionalProps);
+ }
+ }, [formData, MdmsRes, schema]);
+
+ const reqCriteriaSecondUpsert = {
+ url: `/localization/messages/v1/_upsert`,
+ params: {},
+ body: {},
+ config: {
+ enabled: false,
+ },
+ };
+ const secondFormatLocalizationMutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaSecondUpsert);
+
+ const onSubmitV2 = async ({ formData }, e) => {
+
+ const transformedFormData = { ...formData };
+
+ for (const fieldName in additionalProperties) {
+ if (additionalProperties.hasOwnProperty(fieldName)) {
+ const fieldProps = additionalProperties[fieldName];
+ if (fieldProps?.localizationCode) {
+ transformedFormData[fieldName] = fieldProps.mdmsCode;
+ }
+ }
+ }
+
+ const schemaCodeParts = schema?.code?.split(".") || [];
+ const firstPart = schemaCodeParts[0]?.toLowerCase() || "default";
+ const secondPart = schemaCodeParts[1]?.toUpperCase() || "";
+
+ const secondFormatMessages = [];
+ for (const fieldName in additionalProperties) {
+ if (additionalProperties.hasOwnProperty(fieldName)) {
+ const fieldProps = additionalProperties[fieldName];
+ const { mdmsCode, localizationMessage } = fieldProps;
+ if (mdmsCode && localizationMessage) {
+ const code = `${secondPart}.${mdmsCode}`;
+ secondFormatMessages.push({
+ code: code,
+ message: localizationMessage,
+ module: firstPart,
+ locale: "en_IN",
+ });
+ }
+ }
+ }
+
+ if (secondFormatMessages.length > 0) {
+ try {
+ await secondFormatLocalizationMutation.mutateAsync({
+ params: {},
+ body: {
+ tenantId: tenantId,
+ messages: secondFormatMessages
+ }
+ });
+ } catch (err) {
+ console.error("Second format localization upsert failed:", err);
+ }
+ }
+ onSubmit && onSubmit(transformedFormData, additionalProperties);
+ };
+
+ const customWidgets = { SelectWidget: v2 ? CustomDropdown : CustomDropdownV2, CheckboxWidget: CustomCheckbox };
const onError = (errors) => {
- setLiveValidate(true);
- onFormError(errors);
+ onFormError && onFormError(errors);
};
- const person = { t: t };
return (
-
-
- {screenType === "add" ? t("WBH_ADD_MDMS") : screenType === "view" ? t("WBH_VIEW_MDMS") : t("WBH_EDIT_MDMS")}
-
-
-
- {t(Digit.Utils.workbench.getMDMSLabel(`SCHEMA_` + schema?.code))}
-
+
+ {showToast && (
+ {
+ setShowToast(null);
+ }}
+ isDleteBtn={true}
+ >
+ )}
+
+
);
};
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..1e9be3d1c98 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
@@ -810,4 +810,4 @@ export const UICustomizations = {
}
}
-};
+};
\ No newline at end of file
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..735d306f4f8 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
@@ -18,8 +18,6 @@ const onFormError = (errors) => console.log("I have", errors.length, "errors to
const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onViewActionsSelect, viewActions, onSubmitEditAction, ...props }) => {
const tenantId = Digit.ULBService.getCurrentTenantId();
const [spinner, toggleSpinner] = useState(false);
- // const stateId = Digit.ULBService.getStateId();
-
const [uiSchema, setUiSchema] = useState({});
const [api, setAPI] = useState(false);
const [noSchema, setNoSchema] = useState(false);
@@ -66,16 +64,16 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie
const body = api?.requestBody
? { ...api?.requestBody }
: {
- Mdms: {
- tenantId: tenantId,
- schemaCode: `${moduleName}.${masterName}`,
- uniqueIdentifier: null,
- data: {},
- isActive: true,
- },
- };
+ Mdms: {
+ tenantId: tenantId,
+ schemaCode: `${moduleName}.${masterName}`,
+ uniqueIdentifier: null,
+ data: {},
+ isActive: true,
+ },
+ };
const reqCriteriaAdd = {
- url: api ? api?.url : Digit.Utils.workbench.getMDMSActionURL(moduleName,masterName,"create"),
+ url: api ? api?.url : Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "create"),
params: {},
body: { ...body },
config: {
@@ -86,27 +84,100 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie
},
};
- const gotoView = () => {
+ const gotoView = () => {
setTimeout(() => {
- history.push(`/${window?.contextPath}/employee/workbench/mdms-search-v2?moduleName=${moduleName}&masterName=${masterName}${from ? `&from=${from}` : ""}`)
+ history.push(
+ `/${window?.contextPath}/employee/workbench/mdms-search-v2?moduleName=${moduleName}&masterName=${masterName}${
+ from ? `&from=${from}` : ""
+ }`
+ );
}, 2000);
- }
+ };
const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaAdd);
- const onSubmit = (data) => {
+
+ // Define a localization upsert mutation similar to how the main mutation is defined
+ const localizationReqCriteria = {
+ url: `/localization/messages/v1/_upsert`,
+ params: {},
+ body: {},
+ config: {
+ enabled: false,
+ },
+ };
+ const localizationMutation = Digit.Hooks.useCustomAPIMutationHook(localizationReqCriteria);
+
+ const closeToast = () => {
+ setTimeout(() => {
+ setShowToast(null);
+ }, 5000);
+ };
+
+ const onSubmit = (data, additionalProperties) => {
toggleSpinner(true);
- const onSuccess = (resp) => {
- toggleSpinner(false);
- setSessionFormData({});
- setSession({});
- setShowErrorToast(false);
+ const onSuccess = async (resp) => {
+ // After main MDMS add success
const jsonPath = api?.responseJson ? api?.responseJson : "mdms[0].id";
setShowToast(`${t("WBH_SUCCESS_MDMS_MSG")} ${_.get(resp, jsonPath, "NA")}`);
- closeToast();
- gotoView();
+ setShowErrorToast(false);
- //here redirect to search screen(check if it's required cos user might want add multiple masters in one go)
+ // Build messages array from additionalProperties for localization
+ const messages = [];
+ if (additionalProperties && typeof additionalProperties === "object") {
+ for (const fieldName in additionalProperties) {
+ if (additionalProperties.hasOwnProperty(fieldName)) {
+ const fieldProps = additionalProperties[fieldName];
+ if (fieldProps?.localizationCode && fieldProps?.localizationMessage) {
+ messages.push({
+ code: fieldProps.localizationCode,
+ message: fieldProps.localizationMessage,
+ // Append "digit_mdms_" to localization code for module
+ module: `digit_mdms_${schema?.code}`.toUpperCase(),
+ locale: "en_IN",
+ });
+ }
+ }
+ }
+ }
+
+ if (messages.length > 0) {
+ const localizationBody = {
+ tenantId: tenantId,
+ messages: messages,
+ };
+
+ // Perform localization upsert
+ localizationMutation.mutate(
+ {
+ params: {},
+ body: localizationBody,
+ },
+ {
+ onError: (resp) => {
+ toggleSpinner(false);
+ setShowToast(`${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`);
+ setShowErrorToast(true);
+ closeToast();
+ },
+ onSuccess: (upsertResp) => {
+ toggleSpinner(false);
+ setSessionFormData({});
+ setSession({});
+ closeToast();
+ gotoView();
+ },
+ }
+ );
+ } else {
+ // No localization messages to upsert, just proceed
+ toggleSpinner(false);
+ setSessionFormData({});
+ setSession({});
+ closeToast();
+ gotoView();
+ }
};
+
const onError = (resp) => {
toggleSpinner(false);
setShowToast(`${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`);
@@ -128,21 +199,18 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie
}
);
};
+
const onFormValueChange = (updatedSchema, element) => {
const { formData } = updatedSchema;
-
if (!_.isEqual(session, formData)) {
setSession({ ...session, ...formData });
}
};
useEffect(() => {
- // setFormSchema(schema);
- /* localise */
if (schema && schema?.definition) {
Digit.Utils.workbench.updateTitleToLocalisationCodeForObject(schema?.definition, schema?.code);
setFormSchema(schema);
- /* logic to search for the reference data from the mdms data api */
if (schema?.definition?.["x-ref-schema"]?.length > 0) {
schema?.definition?.["x-ref-schema"]?.map((dependent) => {
@@ -159,8 +227,8 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie
}
}
});
+
setFormSchema({ ...schema });
- /* added disable to get the complete form re rendered to get the enum values reflected */
setDisableForm(true);
setTimeout(() => {
setDisableForm(false);
@@ -191,18 +259,11 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie
);
}
- const closeToast = () => {
- setTimeout(() => {
- setShowToast(null);
- }, 5000);
- };
-
- /* use newConfig instead of commonFields for local development in case needed */
if (isLoading || !formSchema || Object.keys(formSchema) == 0) {
return ;
}
- const uiJSONSchema = formSchema?.["definition"]?.["x-ui-schema"];
+ const uiJSONSchema = formSchema?.["definition"]?.["x-ui-schema"];
return (
{spinner && }
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..825fd9ea4cc 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
@@ -1,134 +1,197 @@
-import React,{useState} from 'react'
-import MDMSAdd from './MDMSAddV2'
-import { Loader,Toast } from '@egovernments/digit-ui-react-components';
+import React, { useState } from "react";
+import MDMSAdd from "./MDMSAddV2";
+import { Loader, Toast } from "@egovernments/digit-ui-react-components";
import { useTranslation } from "react-i18next";
import { useHistory } from "react-router-dom";
-const MDMSEdit = ({...props}) => {
- const history = useHistory()
+import _ from "lodash";
- const { t } = useTranslation()
-
- const { moduleName, masterName, tenantId,uniqueIdentifier, from } = Digit.Hooks.useQueryParams();
+const MDMSEdit = ({ ...props }) => {
+ const history = useHistory();
+ const { t } = useTranslation();
+ const { moduleName, masterName, tenantId, uniqueIdentifier, from } = Digit.Hooks.useQueryParams();
const stateId = Digit.ULBService.getCurrentTenantId();
const [showToast, setShowToast] = useState(false);
- const [renderLoader,setRenderLoader] = useState(false)
+ const [renderLoader, setRenderLoader] = useState(false);
+
+ const closeToast = () => {
+ setTimeout(() => setShowToast(null), 5000);
+ };
+
+ const gotoView = () => {
+ setRenderLoader(true);
+ history.push(
+ `/${window?.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${uniqueIdentifier}${
+ from ? `&from=${from}` : ""
+ }`
+ );
+ };
+
+ // Fetch MDMS Data
const reqCriteria = {
url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`,
params: {},
body: {
MdmsCriteria: {
tenantId: stateId,
- uniqueIdentifiers:[uniqueIdentifier],
- schemaCode:`${moduleName}.${masterName}`
+ uniqueIdentifiers: [uniqueIdentifier],
+ schemaCode: `${moduleName}.${masterName}`,
},
},
config: {
- enabled: moduleName && masterName && true,
- select: (data) => {
- return data?.mdms?.[0]
- },
+ enabled: !!moduleName && !!masterName,
+ select: (data) => data?.mdms?.[0],
},
};
+ const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteria);
+
+ // Fetch Schema Definitions
const reqCriteriaSchema = {
url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`,
params: {},
body: {
SchemaDefCriteria: {
tenantId: stateId,
- codes:[`${moduleName}.${masterName}`]
+ codes: [`${moduleName}.${masterName}`],
},
},
config: {
- enabled: moduleName && masterName && true,
- select: (data) => {
- const uniqueFields = data?.SchemaDefinitions?.[0]?.definition?.["x-unique"]
- const updatesToUiSchema = {}
- uniqueFields.forEach(field => updatesToUiSchema[field] = {"ui:readonly":true})
- return {schema:data?.SchemaDefinitions?.[0],updatesToUiSchema}
+ enabled: !!moduleName && !!masterName,
+ select: (data) => {
+ const uniqueFields = data?.SchemaDefinitions?.[0]?.definition?.["x-unique"] || [];
+ const updatesToUiSchema = {};
+ uniqueFields.forEach((field) => {
+ updatesToUiSchema[field] = { "ui:readonly": true };
+ });
+ updatesToUiSchema["complaintSubTypeCode"] = { "ui:readonly": true }; // Explicitly disable Complaint Sub-Type Code
+ return { schema: data?.SchemaDefinitions?.[0], updatesToUiSchema };
},
},
- changeQueryName:"schema"
};
- const closeToast = () => {
- setTimeout(() => {
- setShowToast(null)
- }, 5000);
- }
-
- const gotoView = () => {
- setTimeout(() => {
- setRenderLoader(true)
- history.push(`/${window?.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${uniqueIdentifier}${from ? `&from=${from}` : ""}`)
- }, 2000);
- }
+ const { isLoading: isSchemaLoading, data: schemaData } = Digit.Hooks.useCustomAPIHook(reqCriteriaSchema);
- const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteria);
- const { isLoading:isLoadingSchema,data: schemaData,isFetching: isFetchingSchema,...rest } = Digit.Hooks.useCustomAPIHook(reqCriteriaSchema);
-
+ // Localization Search
+ const localizationModule = `DIGIT_MDMS_${data?.schemaCode}`.toUpperCase();
+ const locale = "en_IN";
- const reqCriteriaUpdate = {
- url: Digit.Utils.workbench.getMDMSActionURL(moduleName,masterName,"update"),
+ const localizationReqCriteria = {
+ url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${stateId}&module=${localizationModule}`,
params: {},
- body: {
-
- },
+ body: {},
config: {
- enabled: true,
+ enabled: !!data,
+ select: (respData) => {
+ const messageMap = {};
+ if (Array.isArray(respData?.messages)) {
+ respData.messages.forEach((msg) => {
+ messageMap[msg.code] = msg.message;
+ });
+ }
+ return messageMap;
+ },
},
};
- const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate);
- const handleUpdate = async (formData) => {
+ const { data: localizationMap, isLoading: isLocalizationLoading } = Digit.Hooks.useCustomAPIHook(localizationReqCriteria);
- const onSuccess = (resp) => {
-
- setShowToast({
- label:`${t("WBH_SUCCESS_UPD_MDMS_MSG")} ${resp?.mdms?.[0]?.id}`
- });
- // closeToast()
- gotoView()
- };
+ // Replace values with localized messages
+ let finalData = data;
+ if (data?.data && localizationMap) {
+ const updatedData = _.cloneDeep(data);
+ Object.keys(updatedData.data).forEach((field) => {
+ const localizationKey = `${data.schemaCode}_${field}_${updatedData.data[field]}`.toUpperCase();
+ if (localizationMap[localizationKey]) {
+ updatedData.data[field] = localizationMap[localizationKey];
+ }
+ });
+ finalData = updatedData;
+ }
- const onError = (resp) => {
- setShowToast({
- label:`${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`,
- isError:true
- });
-
- closeToast()
- };
+ const localizationUpsertMutation = Digit.Hooks.useCustomAPIMutationHook({
+ url: `/localization/messages/v1/_upsert`,
+ params: {},
+ body: {},
+ config: { enabled: false },
+ });
+ const reqCriteriaUpdate = {
+ url: Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "update"),
+ params: {},
+ body: {},
+ config: { enabled: true },
+ };
+ const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate);
+
+ const handleUpdate = async (formData, additionalProperties) => {
+ const transformedFormData = { ...formData };
+
+ // Prepare Localization Messages
+ const messages = [];
+ if (additionalProperties && typeof additionalProperties === "object") {
+ for (const fieldName in additionalProperties) {
+ if (additionalProperties.hasOwnProperty(fieldName)) {
+ const fieldProps = additionalProperties[fieldName];
+ if (fieldProps?.localizationCode && fieldProps?.localizationMessage) {
+ messages.push({
+ code: fieldProps.localizationCode,
+ message: fieldProps.localizationMessage,
+ module: localizationModule,
+ locale: "en_IN",
+ });
+ }
+ }
+ }
+ }
+
+ try {
+ if (messages.length > 0) {
+ await localizationUpsertMutation.mutateAsync({
+ body: { tenantId: stateId, messages },
+ });
+ }
+ } catch (err) {
+ console.error("Localization Upsert Failed:", err);
+ setShowToast({ label: t("WBH_ERROR_LOCALIZATION"), isError: true });
+ closeToast();
+ return;
+ }
+
+ // Perform MDMS Update
mutation.mutate(
{
- url:reqCriteriaUpdate?.url,
+ url: reqCriteriaUpdate.url,
params: {},
- body: {
- Mdms:{
- ...data,
- data:formData
- },
- },
+ body: { Mdms: { ...data, data: transformedFormData } },
},
{
- onError,
- onSuccess,
+ onError: (resp) => {
+ setShowToast({ label: t("WBH_ERROR_MDMS_DATA"), isError: true });
+ closeToast();
+ },
+ onSuccess: () => {
+ setShowToast({ label: t("WBH_SUCCESS_UPD_MDMS_MSG") });
+ gotoView();
+ },
}
);
+ };
- }
+ if (isLoading || isFetching || isSchemaLoading || isLocalizationLoading || renderLoader) return ;
- if(isLoading || isLoadingSchema || renderLoader ) return
-
return (
-
- {showToast && setShowToast(null)} >}
+
+ {showToast && setShowToast(null)} />}
- )
-}
+ );
+};
-export default MDMSEdit
\ No newline at end of file
+export default MDMSEdit;
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..da59983da78 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
@@ -21,8 +21,7 @@ const toDropdownObj = (master = "", mod = "") => {
const MDMSSearchv2 = () => {
let Config = _.clone(Configg)
const { t } = useTranslation();
- const history = useHistory();
-
+ const history = useHistory();
let {masterName:modulee,moduleName:master,tenantId} = Digit.Hooks.useQueryParams()
let {from, screen, action} = Digit.Hooks.useQueryParams()
@@ -163,7 +162,6 @@ const MDMSSearchv2 = () => {
// dontShowNA:true
}]
Config.apiDetails.serviceName=`/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`;
-
setUpdatedConfig(Config)
}
}, [currentSchema]);
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..61ead85ef7f 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
@@ -1,67 +1,65 @@
-import React,{useState} from 'react'
+import React, { useState } from 'react'
import MDMSAdd from './MDMSAddV2'
-import { Loader,Toast } from '@egovernments/digit-ui-react-components';
+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 _ from "lodash";
-const MDMSView = ({...props}) => {
+const MDMSView = ({ ...props }) => {
const history = useHistory()
const { t } = useTranslation()
const [showToast, setShowToast] = useState(false);
- let { moduleName, masterName, tenantId,uniqueIdentifier } = Digit.Hooks.useQueryParams();
- let {from, screen, action} = Digit.Hooks.useQueryParams()
+ let { moduleName, masterName, tenantId, uniqueIdentifier } = Digit.Hooks.useQueryParams();
+ let { from, screen, action } = Digit.Hooks.useQueryParams()
+ tenantId = Digit.ULBService.getCurrentTenantId();
- const additionalParams = {
- from: from,
- screen: screen,
- action: action
- }
-
+ const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(
+ tenantId,
+ "Workbench",
+ [{ name: "UISchema" }],
+ {
+ select: (data) => data?.["Workbench"]?.["UISchema"],
+ }
+ );
+
+ const additionalParams = { from: from, screen: screen, action: action }
Object.keys(additionalParams).forEach(key => {
if (additionalParams[key] === undefined || additionalParams[key] === null) {
delete additionalParams[key];
}
});
- // const stateId = Digit.ULBService.getStateId();
- tenantId = Digit.ULBService.getCurrentTenantId();
+
+
const fetchActionItems = (data) => {
let actionItems = [{
- action:"EDIT",
- label:"Edit Master"
+ 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"
- })
+ if (isActive) {
+ actionItems.push({ action: "DISABLE", label: "Disable Master" })
+ } else {
+ actionItems.push({ action: "ENABLE", label: "Enable Master" })
+ }
return actionItems
}
-
-
const reqCriteria = {
url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`,
params: {},
body: {
MdmsCriteria: {
- tenantId: tenantId ,
- uniqueIdentifiers:[uniqueIdentifier],
- schemaCode:`${moduleName}.${masterName}`
+ tenantId: tenantId,
+ uniqueIdentifiers: [uniqueIdentifier],
+ schemaCode: `${moduleName}.${masterName}`
},
},
config: {
enabled: moduleName && masterName && true,
- select: (data) => {
-
- return data?.mdms?.[0]
- },
+ select: (data) => data?.mdms?.[0]
},
};
@@ -71,49 +69,43 @@ const MDMSView = ({...props}) => {
}, 5000);
}
- const { isLoading, data, isFetching,refetch,revalidate } = Digit.Hooks.useCustomAPIHook(reqCriteria);
+ const { isLoading, data, isFetching, refetch } = Digit.Hooks.useCustomAPIHook(reqCriteria);
const reqCriteriaUpdate = {
- url: Digit.Utils.workbench.getMDMSActionURL(moduleName,masterName,"update"),
+ url: Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "update"),
params: {},
- body: {
-
- },
+ body: {},
config: {
enabled: true,
},
};
const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate);
-
- const handleEnableDisable = async (action) => {
+ const handleEnableDisable = async (action) => {
const onSuccess = (resp) => {
-
setShowToast({
- label:`${t(`WBH_SUCCESS_${resp?.mdms?.[0]?.isActive?"ENA":"DIS"}_MDMS_MSG`)} ${resp?.mdms?.[0]?.id}`
+ label: `${t(`WBH_SUCCESS_${resp?.mdms?.[0]?.isActive ? "ENA" : "DIS"}_MDMS_MSG`)} ${resp?.mdms?.[0]?.id}`
});
closeToast()
refetch()
};
const onError = (resp) => {
setShowToast({
- label:`${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`,
- isError:true
+ label: `${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`,
+ isError: true
});
-
closeToast()
refetch()
};
-
mutation.mutate(
{
- url:reqCriteriaUpdate?.url,
+ url: reqCriteriaUpdate?.url,
params: {},
body: {
- Mdms:{
+ Mdms: {
...data,
- isActive:action==="ENABLE" ? true : false
+ isActive: action === "ENABLE"
},
},
},
@@ -125,30 +117,93 @@ const MDMSView = ({...props}) => {
}
const onActionSelect = (action) => {
- const {action:actionSelected} = action
- //action===EDIT go to edit screen
- if(actionSelected==="EDIT") {
+ const { action: actionSelected } = action
+ 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
+ history.push(`/${window?.contextPath}/employee/workbench/mdms-edit?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${uniqueIdentifier}${additionalParamString ? "&" + additionalParamString : ""}`)
+ } else {
handleEnableDisable(actionSelected)
}
}
- if(isLoading) return
+ let localisableFields = [];
+ if (MdmsRes && Array.isArray(MdmsRes)) {
+ const schemaDef = MdmsRes.find(item => item.schemaCode === `${moduleName}.${masterName}`);
+ localisableFields = schemaDef?.localisation?.localisableFields || [];
+ }
+
+ const rawSchemaCode = data?.schemaCode;
+ const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase();
+
+ const createLocalizationCode = (fieldName, fieldValue) => {
+ const upperFieldName = fieldName.toUpperCase();
+ const transformedValue = (fieldValue || "").replace(/\s+/g, "").toUpperCase();
+ return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase();
+ };
+
+ let localizationCodes = [];
+ if (data && data.data && localisableFields.length > 0) {
+ localizationCodes = localisableFields.map(field => createLocalizationCode(field.fieldPath, data.data[field.fieldPath]));
+ }
+
+ const locale = "en_IN";
+ const localizationReqCriteria = {
+ url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${tenantId}&module=${localizationModule}`,
+ params: {},
+ body: {
+ },
+ config: {
+ enabled: !!data && !!MdmsRes && !!data?.schemaCode && !!tenantId && localizationCodes.length > 0,
+ select: (respData) => {
+ let messageMap = {};
+ if (Array.isArray(respData?.messages)) {
+ respData.messages.forEach(msg => {
+ messageMap[msg.code] = msg.message;
+ });
+ }
+ return messageMap;
+ },
+ },
+ };
+
+ const { data: localizationMap, isLoading: isLocalizationLoading } = Digit.Hooks.useCustomAPIHook(localizationReqCriteria);
+
+ // Transform data if localizationMap is available
+ let finalData = data;
+ if (data && data.data && localizationMap && localisableFields.length > 0) {
+ let updatedData = _.cloneDeep(data);
+ localisableFields.forEach(field => {
+ const code = createLocalizationCode(field.fieldPath, updatedData.data[field.fieldPath]);
+ if (localizationMap[code]) {
+ updatedData.data[field.fieldPath] = localizationMap[code];
+ }
+ });
+ finalData = updatedData;
+ }
+
+ if (isLoading || isFetching || isLocalizationLoading) return
return (
-
-
- {showToast && setShowToast(null)}>}
+
+
+ {showToast && setShowToast(null)}>}
)
}
-export default MDMSView
\ No newline at end of file
+export default MDMSView
diff --git a/micro-ui/web/public/index.html b/micro-ui/web/public/index.html
index e7c3bfe7112..dd0a7e4a743 100644
--- a/micro-ui/web/public/index.html
+++ b/micro-ui/web/public/index.html
@@ -7,7 +7,7 @@
-
+
diff --git a/micro-ui/web/sandbox/inter-package.json b/micro-ui/web/sandbox/inter-package.json
index f749360668a..1d3a02f2792 100644
--- a/micro-ui/web/sandbox/inter-package.json
+++ b/micro-ui/web/sandbox/inter-package.json
@@ -56,6 +56,7 @@
"resolutions": {
"**/@babel/runtime": "7.20.1",
"**/babel-preset-react-app": "10.0.0",
+ "**/@babel/traverse":"7.25.9",
"**/ajv": "8.11.2",
"fast-uri":"2.1.0"
},
diff --git a/micro-ui/web/workbench/inter-package.json b/micro-ui/web/workbench/inter-package.json
index 72f7836b5e1..3f1500abe74 100644
--- a/micro-ui/web/workbench/inter-package.json
+++ b/micro-ui/web/workbench/inter-package.json
@@ -46,6 +46,7 @@
"resolutions": {
"**/@babel/runtime": "7.20.1",
"**/babel-preset-react-app": "10.0.0",
+ "**/@babel/traverse":"7.25.9",
"**/ajv": "8.11.2",
"fast-uri":"2.1.0"
},