From da7a5b469fbaf02f11acd22b54e408d86a8140f5 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Thu, 19 Dec 2024 13:00:40 -0700 Subject: [PATCH 1/2] Removing pre-select in Fuel Category when having multiple elements. --- frontend/src/assets/locales/en/fuelSupply.json | 2 +- .../src/views/FuelSupplies/AddEditFuelSupplies.jsx | 10 ++++++---- frontend/src/views/FuelSupplies/_schema.jsx | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/frontend/src/assets/locales/en/fuelSupply.json b/frontend/src/assets/locales/en/fuelSupply.json index 93c75760b..92ed0968f 100644 --- a/frontend/src/assets/locales/en/fuelSupply.json +++ b/frontend/src/assets/locales/en/fuelSupply.json @@ -15,7 +15,7 @@ "fuelSupplyId": "Fuel supply ID", "fuelType": "Fuel type", "fuelTypeOther": "Fuel type other", - "fuelCategory": "Fuel category", + "fuelCategoryId": "Fuel category", "endUse": "End use", "provisionOfTheActId": "Determining carbon intensity", "fuelCode": "Fuel code", diff --git a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx index 9d3ae3134..3873ed68d 100644 --- a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx +++ b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx @@ -161,10 +161,12 @@ export const AddEditFuelSupplies = () => { (item) => item.fuelCategory ) - params.node.setDataValue( - 'fuelCategory', - fuelCategoryOptions[0] ?? null - ) + // Set to null if multiple options, otherwise use first item + const categoryValue = fuelCategoryOptions.length === 1 + ? fuelCategoryOptions[0] + : null + + params.node.setDataValue('fuelCategory', categoryValue) } } }, diff --git a/frontend/src/views/FuelSupplies/_schema.jsx b/frontend/src/views/FuelSupplies/_schema.jsx index 5939d074b..969a3e9f9 100644 --- a/frontend/src/views/FuelSupplies/_schema.jsx +++ b/frontend/src/views/FuelSupplies/_schema.jsx @@ -145,9 +145,9 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ minWidth: 250 }, { - field: 'fuelCategory', + field: 'fuelCategoryId', headerComponent: RequiredHeader, - headerName: i18n.t('fuelSupply:fuelSupplyColLabels.fuelCategory'), + headerName: i18n.t('fuelSupply:fuelSupplyColLabels.fuelCategoryId'), cellEditor: AutocompleteCellEditor, cellRenderer: (params) => params.value || From eace15cc2d54d00fcdb475e604bbcf90b10b6506 Mon Sep 17 00:00:00 2001 From: Arturo Reyes Lopez Date: Fri, 20 Dec 2024 15:01:36 -0700 Subject: [PATCH 2/2] Code review changes --- .../src/views/FuelSupplies/AddEditFuelSupplies.jsx | 6 ++++-- .../src/views/FuelSupplies/FuelSupplySummary.jsx | 2 +- frontend/src/views/FuelSupplies/_schema.jsx | 14 +++----------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx index 3873ed68d..2c3c90356 100644 --- a/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx +++ b/frontend/src/views/FuelSupplies/AddEditFuelSupplies.jsx @@ -7,7 +7,7 @@ import { useGetFuelSupplies, useSaveFuelSupply } from '@/hooks/useFuelSupply' -import { isArrayEmpty } from '@/utils/formatters' +import { isArrayEmpty, cleanEmptyStringValues } from '@/utils/formatters' import BCTypography from '@/components/BCTypography' import Grid2 from '@mui/material/Unstable_Grid2/Grid2' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' @@ -201,7 +201,9 @@ export const AddEditFuelSupplies = () => { severity: 'pending' }) - let updatedData = params.node.data + // clean up any null or empty string values + let updatedData = cleanEmptyStringValues(params.node.data) + if (updatedData.fuelType === 'Other') { updatedData.ciOfFuel = DEFAULT_CI_FUEL[updatedData.fuelCategory] } diff --git a/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx b/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx index 6944b0383..b9808f1ad 100644 --- a/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx +++ b/frontend/src/views/FuelSupplies/FuelSupplySummary.jsx @@ -66,7 +66,7 @@ export const FuelSupplySummary = ({ data, status }) => { valueGetter: (params) => params.data.fuelType?.fuelType }, { - headerName: t('fuelSupply:fuelSupplyColLabels.fuelCategory'), + headerName: t('fuelSupply:fuelSupplyColLabels.fuelCategoryId'), field: 'fuelCategory', valueGetter: (params) => params.data.fuelCategory?.category }, diff --git a/frontend/src/views/FuelSupplies/_schema.jsx b/frontend/src/views/FuelSupplies/_schema.jsx index 969a3e9f9..ba1b52df9 100644 --- a/frontend/src/views/FuelSupplies/_schema.jsx +++ b/frontend/src/views/FuelSupplies/_schema.jsx @@ -98,6 +98,7 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ params.data.fuelTypeId = fuelType?.fuelTypeId params.data.fuelTypeOther = null params.data.fuelCategory = null + params.data.fuelCategoryId = null params.data.endUseId = null params.data.endUseType = null params.data.eer = null @@ -145,7 +146,7 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ minWidth: 250 }, { - field: 'fuelCategoryId', + field: 'fuelCategory', headerComponent: RequiredHeader, headerName: i18n.t('fuelSupply:fuelSupplyColLabels.fuelCategoryId'), cellEditor: AutocompleteCellEditor, @@ -182,16 +183,7 @@ export const fuelSupplyColDefs = (optionsData, errors, warnings) => [ }, suppressKeyboardEvent, minWidth: 135, - valueGetter: (params) => { - const options = optionsData?.fuelTypes - ?.find((obj) => params.data.fuelType === obj.fuelType) - ?.fuelCategories.map((item) => item.fuelCategory) - if (options?.length === 1) { - return options[0] - } else { - return params.data.fuelCategory - } - }, + valueGetter: (params) => params.data.fuelCategory, editable: (params) => optionsData?.fuelTypes ?.find((obj) => params.data.fuelType === obj.fuelType)