From 0ae04151219feab1aa8225f76ded0154b94e4c8b Mon Sep 17 00:00:00 2001 From: Tulika-eGov Date: Tue, 18 Jun 2024 11:25:58 +0530 Subject: [PATCH] UCEM-195 : Added validation for the search template --- .../micro-ui-internals/example/package.json | 2 +- .../web/micro-ui-internals/package.json | 2 +- .../packages/modules/Estimate/package.json | 2 +- .../src/pageComponents/searchTemplate.js | 33 ++++++++++++++----- frontend/micro-ui/web/package.json | 4 +-- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/frontend/micro-ui/web/micro-ui-internals/example/package.json b/frontend/micro-ui/web/micro-ui-internals/example/package.json index 7f155977b9..852481b570 100644 --- a/frontend/micro-ui/web/micro-ui-internals/example/package.json +++ b/frontend/micro-ui/web/micro-ui-internals/example/package.json @@ -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", diff --git a/frontend/micro-ui/web/micro-ui-internals/package.json b/frontend/micro-ui/web/micro-ui-internals/package.json index a98bdcf59f..d91639de55 100644 --- a/frontend/micro-ui/web/micro-ui-internals/package.json +++ b/frontend/micro-ui/web/micro-ui-internals/package.json @@ -9,7 +9,7 @@ "packages/react-components", "packages/modules/*", "packages/modules/Estimate", - "packages/modules/Expenditure", + "packages/modules/*", "packages/Mukta", "packages/modules/RateAnalysis" ], diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/package.json b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/package.json index 2d88a80719..8174d33b39 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/package.json +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/package.json @@ -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", diff --git a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/src/pageComponents/searchTemplate.js b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/src/pageComponents/searchTemplate.js index d446ac7bd9..762695d556 100644 --- a/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/src/pageComponents/searchTemplate.js +++ b/frontend/micro-ui/web/micro-ui-internals/packages/modules/Estimate/src/pageComponents/searchTemplate.js @@ -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 @@ -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 @@ -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)]; @@ -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 ( @@ -261,7 +276,7 @@ const buttonClick = async () => { {suggestions?.length > 0 && (