From d7478d9449455a4e08cd8a92cfb1cf1dea2a11da Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Thu, 12 Dec 2024 10:24:16 +0530 Subject: [PATCH 01/15] localization fixes --- micro-ui/web/micro-ui-internals/package.json | 1 + .../core/src/pages/employee/Login/login.js | 6 +- .../core/src/pages/employee/Otp/index.js | 6 +- .../workbench/src/components/DigitJSONForm.js | 415 ++++++++++-------- .../workbench/src/pages/employee/MDMSAddV2.js | 137 ++++-- 5 files changed, 334 insertions(+), 231 deletions(-) diff --git a/micro-ui/web/micro-ui-internals/package.json b/micro-ui/web/micro-ui-internals/package.json index 5ba29ad053e..e021347fd43 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/modules/core/src/pages/employee/Login/login.js b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js index afcb7a610cb..24a51fbd940 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js @@ -7,9 +7,9 @@ import Header from "../../../components/Header"; /* set employee details to enable backward compatiable */ const setEmployeeDetail = (userObject, token) => { - if (Digit.Utils.getMultiRootTenant()) { - return; - } +// if (Digit.Utils.getMultiRootTenant()) { +// return; +// } let locale = JSON.parse(sessionStorage.getItem("Digit.locale"))?.value || Digit.Utils.getDefaultLanguage(); localStorage.setItem("Employee.tenant-id", userObject?.tenantId); localStorage.setItem("tenant-id", userObject?.tenantId); diff --git a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js index 25f10845d79..bd98b94127b 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js @@ -8,9 +8,9 @@ import Header from "../../../components/Header"; /* set employee details to enable backward compatiable */ const setEmployeeDetail = (userObject, token) => { - if (Digit.Utils.getMultiRootTenant()) { - return; - } + // if (Digit.Utils.getMultiRootTenant()) { + // return; + // } let locale = JSON.parse(sessionStorage.getItem("Digit.locale"))?.value || Digit.Utils.getDefaultLanguage(); localStorage.setItem("Employee.tenant-id", userObject?.tenantId); localStorage.setItem("tenant-id", userObject?.tenantId); 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..5ff07dda805 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 && ( -
-
- )} -
- ) : ( - props.hasRemove && ( -
-
- - ) + {children} + {props.hasRemove && ( +
+
)} -
+ ); } @@ -140,11 +91,11 @@ function TitleFieldTemplate(props) { ); } -function ArrayFieldTitleTemplate(props) { - const { title, idSchema } = props; - const id = titleId(idSchema); + +function ArrayFieldTitleTemplate() { return null; } + function ArrayFieldTemplate(props) { const { t } = useTranslation(); if (props?.required && !props?.schema?.minItems) { @@ -153,16 +104,14 @@ function ArrayFieldTemplate(props) { return (
- {props.items.map((element, index) => { - return ( - - - - ); - })} + {props.items.map((element, index) => ( + + + + ))} {props.canAdd && ( - {showToast && setShowToast(null)}>} + + + {showToast && setShowToast(null)}>} ) } -export default MDMSView \ No newline at end of file +export default MDMSView From 5ac73ac4f8a132a6cdb1e124826a8a464ba1506c Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Fri, 13 Dec 2024 17:39:13 +0530 Subject: [PATCH 03/15] updated --- .../pages/employee/CreateComplaint/index.js | 1 + .../workbench/src/components/DigitJSONForm.js | 67 ++++++- .../workbench/src/pages/employee/MDMSEdit.js | 187 ++++++++++++------ .../workbench/src/pages/employee/MDMSView.js | 5 +- 4 files changed, 185 insertions(+), 75 deletions(-) diff --git a/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js b/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js index ef5752ef83f..1e46a2856b9 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js @@ -55,6 +55,7 @@ export const CreateComplaint = ({ parentUrl }) => { const [params, setParams] = useState({}); const tenantId = window.Digit.SessionStorage.get("Employee.tenantId"); const menu = Digit.Hooks.pgr.useComplaintTypes({ stateCode: tenantId }); + console.log("complaint types are"+ JSON.stringify(menu)); const dispatch = useDispatch(); const match = useRouteMatch(); const history = useHistory(); 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 5ff07dda805..5f80af1efeb 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 @@ -274,11 +274,22 @@ const DigitJSONForm = ({ } }, [formData, MdmsRes, schema]); + // Define second upsert mutation using custom API hook + const reqCriteriaSecondUpsert = { + url: `/localization/messages/v1/_upsert`, + params: {}, + body: {}, + config: { + enabled: false, // We'll call mutateAsync manually + }, + }; + const secondFormatLocalizationMutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaSecondUpsert); + const onSubmitV2 = async ({ formData }, e) => { console.log("additional data", additionalProperties); const transformedFormData = { ...formData }; - + for (const fieldName in additionalProperties) { if (additionalProperties.hasOwnProperty(fieldName)) { const fieldProps = additionalProperties[fieldName]; @@ -287,11 +298,53 @@ const DigitJSONForm = ({ } } } - - // Now transformedFormData has the replaced values + console.log("Transformed formData before submit:", transformedFormData); - - // Call onSubmit with the updated formData and additionalProperties + + // Construct second format localization messages + // no conditions changed, just always attempt creation + 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", + }); + } + } + } + + console.log("Attempting second format localization upsert before main onSubmit..."); + console.log("secondFormatMessages:", secondFormatMessages); + + if (secondFormatMessages.length > 0) { + try { + await secondFormatLocalizationMutation.mutateAsync({ + params: {}, + body: { + tenantId: tenantId, + messages: secondFormatMessages + } + }); + console.log("Second format localization upsert successful!"); + } catch (err) { + console.error("Second format localization upsert failed:", err); + } + } else { + console.log("No second format messages to upsert"); + } + + // Now call main onSubmit onSubmit && onSubmit(transformedFormData, additionalProperties); }; @@ -326,7 +379,7 @@ const DigitJSONForm = ({ showErrorList={false} formData={formData} noHtml5Validate={true} - onChange={onFormChange} // No processing, just pass the event + onChange={onFormChange} formContext={{ schemaCode: schema?.code, MdmsRes, @@ -344,8 +397,6 @@ const DigitJSONForm = ({ ArrayFieldTitleTemplate, ArrayFieldItemTemplate, }} - // Removed liveValidate and transformErrors - // Removed experimental_defaultFormStateBehavior widgets={customWidgets} uiSchema={{ ...uiSchema, ...inputUiSchema }} onError={onError} 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 d4496908c27..b6d73b0164c 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,42 +1,41 @@ -import React, { useState, useEffect } from 'react' -import MDMSAdd from './MDMSAddV2' -import { Loader, Toast } from '@egovernments/digit-ui-react-components'; -import { useTranslation } from "react-i18next"; +import React, { useState } from "react"; +import MDMSAdd from "./MDMSAddV2"; +import { Loader, Toast } from "@egovernments/digit-ui-react-components"; import { useHistory } from "react-router-dom"; +import { useTranslation } from "react-i18next"; import _ from "lodash"; const MDMSEdit = ({ ...props }) => { - const history = useHistory() - const { t } = useTranslation() - + const history = useHistory(); + const { t } = useTranslation(); const { moduleName, masterName, from, uniqueIdentifier } = Digit.Hooks.useQueryParams(); - const stateId = Digit.ULBService.getCurrentTenantId(); + const tenantId = Digit.ULBService.getCurrentTenantId(); const [showToast, setShowToast] = useState(false); - const [renderLoader, setRenderLoader] = useState(false) const closeToast = () => { setTimeout(() => { - setShowToast(null) + 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); - } + history.push( + `/${window?.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${uniqueIdentifier}${ + from ? `&from=${from}` : "" + }` + ); + }; - // Fetch the main MDMS data for editing + // Fetch MDMS data const reqCriteria = { url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`, params: {}, body: { MdmsCriteria: { - tenantId: stateId, + tenantId, uniqueIdentifiers: [uniqueIdentifier], - schemaCode: `${moduleName}.${masterName}` + schemaCode: `${moduleName}.${masterName}`, }, }, config: { @@ -46,30 +45,29 @@ const MDMSEdit = ({ ...props }) => { }; const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteria); - // Fetch schema details (and unique fields) - const reqCriteriaSchema = { - url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`, - params: {}, - body: { - SchemaDefCriteria: { - tenantId: stateId, - 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 } - }, - }, - changeQueryName: "schema" + // Fetch UISchema data + const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(tenantId, "Workbench", [{ name: "UISchema" }], { + select: (data) => data?.["Workbench"]?.["UISchema"], + }); + + // Prepare Localization Data + const rawSchemaCode = data?.schemaCode || ""; + const firstPartModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); + const secondPartModule = rawSchemaCode.split(".")[0].toLowerCase(); + const schemaPart = rawSchemaCode.split(".")[1]?.toUpperCase() || ""; + + const createLocalizationCode = (prefix, fieldName, fieldValue) => { + const upperFieldName = fieldName.toUpperCase(); + const transformedValue = (fieldValue || "").replace(/\s+/g, "").toUpperCase(); + return `${prefix}_${upperFieldName}_${transformedValue}`.toUpperCase(); }; - const { isLoading: isLoadingSchema, data: schemaData, isFetching: isFetchingSchema } = Digit.Hooks.useCustomAPIHook(reqCriteriaSchema); - // Mutation for update + let localisableFields = []; + if (MdmsRes && Array.isArray(MdmsRes)) { + const schemaDef = MdmsRes.find((item) => item.schemaCode === `${moduleName}.${masterName}`); + localisableFields = schemaDef?.localisation?.localisableFields || []; + } + const reqCriteriaUpdate = { url: Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "update"), params: {}, @@ -80,22 +78,74 @@ const MDMSEdit = ({ ...props }) => { }; const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate); + const upsertMutation = Digit.Hooks.useCustomAPIMutationHook({ + url: `/localization/messages/v1/_upsert`, + params: {}, + body: {}, + config: { enabled: false }, + }); + const handleUpdate = async (formData) => { - const onSuccess = (resp) => { - setShowToast({ - label: `${t("WBH_SUCCESS_UPD_MDMS_MSG")} ${resp?.mdms?.[0]?.id}` - }); - gotoView() - }; + const additionalProperties = {}; + localisableFields.forEach((field) => { + const fieldValue = formData[field.fieldPath]; + if (fieldValue) { + additionalProperties[field.fieldPath] = { + mdmsCode: fieldValue.replace(/\s+/g, "").toUpperCase(), + firstFormatLocalizationCode: createLocalizationCode("RAINMAKER-PGR.SERVICEDEFS", field.fieldPath, fieldValue), + secondFormatLocalizationCode: `${schemaPart}.${fieldValue.replace(/\s+/g, "").toUpperCase()}`, + localizationMessage: fieldValue, + }; + } + }); + + // Construct First Format Messages + const firstFormatMessages = Object.values(additionalProperties).map(({ firstFormatLocalizationCode, localizationMessage }) => ({ + code: firstFormatLocalizationCode, + message: localizationMessage, + module: firstPartModule, + locale: "en_IN", + })); + + // Construct Second Format Messages + const secondFormatMessages = Object.values(additionalProperties).map(({ secondFormatLocalizationCode, localizationMessage }) => ({ + code: secondFormatLocalizationCode, + message: localizationMessage, + module: secondPartModule, + locale: "en_IN", + })); - const onError = (resp) => { + try { + if (firstFormatMessages.length > 0) { + await upsertMutation.mutateAsync({ + body: { + tenantId, + messages: firstFormatMessages, + }, + }); + console.log("First localization upsert successful!"); + } + + if (secondFormatMessages.length > 0) { + await upsertMutation.mutateAsync({ + body: { + tenantId, + messages: secondFormatMessages, + }, + }); + console.log("Second localization upsert successful!"); + } + } catch (err) { + console.error("Error during localization upsert:", err); setShowToast({ - label: `${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`, - isError: true + label: t("WBH_ERROR_LOCALIZATION"), + isError: true, }); - closeToast() - }; + closeToast(); + return; + } + // Proceed with MDMS update mutation.mutate( { url: reqCriteriaUpdate?.url, @@ -103,32 +153,41 @@ const MDMSEdit = ({ ...props }) => { body: { Mdms: { ...data, - // Here, we assume `formData` already contains the mdmsCode values, just like the initial add scenario - data: formData + data: formData, }, }, }, { - onError, - onSuccess, + onError: (resp) => { + setShowToast({ + label: `${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`, + isError: true, + }); + closeToast(); + }, + onSuccess: (resp) => { + setShowToast({ + label: `${t("WBH_SUCCESS_UPD_MDMS_MSG")} ${resp?.mdms?.[0]?.id}`, + }); + gotoView(); + }, } ); - } + }; - if (isLoading || isLoadingSchema || isFetching || isFetchingSchema || renderLoader) return + if (isLoading || isFetching) return ; - // Just pass the data.data as is. We assume this data is already in "mdmsCode" form due to the initial add logic. return ( - {showToast && setShowToast(null)} >} + {showToast && setShowToast(null)} />} - ) -} + ); +}; -export default MDMSEdit +export default MDMSEdit; 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 f17c4f8e0a9..f9965bff780 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 @@ -138,13 +138,12 @@ const MDMSView = ({ ...props }) => { // Convert schema code to match exactly how module was stored in messages. // Example: If messages stored module as: DIGIT_MDMS_RAINMAKER-PGR.SERVICEDEFS // Convert rawSchemaCode: "RAINMAKER-PGR.ServiceDefs" -> "RAINMAKER-PGR.SERVICEDEFS" - const properSchema = rawSchemaCode?.replace("ServiceDefs", "SERVICEDEFS"); - const localizationModule = `DIGIT_MDMS_${properSchema}`; + const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); const createLocalizationCode = (fieldName, fieldValue) => { const upperFieldName = fieldName.toUpperCase(); const transformedValue = (fieldValue || "").replace(/\s+/g, "").toUpperCase(); - return `RAINMAKER-PGR.SERVICEDEFS_${upperFieldName}_${transformedValue}`; + return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase(); }; let localizationCodes = []; From d8c91254557c2c26a390d074077b315512dd7ec1 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Sun, 15 Dec 2024 21:58:40 +0530 Subject: [PATCH 04/15] localization changes --- .../workbench/src/pages/employee/MDMSEdit.js | 187 +++++++++--------- 1 file changed, 93 insertions(+), 94 deletions(-) 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 b6d73b0164c..5ebb34745c1 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,25 +1,25 @@ import React, { useState } from "react"; import MDMSAdd from "./MDMSAddV2"; import { Loader, Toast } from "@egovernments/digit-ui-react-components"; -import { useHistory } from "react-router-dom"; import { useTranslation } from "react-i18next"; +import { useHistory } from "react-router-dom"; import _ from "lodash"; const MDMSEdit = ({ ...props }) => { const history = useHistory(); const { t } = useTranslation(); - const { moduleName, masterName, from, uniqueIdentifier } = Digit.Hooks.useQueryParams(); - const tenantId = Digit.ULBService.getCurrentTenantId(); + 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 closeToast = () => { - setTimeout(() => { - setShowToast(null); - }, 5000); + 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}` : "" @@ -27,160 +27,159 @@ const MDMSEdit = ({ ...props }) => { ); }; - // Fetch MDMS data + // Fetch MDMS Data const reqCriteria = { url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`, params: {}, body: { MdmsCriteria: { - tenantId, + tenantId: stateId, uniqueIdentifiers: [uniqueIdentifier], schemaCode: `${moduleName}.${masterName}`, }, }, config: { - enabled: moduleName && masterName && true, + enabled: !!moduleName && !!masterName, select: (data) => data?.mdms?.[0], }, }; + const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteria); - // Fetch UISchema data - const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(tenantId, "Workbench", [{ name: "UISchema" }], { + // Fetch UISchema to identify localisable fields + const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(stateId, "Workbench", [{ name: "UISchema" }], { select: (data) => data?.["Workbench"]?.["UISchema"], }); - // Prepare Localization Data - const rawSchemaCode = data?.schemaCode || ""; - const firstPartModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); - const secondPartModule = rawSchemaCode.split(".")[0].toLowerCase(); - const schemaPart = rawSchemaCode.split(".")[1]?.toUpperCase() || ""; + const localisableFields = MdmsRes?.find((item) => item.schemaCode === `${moduleName}.${masterName}`)?.localisation + ?.localisableFields || []; - const createLocalizationCode = (prefix, fieldName, fieldValue) => { + // Localization Search Preparation + const rawSchemaCode = data?.schemaCode; + const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); + const locale = "en_IN"; + const createLocalizationCode = (fieldName, fieldValue) => { const upperFieldName = fieldName.toUpperCase(); const transformedValue = (fieldValue || "").replace(/\s+/g, "").toUpperCase(); - return `${prefix}_${upperFieldName}_${transformedValue}`.toUpperCase(); + return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase(); }; - let localisableFields = []; - if (MdmsRes && Array.isArray(MdmsRes)) { - const schemaDef = MdmsRes.find((item) => item.schemaCode === `${moduleName}.${masterName}`); - localisableFields = schemaDef?.localisation?.localisableFields || []; + const localizationCodes = + data?.data && localisableFields.length > 0 + ? localisableFields.map((field) => createLocalizationCode(field.fieldPath, data.data[field.fieldPath])) + : []; + + const localizationReqCriteria = { + url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${stateId}&module=${localizationModule}`, + params: {}, + body: { RequestInfo: { authToken: Digit.UserService.getUser()?.access_token || "" } }, + config: { + enabled: !!data && 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); + + let finalData = data; + if (data?.data && localizationMap) { + const 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; } + // MDMS Update Mutation const reqCriteriaUpdate = { url: Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "update"), params: {}, body: {}, - config: { - enabled: true, - }, + config: { enabled: true }, }; + const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate); - const upsertMutation = Digit.Hooks.useCustomAPIMutationHook({ + // Localization Upsert Mutation + const localizationUpsertMutation = Digit.Hooks.useCustomAPIMutationHook({ url: `/localization/messages/v1/_upsert`, params: {}, body: {}, config: { enabled: false }, }); - const handleUpdate = async (formData) => { - const additionalProperties = {}; - localisableFields.forEach((field) => { - const fieldValue = formData[field.fieldPath]; - if (fieldValue) { - additionalProperties[field.fieldPath] = { - mdmsCode: fieldValue.replace(/\s+/g, "").toUpperCase(), - firstFormatLocalizationCode: createLocalizationCode("RAINMAKER-PGR.SERVICEDEFS", field.fieldPath, fieldValue), - secondFormatLocalizationCode: `${schemaPart}.${fieldValue.replace(/\s+/g, "").toUpperCase()}`, - localizationMessage: fieldValue, - }; + 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) { + const mdmsCode = (fieldProps.localizationMessage || "").replace(/\s+/g, "").toUpperCase(); + messages.push({ + code: `${rawSchemaCode}_${fieldName}_${mdmsCode}`, + message: fieldProps.localizationMessage, + module: localizationModule, + locale: "en_IN", + }); + transformedFormData[fieldName] = mdmsCode; // Update mdmsCode + } + } } - }); - - // Construct First Format Messages - const firstFormatMessages = Object.values(additionalProperties).map(({ firstFormatLocalizationCode, localizationMessage }) => ({ - code: firstFormatLocalizationCode, - message: localizationMessage, - module: firstPartModule, - locale: "en_IN", - })); - - // Construct Second Format Messages - const secondFormatMessages = Object.values(additionalProperties).map(({ secondFormatLocalizationCode, localizationMessage }) => ({ - code: secondFormatLocalizationCode, - message: localizationMessage, - module: secondPartModule, - locale: "en_IN", - })); + } try { - if (firstFormatMessages.length > 0) { - await upsertMutation.mutateAsync({ - body: { - tenantId, - messages: firstFormatMessages, - }, - }); - console.log("First localization upsert successful!"); - } - - if (secondFormatMessages.length > 0) { - await upsertMutation.mutateAsync({ - body: { - tenantId, - messages: secondFormatMessages, - }, + // Perform Localization Upsert + if (messages.length > 0) { + await localizationUpsertMutation.mutateAsync({ + body: { tenantId: stateId, messages }, }); - console.log("Second localization upsert successful!"); } } catch (err) { - console.error("Error during localization upsert:", err); - setShowToast({ - label: t("WBH_ERROR_LOCALIZATION"), - isError: true, - }); + console.error("Localization Upsert Failed:", err); + setShowToast({ label: t("WBH_ERROR_LOCALIZATION"), isError: true }); closeToast(); return; } - // Proceed with MDMS update + // Perform MDMS Update mutation.mutate( { - url: reqCriteriaUpdate?.url, + url: reqCriteriaUpdate.url, params: {}, - body: { - Mdms: { - ...data, - data: formData, - }, - }, + body: { Mdms: { ...data, data: transformedFormData } }, }, { onError: (resp) => { - setShowToast({ - label: `${t("WBH_ERROR_MDMS_DATA")} ${t(resp?.response?.data?.Errors?.[0]?.code)}`, - isError: true, - }); + setShowToast({ label: t("WBH_ERROR_MDMS_DATA"), isError: true }); closeToast(); }, - onSuccess: (resp) => { - setShowToast({ - label: `${t("WBH_SUCCESS_UPD_MDMS_MSG")} ${resp?.mdms?.[0]?.id}`, - }); + onSuccess: () => { + setShowToast({ label: t("WBH_SUCCESS_UPD_MDMS_MSG") }); gotoView(); }, } ); }; - if (isLoading || isFetching) return ; + if (isLoading || isFetching || isLocalizationLoading || renderLoader) return ; return ( Date: Mon, 16 Dec 2024 09:47:13 +0530 Subject: [PATCH 05/15] mdms edit updated --- .../packages/modules/workbench/src/pages/employee/MDMSEdit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5ebb34745c1..201ef1a47f7 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 @@ -129,7 +129,7 @@ const MDMSEdit = ({ ...props }) => { if (fieldProps?.localizationCode && fieldProps?.localizationMessage) { const mdmsCode = (fieldProps.localizationMessage || "").replace(/\s+/g, "").toUpperCase(); messages.push({ - code: `${rawSchemaCode}_${fieldName}_${mdmsCode}`, + code: `${rawSchemaCode}_${fieldName}_${mdmsCode}`.toUpperCase(), message: fieldProps.localizationMessage, module: localizationModule, locale: "en_IN", From 608064d97e3fdafd3d9c24eb7a9c5d1dd4bfe28b Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Mon, 16 Dec 2024 14:16:17 +0530 Subject: [PATCH 06/15] keystroke fix --- .../modules/workbench/src/components/DigitJSONForm.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 5f80af1efeb..555f11bd397 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 @@ -92,7 +92,9 @@ function TitleFieldTemplate(props) { ); } -function ArrayFieldTitleTemplate() { +function ArrayFieldTitleTemplate(props) { + const { title, idSchema } = props; + const id = titleId(idSchema); return null; } @@ -135,7 +137,7 @@ function ObjectFieldTemplate(props) { const inputValue = formData[fieldName]; const isLocalisable = localisableFields.some((field) => field.fieldPath === fieldName); - if (isLocalisable && inputValue !== undefined) { + if (isLocalisable) { const fieldProps = additionalProperties?.[fieldName]; const mdmsCode = fieldProps?.mdmsCode; const localizationCode = fieldProps?.localizationCode; @@ -450,4 +452,4 @@ const DigitJSONForm = ({ ); }; -export default DigitJSONForm; +export default DigitJSONForm; \ No newline at end of file From c30ba57c223c6df91afa0c7db34d95bf722a2ae0 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 14:26:20 +0530 Subject: [PATCH 07/15] css fixes --- .../src/digitv2/pages/employee/workbench.scss | 51 +++++++++++- .../pages/employee/CreateComplaint/index.js | 1 - .../workbench/src/components/DigitJSONForm.js | 32 ++++++-- .../workbench/src/configs/UICustomizations.js | 62 ++++++++++++++ .../workbench/src/pages/employee/MDMSEdit.js | 81 +++++++------------ .../src/pages/employee/MDMSSearchv2.js | 4 +- 6 files changed, 172 insertions(+), 59 deletions(-) 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..4c18e999e59 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; /* Retain padding for alignment */ + background-color: #f9f9f9; /* Keep the subtle background */ + border: 1px solid #e0e0e0; /* Existing border */ + border-radius: 4px; /* Rounded corners */ +} + +.code-row { + display: flex; + align-items: flex-start; /* Align items from the top */ + margin-bottom: 0.75rem; /* Add spacing between rows */ +} + +.code-key { + flex: 0 0 150px; /* Fixed width for keys */ + font-size: 0.9rem; + font-weight: bold; /* Retain emphasis on keys */ + color: #444; /* Key color */ +} + +.code-value-container { + display: flex; + flex-direction: column; /* Stack values vertically */ + flex: 1; /* Take remaining space */ +} + +.code-value { + font-size: 0.9rem; + color: #555; /* Value color */ + margin-bottom: 0.2rem; /* Add spacing between stacked values */ +} + +.code-row:last-child { + margin-bottom: 0; /* Remove margin for the last row */ +} + + + + + + + + + + + diff --git a/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js b/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js index 1e46a2856b9..ef5752ef83f 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/pgr/src/pages/employee/CreateComplaint/index.js @@ -55,7 +55,6 @@ export const CreateComplaint = ({ parentUrl }) => { const [params, setParams] = useState({}); const tenantId = window.Digit.SessionStorage.get("Employee.tenantId"); const menu = Digit.Hooks.pgr.useComplaintTypes({ stateCode: tenantId }); - console.log("complaint types are"+ JSON.stringify(menu)); const dispatch = useDispatch(); const match = useRouteMatch(); const history = useHistory(); 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 555f11bd397..7b425642e13 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 @@ -141,19 +141,39 @@ function ObjectFieldTemplate(props) { const fieldProps = additionalProperties?.[fieldName]; const mdmsCode = fieldProps?.mdmsCode; const localizationCode = fieldProps?.localizationCode; - return ( -
+
+ {/* Actual Input Field */}
{element.content}
-
- {`mdms code: ${mdmsCode || ""}`} -
- {`localization code: ${localizationCode || ""}`} + + {/* MDMS and Localization Codes */} +
+
+ +
+ + {mdmsCode || ""} + +
+
+
+ +
+ + {localizationCode || ""} + +
+
); + } return ( 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..5c5ff140fc5 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 @@ -501,9 +501,71 @@ export const UICustomizations = { return data; }, additionalCustomizations: (row, key, column, value, t, searchResult) => { + console.log("data printed on the screen is"+ JSON.stringify(searchResult)); //here we can add multiple conditions //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 + + const rawSchemaCode = row?.schemaCode; + const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); + + // Function to create localization codes + const createLocalizationCode = (fieldName, fieldValue) => { + const upperFieldName = String(fieldName).toUpperCase(); + const transformedValue = String(fieldValue || "").replace(/\s+/g, "").toUpperCase(); + return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase(); + }; + + // Prepare localization codes for all fields in row.data + const localizationCodes = Object.keys(row.data || {}).map((field) => + createLocalizationCode(field, row.data[field]) + ); + + // Fetch localization messages + const localizationReqCriteria = { + url: `/localization/messages/v1/_search?locale=en_IN&tenantId=${Digit.ULBService.getCurrentTenantId()}&module=${localizationModule}`, + params: {}, + body: { + RequestInfo: { + apiId: null, + ver: null, + ts: null, + action: "POST", + did: null, + key: null, + msgId: Date.now().toString(), + authToken: Digit.UserService.getUser()?.access_token || "", + }, + }, + config: { + enabled: 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 } = Digit.Hooks.useCustomAPIHook(localizationReqCriteria); + + // Replace row data with localized values if available + if (localizationMap && row.data) { + Object.keys(row.data).forEach((field) => { + const code = createLocalizationCode(field, row.data[field]); + if (localizationMap[code]) { + row.data[field] = localizationMap[code]; // Replace with localized message + console.log("replacing the value"+ JSON.stringify(row)); + console.log("search result here is on the screen is"+ JSON.stringify(searchResult)); + + } + }); + } + switch (key) { case "WBH_UNIQUE_IDENTIFIER": const [moduleName, masterName] = row.schemaCode.split(".") 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 201ef1a47f7..ac2b43cb369 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 @@ -54,6 +54,33 @@ const MDMSEdit = ({ ...props }) => { const localisableFields = MdmsRes?.find((item) => item.schemaCode === `${moduleName}.${masterName}`)?.localisation ?.localisableFields || []; + // Fetch Schema Definitions + const reqCriteriaSchema = { + url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`, + params: {}, + body: { + SchemaDefCriteria: { + tenantId: stateId, + codes: [`${moduleName}.${masterName}`], + }, + }, + config: { + enabled: !!moduleName && !!masterName, + select: (data) => { + const uniqueFields = data?.SchemaDefinitions?.[0]?.definition?.["x-unique"] || []; + const updatesToUiSchema = {}; + uniqueFields.forEach((field) => { + updatesToUiSchema[field] = { "ui:readonly": true }; // Disable fields dynamically + }); + // Explicitly disable Complaint Sub-Type Code + updatesToUiSchema["complaintSubTypeCode"] = { "ui:readonly": true }; + return { schema: data?.SchemaDefinitions?.[0], updatesToUiSchema }; + }, + }, + }; + + const { isLoading: isSchemaLoading, data: schemaData } = Digit.Hooks.useCustomAPIHook(reqCriteriaSchema); + // Localization Search Preparation const rawSchemaCode = data?.schemaCode; const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); @@ -99,7 +126,6 @@ const MDMSEdit = ({ ...props }) => { finalData = updatedData; } - // MDMS Update Mutation const reqCriteriaUpdate = { url: Digit.Utils.workbench.getMDMSActionURL(moduleName, masterName, "update"), params: {}, @@ -109,57 +135,12 @@ const MDMSEdit = ({ ...props }) => { const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate); - // Localization Upsert Mutation - const localizationUpsertMutation = Digit.Hooks.useCustomAPIMutationHook({ - url: `/localization/messages/v1/_upsert`, - params: {}, - body: {}, - config: { enabled: false }, - }); - - 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) { - const mdmsCode = (fieldProps.localizationMessage || "").replace(/\s+/g, "").toUpperCase(); - messages.push({ - code: `${rawSchemaCode}_${fieldName}_${mdmsCode}`.toUpperCase(), - message: fieldProps.localizationMessage, - module: localizationModule, - locale: "en_IN", - }); - transformedFormData[fieldName] = mdmsCode; // Update mdmsCode - } - } - } - } - - try { - // Perform Localization Upsert - 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 + const handleUpdate = async (formData) => { mutation.mutate( { url: reqCriteriaUpdate.url, params: {}, - body: { Mdms: { ...data, data: transformedFormData } }, + body: { Mdms: { ...data, data: formData } }, }, { onError: (resp) => { @@ -174,7 +155,7 @@ const MDMSEdit = ({ ...props }) => { ); }; - if (isLoading || isFetching || isLocalizationLoading || renderLoader) return ; + if (isLoading || isFetching || isSchemaLoading || isLocalizationLoading || renderLoader) return ; return ( @@ -182,7 +163,7 @@ const MDMSEdit = ({ ...props }) => { defaultFormData={finalData?.data} screenType={"edit"} onSubmitEditAction={handleUpdate} - updatesToUISchema={{ "ui:readonly": false }} + updatesToUISchema={schemaData?.updatesToUiSchema} // Pass updatesToUiSchema /> {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 224c0b914e4..5904e0e225c 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 @@ -163,7 +163,7 @@ const MDMSSearchv2 = () => { // dontShowNA:true }] Config.apiDetails.serviceName=`/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`; - + console.log("configuration details are"+ JSON.stringify(Config)); setUpdatedConfig(Config) } }, [currentSchema]); @@ -183,6 +183,8 @@ const MDMSSearchv2 = () => { history.push(`/${window.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${row.uniqueIdentifier}${additionalParamString ? "&"+additionalParamString : ""}`) } + console.log("updated configuration"+ JSON.stringify(updatedConfig)); + if (isLoading) return ; return ( From 745974ea2095740766e92079d23c457619e5092c Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 14:40:48 +0530 Subject: [PATCH 08/15] inter package json updated --- micro-ui/web/core/inter-package.json | 1 + micro-ui/web/sandbox/inter-package.json | 1 + micro-ui/web/workbench/inter-package.json | 1 + 3 files changed, 3 insertions(+) diff --git a/micro-ui/web/core/inter-package.json b/micro-ui/web/core/inter-package.json index d921ea14e61..47b2a3b9d9b 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/sandbox/inter-package.json b/micro-ui/web/sandbox/inter-package.json index cd176f6aef5..02d244f5635 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 d8f50f40358..1f65f3669a6 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" }, From 9d68cf4a90c56ba7a04782390348209485ac9f70 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 15:04:52 +0530 Subject: [PATCH 09/15] ui cusotmization --- .../packages/modules/sandbox/src/configs/UICustomizations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 5ba8d419b6878e604cbb3fc33f20aee2c7abca2c Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 15:06:09 +0530 Subject: [PATCH 10/15] cleanup console --- .../packages/modules/core/src/pages/employee/Login/login.js | 6 +++--- .../packages/modules/core/src/pages/employee/Otp/index.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js index 24a51fbd940..afcb7a610cb 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Login/login.js @@ -7,9 +7,9 @@ import Header from "../../../components/Header"; /* set employee details to enable backward compatiable */ const setEmployeeDetail = (userObject, token) => { -// if (Digit.Utils.getMultiRootTenant()) { -// return; -// } + if (Digit.Utils.getMultiRootTenant()) { + return; + } let locale = JSON.parse(sessionStorage.getItem("Digit.locale"))?.value || Digit.Utils.getDefaultLanguage(); localStorage.setItem("Employee.tenant-id", userObject?.tenantId); localStorage.setItem("tenant-id", userObject?.tenantId); diff --git a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js index bd98b94127b..25f10845d79 100644 --- a/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js +++ b/micro-ui/web/micro-ui-internals/packages/modules/core/src/pages/employee/Otp/index.js @@ -8,9 +8,9 @@ import Header from "../../../components/Header"; /* set employee details to enable backward compatiable */ const setEmployeeDetail = (userObject, token) => { - // if (Digit.Utils.getMultiRootTenant()) { - // return; - // } + if (Digit.Utils.getMultiRootTenant()) { + return; + } let locale = JSON.parse(sessionStorage.getItem("Digit.locale"))?.value || Digit.Utils.getDefaultLanguage(); localStorage.setItem("Employee.tenant-id", userObject?.tenantId); localStorage.setItem("tenant-id", userObject?.tenantId); From 62cf267f8f8092705b7dd70de96ce18a6f8353dc Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 15:13:52 +0530 Subject: [PATCH 11/15] removed console log --- .../workbench/src/configs/UICustomizations.js | 64 +------------------ .../workbench/src/pages/employee/MDMSAddV2.js | 4 -- .../src/pages/employee/MDMSSearchv2.js | 4 -- .../workbench/src/pages/employee/MDMSView.js | 1 - 4 files changed, 1 insertion(+), 72 deletions(-) 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 5c5ff140fc5..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 @@ -501,71 +501,9 @@ export const UICustomizations = { return data; }, additionalCustomizations: (row, key, column, value, t, searchResult) => { - console.log("data printed on the screen is"+ JSON.stringify(searchResult)); //here we can add multiple conditions //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 - - const rawSchemaCode = row?.schemaCode; - const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); - - // Function to create localization codes - const createLocalizationCode = (fieldName, fieldValue) => { - const upperFieldName = String(fieldName).toUpperCase(); - const transformedValue = String(fieldValue || "").replace(/\s+/g, "").toUpperCase(); - return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase(); - }; - - // Prepare localization codes for all fields in row.data - const localizationCodes = Object.keys(row.data || {}).map((field) => - createLocalizationCode(field, row.data[field]) - ); - - // Fetch localization messages - const localizationReqCriteria = { - url: `/localization/messages/v1/_search?locale=en_IN&tenantId=${Digit.ULBService.getCurrentTenantId()}&module=${localizationModule}`, - params: {}, - body: { - RequestInfo: { - apiId: null, - ver: null, - ts: null, - action: "POST", - did: null, - key: null, - msgId: Date.now().toString(), - authToken: Digit.UserService.getUser()?.access_token || "", - }, - }, - config: { - enabled: 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 } = Digit.Hooks.useCustomAPIHook(localizationReqCriteria); - - // Replace row data with localized values if available - if (localizationMap && row.data) { - Object.keys(row.data).forEach((field) => { - const code = createLocalizationCode(field, row.data[field]); - if (localizationMap[code]) { - row.data[field] = localizationMap[code]; // Replace with localized message - console.log("replacing the value"+ JSON.stringify(row)); - console.log("search result here is on the screen is"+ JSON.stringify(searchResult)); - - } - }); - } - switch (key) { case "WBH_UNIQUE_IDENTIFIER": const [moduleName, masterName] = row.schemaCode.split(".") @@ -872,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 39100cfed50..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 @@ -114,9 +114,6 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie }; const onSubmit = (data, additionalProperties) => { - console.log("data on submit is" + JSON.stringify(data)); - console.log("add data on submit is" + JSON.stringify(additionalProperties)); - toggleSpinner(true); const onSuccess = async (resp) => { // After main MDMS add success @@ -267,7 +264,6 @@ const MDMSAdd = ({ defaultFormData, updatesToUISchema, screenType = "add", onVie } const uiJSONSchema = formSchema?.["definition"]?.["x-ui-schema"]; - console.log("session schema object is" + JSON.stringify(formSchema)); return ( {spinner && } 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 5904e0e225c..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 @@ -19,7 +19,6 @@ const toDropdownObj = (master = "", mod = "") => { const MDMSSearchv2 = () => { - console.log("in the search page now") let Config = _.clone(Configg) const { t } = useTranslation(); const history = useHistory(); @@ -163,7 +162,6 @@ const MDMSSearchv2 = () => { // dontShowNA:true }] Config.apiDetails.serviceName=`/${Digit.Hooks.workbench.getMDMSContextPath()}/v2/_search`; - console.log("configuration details are"+ JSON.stringify(Config)); setUpdatedConfig(Config) } }, [currentSchema]); @@ -183,8 +181,6 @@ const MDMSSearchv2 = () => { history.push(`/${window.contextPath}/employee/workbench/mdms-view?moduleName=${moduleName}&masterName=${masterName}&uniqueIdentifier=${row.uniqueIdentifier}${additionalParamString ? "&"+additionalParamString : ""}`) } - console.log("updated configuration"+ JSON.stringify(updatedConfig)); - if (isLoading) return ; return ( 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 f9965bff780..87f407757b1 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 @@ -149,7 +149,6 @@ const MDMSView = ({ ...props }) => { let localizationCodes = []; if (data && data.data && localisableFields.length > 0) { localizationCodes = localisableFields.map(field => createLocalizationCode(field.fieldPath, data.data[field.fieldPath])); - console.log("localizable fields constructed"+localizationCodes); } const locale = "en_IN"; From 680d8e8903834f388dd423110401db412c6b5ef5 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 15:35:58 +0530 Subject: [PATCH 12/15] updated mdms edit --- .../workbench/src/components/DigitJSONForm.js | 60 ++++++------ .../workbench/src/pages/employee/MDMSEdit.js | 92 ++++++++++++------- 2 files changed, 90 insertions(+), 62 deletions(-) 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 7b425642e13..ebb8beea2ec 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 @@ -141,38 +141,42 @@ function ObjectFieldTemplate(props) { const fieldProps = additionalProperties?.[fieldName]; const mdmsCode = fieldProps?.mdmsCode; const localizationCode = fieldProps?.localizationCode; - return ( -
- {/* Actual Input Field */} -
- {element.content} -
- - {/* MDMS and Localization Codes */} -
-
- -
- - {mdmsCode || ""} - -
+ const isMultiRootTenant = Digit.Utils.getMultiRootTenant(); + if(isMultiRootTenant){ + return ( +
+ {/* Actual Input Field */} +
+ {element.content}
-
- -
- - {localizationCode || ""} - + + {/* MDMS and Localization Codes */} +
+
+ +
+ + {mdmsCode || ""} + +
+
+
+ +
+ + {localizationCode || ""} + +
-
- ); + ); + } + } 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 ac2b43cb369..0b8114c9efd 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 @@ -46,14 +46,6 @@ const MDMSEdit = ({ ...props }) => { const { isLoading, data, isFetching } = Digit.Hooks.useCustomAPIHook(reqCriteria); - // Fetch UISchema to identify localisable fields - const { data: MdmsRes } = Digit.Hooks.useCustomMDMS(stateId, "Workbench", [{ name: "UISchema" }], { - select: (data) => data?.["Workbench"]?.["UISchema"], - }); - - const localisableFields = MdmsRes?.find((item) => item.schemaCode === `${moduleName}.${masterName}`)?.localisation - ?.localisableFields || []; - // Fetch Schema Definitions const reqCriteriaSchema = { url: `/${Digit.Hooks.workbench.getMDMSContextPath()}/schema/v1/_search`, @@ -70,10 +62,9 @@ const MDMSEdit = ({ ...props }) => { const uniqueFields = data?.SchemaDefinitions?.[0]?.definition?.["x-unique"] || []; const updatesToUiSchema = {}; uniqueFields.forEach((field) => { - updatesToUiSchema[field] = { "ui:readonly": true }; // Disable fields dynamically + updatesToUiSchema[field] = { "ui:readonly": true }; }); - // Explicitly disable Complaint Sub-Type Code - updatesToUiSchema["complaintSubTypeCode"] = { "ui:readonly": true }; + updatesToUiSchema["complaintSubTypeCode"] = { "ui:readonly": true }; // Explicitly disable Complaint Sub-Type Code return { schema: data?.SchemaDefinitions?.[0], updatesToUiSchema }; }, }, @@ -81,31 +72,22 @@ const MDMSEdit = ({ ...props }) => { const { isLoading: isSchemaLoading, data: schemaData } = Digit.Hooks.useCustomAPIHook(reqCriteriaSchema); - // Localization Search Preparation - const rawSchemaCode = data?.schemaCode; - const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); + // Localization Search + const localizationModule = `DIGIT_MDMS_${data?.schemaCode}`.toUpperCase(); const locale = "en_IN"; - const createLocalizationCode = (fieldName, fieldValue) => { - const upperFieldName = fieldName.toUpperCase(); - const transformedValue = (fieldValue || "").replace(/\s+/g, "").toUpperCase(); - return `${rawSchemaCode}_${upperFieldName}_${transformedValue}`.toUpperCase(); - }; - - const localizationCodes = - data?.data && localisableFields.length > 0 - ? localisableFields.map((field) => createLocalizationCode(field.fieldPath, data.data[field.fieldPath])) - : []; const localizationReqCriteria = { url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${stateId}&module=${localizationModule}`, params: {}, body: { RequestInfo: { authToken: Digit.UserService.getUser()?.access_token || "" } }, config: { - enabled: !!data && localizationCodes.length > 0, + enabled: !!data, select: (respData) => { - let messageMap = {}; + const messageMap = {}; if (Array.isArray(respData?.messages)) { - respData.messages.forEach((msg) => (messageMap[msg.code] = msg.message)); + respData.messages.forEach((msg) => { + messageMap[msg.code] = msg.message; + }); } return messageMap; }, @@ -114,18 +96,26 @@ const MDMSEdit = ({ ...props }) => { const { data: localizationMap, isLoading: isLocalizationLoading } = Digit.Hooks.useCustomAPIHook(localizationReqCriteria); + // Replace values with localized messages let finalData = data; if (data?.data && localizationMap) { const updatedData = _.cloneDeep(data); - localisableFields.forEach((field) => { - const code = createLocalizationCode(field.fieldPath, updatedData.data[field.fieldPath]); - if (localizationMap[code]) { - updatedData.data[field.fieldPath] = localizationMap[code]; + 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 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: {}, @@ -135,12 +125,46 @@ const MDMSEdit = ({ ...props }) => { const mutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaUpdate); - const handleUpdate = async (formData) => { + 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, params: {}, - body: { Mdms: { ...data, data: formData } }, + body: { Mdms: { ...data, data: transformedFormData } }, }, { onError: (resp) => { @@ -163,7 +187,7 @@ const MDMSEdit = ({ ...props }) => { defaultFormData={finalData?.data} screenType={"edit"} onSubmitEditAction={handleUpdate} - updatesToUISchema={schemaData?.updatesToUiSchema} // Pass updatesToUiSchema + updatesToUISchema={schemaData?.updatesToUiSchema} /> {showToast && setShowToast(null)} />} From c0d0d45c870fb0d77d3306130db1ba0d0e41c473 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 15:39:43 +0530 Subject: [PATCH 13/15] cleanup console log --- .../src/digitv2/pages/employee/workbench.scss | 28 +++++++++---------- .../workbench/src/components/DigitJSONForm.js | 10 ------- 2 files changed, 14 insertions(+), 24 deletions(-) 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 4c18e999e59..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 @@ -1052,39 +1052,39 @@ background-color: #eaffee; .code-details { - padding: 0.5rem 1.5rem; /* Retain padding for alignment */ - background-color: #f9f9f9; /* Keep the subtle background */ - border: 1px solid #e0e0e0; /* Existing border */ - border-radius: 4px; /* Rounded corners */ + padding: 0.5rem 1.5rem; + background-color: #f9f9f9; + border: 1px solid #e0e0e0; + border-radius: 4px; } .code-row { display: flex; - align-items: flex-start; /* Align items from the top */ - margin-bottom: 0.75rem; /* Add spacing between rows */ + align-items: flex-start; + margin-bottom: 0.75rem; } .code-key { - flex: 0 0 150px; /* Fixed width for keys */ + flex: 0 0 150px; font-size: 0.9rem; - font-weight: bold; /* Retain emphasis on keys */ - color: #444; /* Key color */ + font-weight: bold; + color: #444; } .code-value-container { display: flex; - flex-direction: column; /* Stack values vertically */ - flex: 1; /* Take remaining space */ + flex-direction: column; + flex: 1; } .code-value { font-size: 0.9rem; - color: #555; /* Value color */ - margin-bottom: 0.2rem; /* Add spacing between stacked values */ + color: #555; + margin-bottom: 0.2rem; } .code-row:last-child { - margin-bottom: 0; /* Remove margin for the last row */ + margin-bottom: 0; } 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 ebb8beea2ec..14d1a1614ac 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 @@ -312,7 +312,6 @@ const DigitJSONForm = ({ const secondFormatLocalizationMutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaSecondUpsert); const onSubmitV2 = async ({ formData }, e) => { - console.log("additional data", additionalProperties); const transformedFormData = { ...formData }; @@ -325,7 +324,6 @@ const DigitJSONForm = ({ } } - console.log("Transformed formData before submit:", transformedFormData); // Construct second format localization messages // no conditions changed, just always attempt creation @@ -350,9 +348,6 @@ const DigitJSONForm = ({ } } - console.log("Attempting second format localization upsert before main onSubmit..."); - console.log("secondFormatMessages:", secondFormatMessages); - if (secondFormatMessages.length > 0) { try { await secondFormatLocalizationMutation.mutateAsync({ @@ -362,15 +357,10 @@ const DigitJSONForm = ({ messages: secondFormatMessages } }); - console.log("Second format localization upsert successful!"); } catch (err) { console.error("Second format localization upsert failed:", err); } - } else { - console.log("No second format messages to upsert"); } - - // Now call main onSubmit onSubmit && onSubmit(transformedFormData, additionalProperties); }; From 60650ad5337a8884dec42c0baa1bdd409d4bed94 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 19:19:34 +0530 Subject: [PATCH 14/15] console cleanup --- .../workbench/src/pages/employee/MDMSEdit.js | 2 +- .../workbench/src/pages/employee/MDMSView.js | 16 ---------------- 2 files changed, 1 insertion(+), 17 deletions(-) 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 0b8114c9efd..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 @@ -79,7 +79,7 @@ const MDMSEdit = ({ ...props }) => { const localizationReqCriteria = { url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${stateId}&module=${localizationModule}`, params: {}, - body: { RequestInfo: { authToken: Digit.UserService.getUser()?.access_token || "" } }, + body: {}, config: { enabled: !!data, select: (respData) => { 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 87f407757b1..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 @@ -132,12 +132,7 @@ const MDMSView = ({ ...props }) => { localisableFields = schemaDef?.localisation?.localisableFields || []; } - // Ensure that the module matches what was used when upserting localization messages. - // If your messages have module "DIGIT_MDMS_RAINMAKER-PGR.SERVICEDEFS", replicate that exactly: const rawSchemaCode = data?.schemaCode; - // Convert schema code to match exactly how module was stored in messages. - // Example: If messages stored module as: DIGIT_MDMS_RAINMAKER-PGR.SERVICEDEFS - // Convert rawSchemaCode: "RAINMAKER-PGR.ServiceDefs" -> "RAINMAKER-PGR.SERVICEDEFS" const localizationModule = `DIGIT_MDMS_${rawSchemaCode}`.toUpperCase(); const createLocalizationCode = (fieldName, fieldValue) => { @@ -152,21 +147,10 @@ const MDMSView = ({ ...props }) => { } const locale = "en_IN"; - const localizationReqCriteria = { url: `/localization/messages/v1/_search?locale=${locale}&tenantId=${tenantId}&module=${localizationModule}`, params: {}, body: { - RequestInfo: { - apiId: null, - ver: null, - ts: null, - action: "POST", - did: null, - key: null, - msgId: Date.now().toString(), - authToken: Digit.UserService.getUser()?.access_token || "", - } }, config: { enabled: !!data && !!MdmsRes && !!data?.schemaCode && !!tenantId && localizationCodes.length > 0, From a8a7f8ca9b067b5e6a2c6eb94c479c743819dc81 Mon Sep 17 00:00:00 2001 From: mithun-hegde-egov Date: Wed, 18 Dec 2024 19:21:06 +0530 Subject: [PATCH 15/15] cleanup console --- .../modules/workbench/src/components/DigitJSONForm.js | 6 +----- micro-ui/web/public/index.html | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) 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 14d1a1614ac..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 @@ -300,13 +300,12 @@ const DigitJSONForm = ({ } }, [formData, MdmsRes, schema]); - // Define second upsert mutation using custom API hook const reqCriteriaSecondUpsert = { url: `/localization/messages/v1/_upsert`, params: {}, body: {}, config: { - enabled: false, // We'll call mutateAsync manually + enabled: false, }, }; const secondFormatLocalizationMutation = Digit.Hooks.useCustomAPIMutationHook(reqCriteriaSecondUpsert); @@ -324,9 +323,6 @@ const DigitJSONForm = ({ } } - - // Construct second format localization messages - // no conditions changed, just always attempt creation const schemaCodeParts = schema?.code?.split(".") || []; const firstPart = schemaCodeParts[0]?.toLowerCase() || "default"; const secondPart = schemaCodeParts[1]?.toUpperCase() || ""; 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 @@ - +