Skip to content

Commit

Permalink
Adding helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
areyeslo committed Nov 26, 2024
1 parent a8537ba commit 61f99c2
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions frontend/src/views/OtherUses/AddEditOtherUses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ export const AddEditOtherUses = () => {
}
}, [otherUses]);

const findCiOfFuel = useCallback((data, optionsData) => {
let ciOfFuel = 0;
if (data.provisionOfTheAct === PROVISION_APPROVED_FUEL_CODE) {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => data.fuelType === obj.fuelType
);
const fuelCode = fuelType?.fuelCodes?.find(
(item) => item.fuelCode === data.fuelCode
);
ciOfFuel = fuelCode?.carbonIntensity || 0;
} else {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => data.fuelType === obj.fuelType
);
ciOfFuel = fuelType?.defaultCarbonIntensity || 0;
}
return ciOfFuel;
}, []);

const onGridReady = (params) => {
const ensureRowIds = (rows) => {
return rows.map((row) => {
Expand Down Expand Up @@ -128,22 +147,7 @@ export const AddEditOtherUses = () => {
params.colDef.field
)
) {
let ciOfFuel = 0
if (params.data.provisionOfTheAct === PROVISION_APPROVED_FUEL_CODE) {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => params.data.fuelType === obj.fuelType
)
const fuelCode = fuelType?.fuelCodes?.find(
(item) => item.fuelCode === params.data.fuelCode
)
ciOfFuel = fuelCode?.carbonIntensity || 0
} else {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => params.data.fuelType === obj.fuelType
)
ciOfFuel = fuelType?.defaultCarbonIntensity || 0
}

const ciOfFuel = findCiOfFuel(params.data, optionsData)
params.node.setDataValue('ciOfFuel', ciOfFuel)
}
},
Expand Down

0 comments on commit 61f99c2

Please sign in to comment.