Skip to content

Commit

Permalink
Merge pull request #264 from odisha-muktasoft/PFM-5508-FIX
Browse files Browse the repository at this point in the history
PFM-5508 : fixed the state management issues in multi leasure row
  • Loading branch information
Tulika-eGov authored Mar 4, 2024
2 parents 78e3a8d + 7488c13 commit bba9cd9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const MeasureCard = React.memo(({ columns, fields = [], register, setValue, tabl
if(mode === "CREATE")
calculatedValue = element?.additionalDetails?.measureLineItems?.reduce((sum, row, index) => {
state[findIndex].additionalDetails.measureLineItems[index].quantity = initialValue(element,row) ? 0 : validate(row.number) * validate(row.length) * validate(row.width) * validate(row.height);
return sum + (validate(row.number) * validate(row.length) * validate(row.width) * validate(row.height));
return sum + (row?.quantity);
},0);
if (initialValue(element)) {
calculatedValue = 0;
Expand All @@ -122,17 +122,17 @@ const MeasureCard = React.memo(({ columns, fields = [], register, setValue, tabl
if (!row.additionalDetails || !row.additionalDetails.measureLineItems) return [];
const filteredMeasureLineItems = row.additionalDetails.measureLineItems.filter(ob => ob?.measurelineitemNo !== measurelineitemNo);
// Reorder measureLineItems to ensure they are in sequence
const reorderedMeasureLineItems = filteredMeasureLineItems.map((item, index) => ({ ...item, measurelineitemNo: index + 1 }));
return reorderedMeasureLineItems;
})?.[0]
//const reorderedMeasureLineItems = filteredMeasureLineItems.map((item, index) => ({ ...item, measurelineitemNo: index + 1 }));
return filteredMeasureLineItems;
})?.[0];
if(updatedmeasureLineItems)
state[findIndexofMeasure]["additionalDetails"]["measureLineItems"] = updatedmeasureLineItems;

//calculating the new total value and setting to the noofunits
const ele = state[findIndexofMeasure];
let calculatedvalue = ele?.additionalDetails?.measureLineItems?.reduce((sum, row, index) => {
state[findIndexofMeasure].additionalDetails.measureLineItems[index].quantity = initialValue(ele,row) ? 0 : validate(row.number) * validate(row.length) * validate(row.width) * validate(row.height);
return sum + (validate(row.number) * validate(row.length) * validate(row.width) * validate(row.height));
return sum + (row?.quantity);
},0);

//let calculatedValue = validate(element.number) * validate(element.length) * validate(element.width) * validate(element.height);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const MeasureInputAtom = ({ id, row, mode, disable = false, fieldKey, value, dis
let updatedMeasureLineItems = []
if(mode === "CREATE"){
updatedMeasureLineItems = row?.additionalDetails?.measureLineItems?.length > 0 ? [...row?.additionalDetails?.measureLineItems] : [];
updatedMeasureLineItems[measurelineitemNo][fieldKey] = newValue?.target?.value;
let findMeasureIndex = updatedMeasureLineItems?.findIndex((ob) => ob?.measurelineitemNo === measurelineitemNo);
updatedMeasureLineItems[findMeasureIndex][fieldKey] = newValue?.target?.value;
}
//on addition of multimeasure updating its value inside additional details
if(InputDecimalValidation?.active){
Expand Down Expand Up @@ -141,10 +142,10 @@ const MeasureRow = ({ value, index, rowState, dispatch, mode, fields }) => {
</>
)}

<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"number"} id={index + 1} value={firstMeasurelineitem?.["number"] || rowState?.["number"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"length"} id={index + 1} value={firstMeasurelineitem?.["length"] || rowState?.["length"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo}/>
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"width"} id={index + 1} value={firstMeasurelineitem?.["width"] || rowState?.["width"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"height"} id={index + 1} value={firstMeasurelineitem?.["height"] || rowState?.["height"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"number"} id={index + 1} value={value?.additionalDetails?.measureLineItems?.length > 0 ? firstMeasurelineitem?.["number"] : rowState?.["number"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"length"} id={index + 1} value={value?.additionalDetails?.measureLineItems?.length > 0 ? firstMeasurelineitem?.["length"] : rowState?.["length"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo}/>
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"width"} id={index + 1} value={value?.additionalDetails?.measureLineItems?.length > 0 ? firstMeasurelineitem?.["width"] : rowState?.["width"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<MeasureInputAtom dispatch={dispatch} row={value} disable={mode.includes("VIEW")} fieldKey={"height"} id={index + 1} value={value?.additionalDetails?.measureLineItems?.length > 0 ? firstMeasurelineitem?.["height"] : rowState?.["height"]} mode={mode} InputDecimalValidation={InputDecimalValidation} measurelineitemNo={firstMeasurelineitem?.measurelineitemNo} />
<td><div style={{marginBottom:"21px"}}>{firstMeasurelineitem?.["quantity"] || rowState?.noOfunit}</div></td>
{(mode == "CREATEALL" || mode == "CREATERE") && fields?.length > 1 && (
<td>
Expand Down Expand Up @@ -178,7 +179,7 @@ const MeasureRow = ({ value, index, rowState, dispatch, mode, fields }) => {
<Button
className={"outline-btn"}
label={t("MB_ADD_MORE_MBS")}
style={{width:"95%",borderRadius:"revert"}}
style={{width:"100%",borderRadius:"revert", marginLeft:"0px", marginRight:"0px"}}
onButtonClick={() => {
dispatch({
type: "ADD_MEASURE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const getMeasurementFromMeasures = (item, type) => {
additionalDetails: {
mbAmount: measure?.rowAmount || 0,
type: type,
measureLineItems : measure?.additionalDetails?.measureLineItems?.length == 1 && measure?.additionalDetails?.measureLineItems?.[0]?.quantity <= 0? [] : measure?.additionalDetails?.measureLineItems,
measureLineItems : measure?.additionalDetails?.measureLineItems?.length == 1 && measure?.additionalDetails?.measureLineItems?.[0]?.quantity <= 0? [] : measure?.additionalDetails?.measureLineItems?.filter(item => item.quantity !== null && item.quantity !== 0).sort((a, b) => a.measurelineitemNo - b.measurelineitemNo).map((item, index) => ({ ...item, measurelineitemNo: index })),
},
};
measurements.push(measurement);
Expand Down

0 comments on commit bba9cd9

Please sign in to comment.