diff --git a/web/src/features/fbaCalculator/slices/fbaCalculatorSlice.ts b/web/src/features/fbaCalculator/slices/fbaCalculatorSlice.ts index bfa19f65d..185c64967 100644 --- a/web/src/features/fbaCalculator/slices/fbaCalculatorSlice.ts +++ b/web/src/features/fbaCalculator/slices/fbaCalculatorSlice.ts @@ -4,7 +4,7 @@ import { FBAStation, FBAWeatherStationsResponse, postFBAStations } from 'api/fba import { AppThunk } from 'app/store' import { logError } from 'utils/error' import { FuelTypes } from '../fuelTypes' -import { isEmpty, isEqual, isNull, isUndefined } from 'lodash' +import { isEmpty, isNil } from 'lodash' import { FBATableRow } from 'features/fbaCalculator/RowManager' import { DateTime } from 'luxon' import { PST_UTC_OFFSET } from 'utils/constants' @@ -60,12 +60,7 @@ export const fetchFireBehaviourStations = async dispatch => { const fetchableFireStations = fbcInputRows.flatMap(row => { const fuelTypeDetails = FuelTypes.lookup(row.fuelType?.value) - if ( - isNull(fuelTypeDetails) || - isUndefined(fuelTypeDetails) || - isUndefined(row.weatherStation) || - isEqual(row.weatherStation, 'undefined') - ) { + if (isNil(fuelTypeDetails) || isNil(row.weatherStation)) { return [] } return { diff --git a/web/src/features/moreCast2/components/TabbedDataGrid.tsx b/web/src/features/moreCast2/components/TabbedDataGrid.tsx index adb45023d..c1943aa3c 100644 --- a/web/src/features/moreCast2/components/TabbedDataGrid.tsx +++ b/web/src/features/moreCast2/components/TabbedDataGrid.tsx @@ -343,19 +343,17 @@ const TabbedDataGrid = ({ fromTo, setFromTo, fetchWeatherIndeterminates }: Tabbe /********** End useEffects for managing visibility of column groups *************/ const updateColumnHelper = (editedRows: MoreCast2Row[]) => { - // Create a copy of all Morecast2ForecastRows - let newRows = cloneDeep(allRows) - newRows = newRows.map(newRow => editedRows.find(row => row.id === newRow.id) || newRow) - + // Create a copy of editedRows which will be stored as a draft + let draftRows = cloneDeep(editedRows) const rowsForSimulation = filterAllVisibleRowsForSimulation(editedRows) ?? [] if (rowsForSimulation.length > 0) { const filteredRowsWithIndices = simulateFireWeatherIndices(rowsForSimulation) - storedDraftForecast.updateStoredDraftForecasts(filteredRowsWithIndices, getDateTimeNowPST()) - // Merge the copy of allRows with rows that were updated with simulated indices - newRows = newRows.map(newRow => filteredRowsWithIndices.find(row => row.id === newRow.id) || newRow) + draftRows = draftRows.map(newRow => filteredRowsWithIndices.find(row => row.id === newRow.id) || newRow) } - + storedDraftForecast.updateStoredDraftForecasts(draftRows, getDateTimeNowPST()) + let newRows = cloneDeep(allRows) + newRows = newRows.map(newRow => draftRows.find(row => row.id === newRow.id) || newRow) setAllRows(newRows) } @@ -496,13 +494,15 @@ const TabbedDataGrid = ({ fromTo, setFromTo, fetchWeatherIndeterminates }: Tabbe // Handler passed to our datagrids that runs after a row is updated. const processRowUpdate = (newRow: MoreCast2Row) => { - const filledRows = fillStationGrassCuringForward(newRow, allRows) + let filledRows = fillStationGrassCuringForward(newRow, allRows) const filteredRows = filterRowsForSimulationFromEdited(newRow, filledRows) const filteredRowsWithIndices = simulateFireWeatherIndices(filteredRows) - storedDraftForecast.updateStoredDraftForecasts(filteredRowsWithIndices, getDateTimeNowPST()) + // Merge rows that have been updated (ie. filledRows) with rows that have had indices added and save as a draft + filledRows = filledRows.map(filledRow => filteredRowsWithIndices.find(row => row.id === filledRow.id) || filledRow) + storedDraftForecast.updateStoredDraftForecasts(filledRows, getDateTimeNowPST()) let newRows = cloneDeep(allRows) // Merge the copy of existing rows with rows that were updated with simulated indices - newRows = newRows.map(newRow => filteredRowsWithIndices.find(row => row.id === newRow.id) || newRow) + newRows = newRows.map(newRow => filledRows.find(row => row.id === newRow.id) || newRow) setAllRows(newRows) return newRow }