Skip to content

Commit

Permalink
Merge pull request #1352 from bcgov/feat/hamed-remove-kwh-duplicate-1279
Browse files Browse the repository at this point in the history
Feat: Prevent copying 'kWh usage' field in duplicate row function - #1279
  • Loading branch information
hamed-valiollahi authored Dec 4, 2024
2 parents 07139c3 + f064aa3 commit 3a7474c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion backend/lcfs/web/api/final_supply_equipment/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class FinalSupplyEquipmentCreateSchema(BaseSchema):
compliance_report_id: Optional[int] = None
supply_from_date: date
supply_to_date: date
kwh_usage: Optional[float] = None
kwh_usage: float
serial_nbr: str
manufacturer: str
model: Optional[str] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ export const AddEditFinalSupplyEquipments = () => {
if (fields[0] === 'postalCode') {
errMsg = t('finalSupplyEquipment:postalCodeError')
} else {
errMsg = `Error updating row: ${fieldLabels.length === 1 ? fieldLabels[0] : ''
} ${String(message).toLowerCase()}`
errMsg = `Error updating row: ${
fieldLabels.length === 1 ? fieldLabels[0] : ''
} ${String(message).toLowerCase()}`
}
} else {
errMsg = error.response.data?.detail
Expand Down Expand Up @@ -206,6 +207,7 @@ export const AddEditFinalSupplyEquipments = () => {
const rowData = {
...params.node.data,
id: newRowID,
kwhUsage: null,
serialNbr: null,
latitude: null,
longitude: null,
Expand Down Expand Up @@ -239,16 +241,21 @@ export const AddEditFinalSupplyEquipments = () => {
)
}, [navigate, compliancePeriod, complianceReportId])

const onAddRows = useCallback((numRows) => {
return Array(numRows).fill().map(() => ({
id: uuid(),
complianceReportId,
supplyFromDate: `${compliancePeriod}-01-01`,
supplyToDate: `${compliancePeriod}-12-31`,
validationStatus: 'error',
modified: true
}))
}, [compliancePeriod, complianceReportId])
const onAddRows = useCallback(
(numRows) => {
return Array(numRows)
.fill()
.map(() => ({
id: uuid(),
complianceReportId,
supplyFromDate: `${compliancePeriod}-01-01`,
supplyToDate: `${compliancePeriod}-12-31`,
validationStatus: 'error',
modified: true
}))
},
[compliancePeriod, complianceReportId]
)

return (
isFetched &&
Expand Down
27 changes: 13 additions & 14 deletions frontend/src/views/FinalSupplyEquipments/_schema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import { CommonArrayRenderer } from '@/utils/grid/cellRenderers'
import { StandardCellErrors } from '@/utils/grid/errorRenderers'
import { apiRoutes } from '@/constants/routes'

export const finalSupplyEquipmentColDefs = (
optionsData,
compliancePeriod,
errors
) => [
export const finalSupplyEquipmentColDefs = (optionsData, compliancePeriod, errors) => [
validation,
actions({
enableDuplicate: true,
Expand Down Expand Up @@ -75,6 +71,7 @@ export const finalSupplyEquipmentColDefs = (
},
{
field: 'kwhUsage',
headerComponent: RequiredHeader,
headerName: i18n.t(
'finalSupplyEquipment:finalSupplyEquipmentColLabels.kwhUsage'
),
Expand All @@ -83,9 +80,9 @@ export const finalSupplyEquipmentColDefs = (
cellDataType: 'text',
cellStyle: (params) => StandardCellErrors(params, errors),
valueFormatter: (params) => {
const value = parseFloat(params.value);
return !isNaN(value) ? value.toFixed(2) : '';
},
const value = parseFloat(params.value)
return !isNaN(value) ? value.toFixed(2) : ''
}
},
{
field: 'serialNbr',
Expand All @@ -110,13 +107,15 @@ export const finalSupplyEquipmentColDefs = (
queryKey: 'fuel-code-search',
queryFn: async ({ client, queryKey }) => {
try {
const [, searchTerm] = queryKey;
const path = `${apiRoutes.searchFinalSupplyEquipments}manufacturer=${encodeURIComponent(searchTerm)}`;
const response = await client.get(path);
return response.data;
const [, searchTerm] = queryKey
const path = `${
apiRoutes.searchFinalSupplyEquipments
}manufacturer=${encodeURIComponent(searchTerm)}`
const response = await client.get(path)
return response.data
} catch (error) {
console.error('Error fetching manufacturer data:', error);
return [];
console.error('Error fetching manufacturer data:', error)
return []
}
},
optionLabel: 'manufacturer',
Expand Down

0 comments on commit 3a7474c

Please sign in to comment.