Skip to content

Commit b032c4a

Browse files
authored
fix(protocol-designer): retain timeline data when overwriting protocol via import (#17476)
closes AUTH-1429
1 parent e734350 commit b032c4a

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

protocol-designer/src/configureStore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ export function configureStore(): StoreType {
8989
/* preloadedState, */
9090
composeEnhancers(
9191
applyMiddleware(
92-
thunk,
9392
timelineMiddleware as Middleware<BaseState, Record<string, any>, any>,
93+
thunk,
9494
trackEventMiddleware as Middleware<BaseState, Record<string, any>, any>
9595
)
9696
) as StoreEnhancer<unknown, unknown>

protocol-designer/src/timelineMiddleware/makeTimelineMiddleware.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { getLabwareNamesByModuleId } from '../ui/modules/selectors'
1313
import type { ComputeRobotStateTimelineSuccessAction } from '../file-data/actions'
1414
import type { Middleware } from 'redux'
15-
import type { BaseState } from '../types'
15+
import type { Action, BaseState } from '../types'
1616
import type { GenerateRobotStateTimelineArgs } from './generateRobotStateTimeline'
1717
import type { SubstepsArgsNoTimeline, WorkerResponse } from './types'
1818

@@ -51,7 +51,10 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
5151
let prevSubstepsArgs: SubstepsArgsNoTimeline | null = null
5252
let prevSuccessAction: ComputeRobotStateTimelineSuccessAction | null = null
5353

54-
const timelineNeedsRecompute = (state: BaseState): boolean => {
54+
const timelineNeedsRecompute = (
55+
state: BaseState,
56+
actionType: string
57+
): boolean => {
5558
const nextSelectorResults = getTimelineArgs(state)
5659

5760
if (prevTimelineArgs === null) {
@@ -63,10 +66,13 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
6366
const needsRecompute = hasChanged(nextSelectorResults, prevTimelineArgs)
6467
// update memoized values
6568
prevTimelineArgs = nextSelectorResults
66-
return needsRecompute
69+
return needsRecompute || actionType === 'LOAD_FILE'
6770
}
6871

69-
const substepsNeedsRecompute = (state: BaseState): boolean => {
72+
const substepsNeedsRecompute = (
73+
state: BaseState,
74+
actionType: string
75+
): boolean => {
7076
if (prevSubstepsArgs === null) {
7177
// initial call, must populate memoized value
7278
prevSubstepsArgs = getSubstepsArgs(state)
@@ -80,18 +86,20 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
8086
)
8187
prevSubstepsArgs = nextSubstepSelectorResults // update memoized value
8288

83-
return needsRecompute
89+
return needsRecompute || actionType === 'LOAD_FILE'
8490
}
8591

86-
return ({ getState, dispatch }) => next => action => {
92+
return ({ getState, dispatch }) => next => (action: Action) => {
8793
// call the next dispatch method in the middleware chain
8894
const returnValue = next(action)
8995
const nextState = getState()
9096
const shouldRecomputeTimeline = timelineNeedsRecompute(
91-
nextState as BaseState
97+
nextState as BaseState,
98+
action.type
9299
)
93100
const shouldRecomputeSubsteps = substepsNeedsRecompute(
94-
nextState as BaseState
101+
nextState as BaseState,
102+
action.type
95103
)
96104

97105
// TODO: how to stop re-assigning this event handler every middleware call? We need

0 commit comments

Comments
 (0)