Skip to content

Commit

Permalink
Merge pull request #1445 from bcgov/LCFS-1399-FuelsOtherUse-UnitAutoP…
Browse files Browse the repository at this point in the history
…opulated

LCFS-1399: Autopopulating units field depending on the Fuel Type selected
  • Loading branch information
areyeslo authored Dec 12, 2024
2 parents cbc1888 + d08d44e commit 390f6f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
12 changes: 12 additions & 0 deletions frontend/src/views/OtherUses/AddEditOtherUses.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ export const AddEditOtherUses = () => {
) {
const ciOfFuel = findCiOfFuel(params.data, optionsData)
params.node.setDataValue('ciOfFuel', ciOfFuel)

// Auto-populate the "Unit" field based on the selected fuel type
if (params.colDef.field === 'fuelType') {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => params.data.fuelType === obj.fuelType
);
if (fuelType && fuelType.units) {
params.node.setDataValue('units', fuelType.units);
} else {
params.node.setDataValue('units', '');
}
}
}
},
[optionsData]
Expand Down
28 changes: 15 additions & 13 deletions frontend/src/views/OtherUses/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,22 @@ export const otherUsesColDefs = (optionsData, errors) => [
{
field: 'units',
headerName: i18n.t('otherUses:otherUsesColLabels.units'),
headerComponent: RequiredHeader,
cellEditor: AutocompleteCellEditor,
minWidth: '155',
cellEditorParams: {
options: optionsData.unitsOfMeasure.map((obj) => obj),
multiple: false,
disableCloseOnSelect: false,
freeSolo: false,
openOnFocus: true
cellEditor: 'agSelectCellEditor',
cellEditorParams: (params) => {
const fuelType = optionsData?.fuelTypes?.find(
(obj) => params.data.fuelType === obj.fuelType
);
const values = fuelType ? [fuelType.units] : [];
return {
values: values
};
},
suppressKeyboardEvent,
cellRenderer: (params) =>
params.value || <BCTypography variant="body4">Select</BCTypography>,
cellStyle: (params) => StandardCellErrors(params, errors)
cellRenderer: (params) => {
return params.value ? params.value : <BCTypography variant="body4">Select</BCTypography>;
},
cellStyle: (params) => StandardCellErrors(params, errors),
editable: true,
minWidth: 100
},
{
field: 'ciOfFuel',
Expand Down

0 comments on commit 390f6f1

Please sign in to comment.