Skip to content

Feature/hcmpre 2588 #2314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: console
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion health/micro-ui/web/console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"homepage": "/console",
"dependencies": {
"@egovernments/digit-ui-libraries": "1.8.10",
"@egovernments/digit-ui-libraries": "1.8.11",
"@egovernments/digit-ui-module-core": "1.8.30",
"@egovernments/digit-ui-react-components": "1.8.19",
"@egovernments/digit-ui-components":"0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion health/micro-ui/web/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"homepage": "/core-ui",
"dependencies": {
"@egovernments/digit-ui-libraries": "1.8.10",
"@egovernments/digit-ui-libraries": "1.8.11",
"@egovernments/digit-ui-module-core": "1.8.30",
"@egovernments/digit-ui-react-components": "1.8.19",
"@egovernments/digit-ui-components":"0.0.2-beta.66",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "react-scripts start"
},
"devDependencies": {
"@egovernments/digit-ui-libraries": "1.8.10",
"@egovernments/digit-ui-libraries": "1.8.11",
"@egovernments/digit-ui-module-workbench": "1.0.12",
"@egovernments/digit-ui-components": "0.0.2-beta.65",
"@egovernments/digit-ui-module-core": "1.8.30",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import DataTable from "react-data-table-component";
import { useTranslation } from "react-i18next";
import { wrap } from "lodash";


const LocalisationEditorPopup = ({ locales,languages, currentLocale, localisationData, onSave, onClose }) => {
const LocalisationEditorPopup = ({ locales, languages, currentLocale, localisationData, onSave, onClose }) => {
const { t } = useTranslation();
const [activeLocale, setActiveLocale] = useState(locales[0]);
const [translations, setTranslations] = useState({});
Expand All @@ -25,40 +24,49 @@ const LocalisationEditorPopup = ({ locales,languages, currentLocale, localisatio
name: t(activeLocale),
cell: (row) => (
<TextInput
value={translations[row.code]?.[activeLocale] !== undefined && translations[row.code]?.[activeLocale] !== null
? translations[row.code]?.[activeLocale]
: row?.[activeLocale] !== undefined && row?.[activeLocale] !== null
? row?.[activeLocale]
: ""}
value={
translations[row.code]?.[activeLocale] !== undefined && translations[row.code]?.[activeLocale] !== null
? translations[row.code]?.[activeLocale]
: row?.[activeLocale] !== undefined && row?.[activeLocale] !== null
? row?.[activeLocale]
: ""
}
onChange={(e) =>
setTranslations((prev) => ({
...prev,
[row.code]: { ...prev[row.code], [activeLocale]: e.target.value },
}))
}
placeholder={t("ENTER_TRANSLATION")}
/>
>
</TextInput>
),
width: "55%",
},
];


return (
<div style={{ minWidth: "min-content" }}>
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Use self-closing JSX elements for elements without children

The current implementation has an empty div with opening and closing tags.

-<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
+<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }} />
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }}></div>
<div style={{ display: "flex", justifyContent: "space-between", marginBottom: "1rem" }} />
🧰 Tools
🪛 Biome (1.9.4)

[error] 50-50: JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.

Unsafe fix: Use a SelfClosingElement instead

(lint/style/useSelfClosingElements)


<Tab
activeLink = {activeLocale}
activeLink={activeLocale}
configItemKey="value"
configNavItems={languages}
onTabClick={(v)=>{}}
onTabClick={(v) => {}}
setActiveLink={setActiveLocale}
showNav
style={{}}
/>

<DataTable columns={columns} data={localisationData} pagination highlightOnHover noHeader persistTableHead />
<DataTable
columns={columns}
data={localisationData.filter((row) => row.message?.trim() !== "")}
pagination
highlightOnHover
noHeader
persistTableHead
/>

<div style={{ display: "flex", gap: "1rem", justifyContent: "flex-end", marginTop: "2rem" }}>
<Button label={t("CANCEL")} variation="secondary" onClick={onClose} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ const CreateChecklist = () => {
const { languages, stateInfo } = storeData || {};
const currentLocales = languages?.map(locale => locale.value);

const presentLocale = Digit?.SessionStorage.get("locale");

module = "hcm-checklist";
const { mutateAsync: localisationMutateAsync } = Digit.Hooks.campaign.useUpsertLocalisation(tenantId, module, locale);

Expand Down Expand Up @@ -237,7 +239,7 @@ const CreateChecklist = () => {
{
code: `${campaignName}.${checklistTypeTemp}.${roleTemp}.${helpTextCode}`,
locale: locale,
message: helpText || ".",
message: helpText || "",
module: "hcm-checklist"
}
);
Expand Down Expand Up @@ -353,7 +355,44 @@ const CreateChecklist = () => {

return { codes: codes, local: local };
};

function getFilteredLocaleEntries(quesArray, localeArray) {
const messages = new Set();

let activeCount = 0;

// Collect all active question titles, options, helpTexts, and sub-question titles
quesArray.forEach((question) => {
if (!question?.isActive) return;

activeCount++;
const prefix = `${activeCount}) `;

if (question.title) messages.add(prefix + question.title.trim());
if (question.helpText) messages.add(question.helpText.trim());

if (Array.isArray(question.options)) {
question.options.forEach((option) => {
if (option.label) messages.add(option.label.trim());

if (Array.isArray(option.subQuestions)) {
option.subQuestions.forEach((subQ) => {
if (subQ.isActive) {
if (subQ.title) messages.add(subQ.title.trim());
if (subQ.helpText) messages.add(subQ.helpText.trim());
}
});
}
});
}
});

// Now filter locale entries by matching message
const filteredLocales = localeArray.filter((entry) =>
messages.has(entry.message?.trim())
);
return filteredLocales;
}
// Helper function remains unchanged as it already handles both active and inactive questions
function createQuestionObject(item, tenantId, idCodeMap) {
let labelsArray = [];
Expand Down Expand Up @@ -483,7 +522,7 @@ const CreateChecklist = () => {
let allLocalisations = [...uniqueLocal, ...translations].filter(
(value, index, self) =>
index === self.findIndex((t) => t.code === value.code && t.locale === value.locale)
);
).filter((item) => item.message !== "");

setSubmitting(true);
try {
Expand Down Expand Up @@ -608,7 +647,8 @@ const CreateChecklist = () => {
onClick={() => {
const processed = organizeQuestions(tempFormData);
const { local: generatedLocal } = generateCodes(processed);
setLocalisationData(generatedLocal);
const currentLocalisationData = getFilteredLocaleEntries(processed, generatedLocal);
setLocalisationData(currentLocalisationData);
setShowLocalisationPopup(true);
setShowPopUp(false);
}}
Expand Down Expand Up @@ -693,11 +733,14 @@ const CreateChecklist = () => {
className="localisation-popup-container"
heading={t("ADD_TRANSLATIONS")}
onClose={() => setShowLocalisationPopup(false)}
onOverlayClick={() => {
setShowLocalisationPopup(false);
}}
>
<LocalisationEditorPopup
locales={currentLocales.filter(local => local !== locale)}
languages = {languages.filter(item => item.value !== locale)}
currentLocale={locale}
locales={currentLocales.filter(local => local !== presentLocale)}
languages = {languages.filter(item => item.value !== presentLocale)}
currentLocale={presentLocale}
localisationData={localisationData}
onSave={(translations) => {
onSubmit(null, 1, tempFormData, translations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import LocalisationEditorPopup from "../../components/LocalisationEditorPopup";

const UpdateChecklist = () => {
const { t } = useTranslation();
const module = "hcm-checklist";
const tenantId = Digit.ULBService.getCurrentTenantId();
const searchParams = new URLSearchParams(location.search);
const campaignName = searchParams.get("campaignName");
Expand All @@ -29,9 +30,9 @@ const UpdateChecklist = () => {
const [searching, setSearching] = useState(true);
const [viewData, setViewData] = useState(null);
let locale = Digit?.SessionStorage.get("initData")?.selectedLanguage || "en_IN";
const presentLocale = Digit?.SessionStorage.get("locale");
const { mutateAsync } = Digit.Hooks.campaign.useUpdateChecklist(tenantId);
const { mutateAsync: localisationMutateAsync } = Digit.Hooks.campaign.useUpsertLocalisation(tenantId, module, locale);
module = "hcm-checklist";
let processedData = [];
let checklistName = `${checklistType} ${role}`;
const [submitting, setSubmitting] = useState(false);
Expand Down Expand Up @@ -156,7 +157,7 @@ const UpdateChecklist = () => {
return organizedQuestions;
}

const { data: searchLocalisationData } = Digit.Hooks.campaign.useSearchLocalisation({
const { data: searchLocalisationData, refetch } = Digit.Hooks.campaign.useSearchLocalisation({
tenantId: tenantId,
locale: currentLocales,
module: module,
Expand All @@ -174,7 +175,7 @@ const UpdateChecklist = () => {
function enrichLocalizationData(localArray, searchLocalizationData) {
const existingCodeLocales = localArray.map(item => `${item.code}|${item.locale}`);

const entriesToAdd = searchLocalizationData.filter(searchItem => {
const entriesToAdd = searchLocalizationData?.filter(searchItem => {
const codeLocaleKey = `${searchItem.code}|${searchItem.locale}`;

return existingCodeLocales.includes(codeLocaleKey) === false &&
Expand Down Expand Up @@ -322,14 +323,68 @@ const UpdateChecklist = () => {
generateCode(question, '', index);
}
});
if(searchLocalisationData){
const enrichedArray = enrichLocalizationData(local, searchLocalisationData);
setLocalisationData(enrichedArray);
}

return { codes: codes, local: local };
};

function getFilteredLocaleEntries(quesArray, localeArray) {
const messages = new Set();

let activeCount = 0;

// Collect all active question titles, options, helpTexts, and sub-question titles
quesArray.forEach((question) => {
if (!question?.isActive) return;

activeCount++;
const prefix = `${activeCount}) `;

if (question.title) messages.add(prefix + question.title.trim());
if (question.helpText) messages.add(question.helpText.trim());

if (Array.isArray(question.options)) {
question.options.forEach((option) => {
if (option.label) messages.add(option.label.trim());

if (Array.isArray(option.subQuestions)) {
option.subQuestions.forEach((subQ) => {
if (subQ.isActive) {
if (subQ.title) messages.add(subQ.title.trim());
if (subQ.helpText) messages.add(subQ.helpText.trim());
}
});
}
});
}
});

// Now filter locale entries by matching message
const filteredLocales = localeArray.filter((entry) =>
messages.has(entry.message?.trim())
);

return filteredLocales;
}

function freshMessage(currentLocalisationData, enrichedArray) {
const common = enrichedArray.filter((enrichedItem) => {
const match = currentLocalisationData.find((localItem) => {
const localeMessage = localItem[enrichedItem.locale]; // e.g., en_IN
return (
localItem.code === enrichedItem.code &&
localItem.module === enrichedItem.module &&
localeMessage === enrichedItem.message
);
});
return match !== undefined;
});

setLocalisationData(common);

return common;
}


// Helper function remains unchanged as it already handles both active and inactive questions
function createQuestionObject(item, tenantId, idCodeMap) {
let labelsArray = [];
Expand Down Expand Up @@ -482,6 +537,7 @@ const UpdateChecklist = () => {
const data = await mutateAsync(payload);

if (data.success) { // Replace with your actual condition
refetch();
history.push(`/${window.contextPath}/employee/campaign/response?isSuccess=${true}`, {
message: "ES_CHECKLIST_UPDATE_SUCCESS_RESPONSE",
preText: "ES_CHECKLIST_UPDATE_SUCCESS_RESPONSE_PRE_TEXT",
Expand Down Expand Up @@ -577,7 +633,9 @@ const UpdateChecklist = () => {
onClick={() => {
const processed = organizeQuestions(tempFormData);
const { local: generatedLocal } = generateCodes(processed);
// setLocalisationData(generatedLocal);
const currentLocalisationData = getFilteredLocaleEntries(processed, generatedLocal);
const enrichedArray = enrichLocalizationData(generatedLocal, searchLocalisationData);
const fresh = freshMessage(currentLocalisationData , enrichedArray);
setShowLocalisationPopup(true);
setShowPopUp(false);
}}
Expand Down Expand Up @@ -642,6 +700,7 @@ const UpdateChecklist = () => {
className="localisation-popup-container"
heading={t("ADD_TRANSLATIONS")}
onClose={() => setShowLocalisationPopup(false)}
onOverlayClick={() => setShowLocalisationPopup(false)}
>
<LocalisationEditorPopup
locales={currentLocales.filter(local => local !== locale)}
Expand Down
Loading
Loading