From 817518c32f10f0251e457d77576310de7ad3585c Mon Sep 17 00:00:00 2001 From: dgboss Date: Tue, 24 Sep 2024 16:03:41 -0700 Subject: [PATCH] Store incomplete rows in drafts (#3960) --- .../moreCast2/components/TabbedDataGrid.tsx | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) 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 }