Skip to content

Commit

Permalink
Merge branch 'main' into task/mc-validation-tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
brettedw authored Sep 24, 2024
2 parents 06e148a + 817518c commit c3c42fa
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
9 changes: 2 additions & 7 deletions web/src/features/fbaCalculator/slices/fbaCalculatorSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
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 @@ 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)
}

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c3c42fa

Please sign in to comment.