Skip to content

Commit

Permalink
Merge pull request #435 from odisha-muktasoft/UCEM-195-UI-2
Browse files Browse the repository at this point in the history
UCEM-195 : Added validation for the search template
  • Loading branch information
Tulika-eGov authored Jun 18, 2024
2 parents 075d37e + 0ae0415 commit 6003a4c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@egovernments/digit-ui-module-attendencemgmt": "0.4.1",
"@egovernments/digit-ui-module-contracts": "0.4.1",
"@egovernments/digit-ui-module-measurement":"0.2.0",
"@egovernments/digit-ui-module-estimate": "0.4.4",
"@egovernments/digit-ui-module-estimate": "0.4.5",
"@egovernments/digit-ui-module-masters": "0.4.1",
"@egovernments/digit-ui-module-project": "0.4.1",
"@egovernments/digit-ui-module-expenditure": "0.4.1",
Expand Down
2 changes: 1 addition & 1 deletion frontend/micro-ui/web/micro-ui-internals/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"packages/react-components",
"packages/modules/*",
"packages/modules/Estimate",
"packages/modules/Expenditure",
"packages/modules/*",
"packages/Mukta",
"packages/modules/RateAnalysis"
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@egovernments/digit-ui-module-estimate",
"version": "0.4.4",
"version": "0.4.5",
"description": "Estimate Module UI",
"main": "dist/index.js",
"module": "dist/index.modern.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ const fetchTemplateData = async (searchText, setShowToast) => {
"masterDetails": [
{
"name": "EstimateTemplate",
"filter": searchText?.startsWith("TMP_") ? `$[?(@.templateId=~/${searchText}/i )]` : `$[?(@.templateName=~/.*${searchText}.*/i )]`
"filter": `$[?(@.templateId=~/.*${searchText}.*/i || @.templateName=~/.*${searchText}.*/i )]`
}
]
}
]
}
}
},
useCache: false,
setTimeParam: false
};

//either search with Template id or name
Expand Down Expand Up @@ -99,13 +101,15 @@ const fetchData = async (sorid, state, setState, setShowToast,t) => {
});
if(Rates.length <= 0)
{
setShowToast({show: true, error: true, label:`${t(`TMP_RATE_NO_ACTIVE_RATE_ERROR`)} ${sorid}`});
//setShowToast({show: true, error: true, label:`${t(`TMP_RATE_NO_ACTIVE_RATE_ERROR`)} ${sorid}`});
return undefined;
}
return Rates;
}
else
{
setShowToast({show: true, error: true, label:`${t(`TMP_RATE_NOT_FOUND_ERROR`)} ${sorid}`});
//setShowToast({show: true, error: true, label:`${t(`TMP_RATE_NOT_FOUND_ERROR`)} ${sorid}`});
return undefined;
}
} catch (error) {
// Handle any errors here
Expand Down Expand Up @@ -208,15 +212,22 @@ const buttonClick = async () => {
try {
// Fetch rates for SOR items
const sorItems = transformedItems?.filter(item => item.category === "SOR") || [];
let ratesErrorSorIds = [];
for (const sor of sorItems) {
const apiData = await fetchData(sor.sorCode, formData, setFormValue, setShowToast,t);
if (apiData !== undefined && apiData?.[0]?.sorId === sor.sorId) {
sor.unitRate = apiData?.[0]?.rate || 0;
sor.amountDetails = apiData?.[0]?.amountDetails;
} else {
ratesErrorSorIds.push(sor?.sorCode);
console.error('Rates not available in fetchData response');
}
}

if(ratesErrorSorIds?.length > 0)
{
setShowToast({show: true, error: true, label:`${t(`TMP_RATE_NOT_FOUND_OR_ACTIVE_ERROR`)} ${ratesErrorSorIds.join(", ")} `});
}

// Combine SOR and non-SOR items
let updatedFormData = [...formData, ...transformedItems?.filter(item => item.category === "SOR" && item?.amountDetails)];
Expand All @@ -238,10 +249,14 @@ const buttonClick = async () => {
};

const handleSelectOption = (option) => {
setStateData({...stateData, selectedTemplate:option});
setInputValue(option?.templateName);
setSelectedTemplate(option);
setSuggestions([]);
//check if optionid is there or not
if(option?.templateId)
{
setStateData({...stateData, selectedTemplate:option});
setInputValue(option?.templateName);
setSelectedTemplate(option);
setSuggestions([]);
}
};

return (
Expand All @@ -261,7 +276,7 @@ const buttonClick = async () => {
{suggestions?.length > 0 && (
<ul className="suggestions-sor" style={{ zIndex: "10", maxHeight: "33rem", overflow: "auto" }}>
{suggestions.map((option) => (
<li key={option.id} onClick={() => handleSelectOption(option)}>
<li key={option?.templateId} onClick={() => handleSelectOption(option)}>
{option?.templateName}
</li>
))}
Expand Down
4 changes: 2 additions & 2 deletions frontend/micro-ui/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"micro-ui-internals/packages/react-components",
"micro-ui-internals/packages/modules/Estimate",
"micro-ui-internals/packages/modules/Expenditure",
"micro-ui-internals/packages/modules/Measurement",
"micro-ui-internals/packages/modules/*",
"micro-ui-internals/packages/Mukta",
"micro-ui-internals/packages/modules/RateAnalysis"
],
Expand All @@ -26,7 +26,7 @@
"@egovernments/digit-ui-module-attendencemgmt": "0.4.1",
"@egovernments/digit-ui-module-contracts": "0.4.1",
"@egovernments/digit-ui-module-measurement":"0.2.0",
"@egovernments/digit-ui-module-estimate": "0.4.4",
"@egovernments/digit-ui-module-estimate": "0.4.5",
"@egovernments/digit-ui-module-masters": "0.4.1",
"@egovernments/digit-ui-module-project": "0.4.1",
"@egovernments/digit-ui-module-expenditure": "0.4.1",
Expand Down

0 comments on commit 6003a4c

Please sign in to comment.