Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Prevent copying 'kWh usage' field in duplicate row function - #1279 #1352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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