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

Store incomplete rows in drafts #3960

Merged
merged 3 commits into from
Sep 24, 2024
Merged
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
22 changes: 11 additions & 11 deletions web/src/features/moreCast2/components/TabbedDataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,17 @@
/********** 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)

Check warning on line 347 in web/src/features/moreCast2/components/TabbedDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

web/src/features/moreCast2/components/TabbedDataGrid.tsx#L347

Added line #L347 was not covered by tests
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)

Check warning on line 355 in web/src/features/moreCast2/components/TabbedDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

web/src/features/moreCast2/components/TabbedDataGrid.tsx#L354-L355

Added lines #L354 - L355 were not covered by tests
newRows = newRows.map(newRow => draftRows.find(row => row.id === newRow.id) || newRow)
setAllRows(newRows)
}

Expand Down Expand Up @@ -496,13 +494,15 @@

// 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)

Check warning on line 497 in web/src/features/moreCast2/components/TabbedDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

web/src/features/moreCast2/components/TabbedDataGrid.tsx#L497

Added line #L497 was not covered by tests
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)
dgboss marked this conversation as resolved.
Show resolved Hide resolved
storedDraftForecast.updateStoredDraftForecasts(filledRows, getDateTimeNowPST())

Check warning on line 502 in web/src/features/moreCast2/components/TabbedDataGrid.tsx

View check run for this annotation

Codecov / codecov/patch

web/src/features/moreCast2/components/TabbedDataGrid.tsx#L502

Added line #L502 was not covered by tests
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
}
Expand Down
Loading