From f206da78df98efe082b5103ec23632af25f93264 Mon Sep 17 00:00:00 2001 From: Shlok Amin Date: Fri, 7 Feb 2025 16:43:37 -0500 Subject: [PATCH 1/2] fix(protocol-designer): retain timeline data when overwriting protocol via import closes AUTH-1429 --- protocol-designer/src/configureStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/protocol-designer/src/configureStore.ts b/protocol-designer/src/configureStore.ts index 9f049628c0a..aa77d4368f1 100644 --- a/protocol-designer/src/configureStore.ts +++ b/protocol-designer/src/configureStore.ts @@ -89,8 +89,8 @@ export function configureStore(): StoreType { /* preloadedState, */ composeEnhancers( applyMiddleware( - thunk, timelineMiddleware as Middleware, any>, + thunk, trackEventMiddleware as Middleware, any> ) ) as StoreEnhancer From 90098fdef44ca62c7df46c7a908444ea6c412459 Mon Sep 17 00:00:00 2001 From: Shlok Amin Date: Mon, 10 Feb 2025 10:34:58 -0500 Subject: [PATCH 2/2] recompute timeline and substeps whenever importing a protocol --- .../makeTimelineMiddleware.ts | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/protocol-designer/src/timelineMiddleware/makeTimelineMiddleware.ts b/protocol-designer/src/timelineMiddleware/makeTimelineMiddleware.ts index 2d992b50921..3dd7272607c 100644 --- a/protocol-designer/src/timelineMiddleware/makeTimelineMiddleware.ts +++ b/protocol-designer/src/timelineMiddleware/makeTimelineMiddleware.ts @@ -12,7 +12,7 @@ import { import { getLabwareNamesByModuleId } from '../ui/modules/selectors' import type { ComputeRobotStateTimelineSuccessAction } from '../file-data/actions' import type { Middleware } from 'redux' -import type { BaseState } from '../types' +import type { Action, BaseState } from '../types' import type { GenerateRobotStateTimelineArgs } from './generateRobotStateTimeline' import type { SubstepsArgsNoTimeline, WorkerResponse } from './types' @@ -51,7 +51,10 @@ export const makeTimelineMiddleware: () => Middleware = () => { let prevSubstepsArgs: SubstepsArgsNoTimeline | null = null let prevSuccessAction: ComputeRobotStateTimelineSuccessAction | null = null - const timelineNeedsRecompute = (state: BaseState): boolean => { + const timelineNeedsRecompute = ( + state: BaseState, + actionType: string + ): boolean => { const nextSelectorResults = getTimelineArgs(state) if (prevTimelineArgs === null) { @@ -63,10 +66,13 @@ export const makeTimelineMiddleware: () => Middleware = () => { const needsRecompute = hasChanged(nextSelectorResults, prevTimelineArgs) // update memoized values prevTimelineArgs = nextSelectorResults - return needsRecompute + return needsRecompute || actionType === 'LOAD_FILE' } - const substepsNeedsRecompute = (state: BaseState): boolean => { + const substepsNeedsRecompute = ( + state: BaseState, + actionType: string + ): boolean => { if (prevSubstepsArgs === null) { // initial call, must populate memoized value prevSubstepsArgs = getSubstepsArgs(state) @@ -80,18 +86,20 @@ export const makeTimelineMiddleware: () => Middleware = () => { ) prevSubstepsArgs = nextSubstepSelectorResults // update memoized value - return needsRecompute + return needsRecompute || actionType === 'LOAD_FILE' } - return ({ getState, dispatch }) => next => action => { + return ({ getState, dispatch }) => next => (action: Action) => { // call the next dispatch method in the middleware chain const returnValue = next(action) const nextState = getState() const shouldRecomputeTimeline = timelineNeedsRecompute( - nextState as BaseState + nextState as BaseState, + action.type ) const shouldRecomputeSubsteps = substepsNeedsRecompute( - nextState as BaseState + nextState as BaseState, + action.type ) // TODO: how to stop re-assigning this event handler every middleware call? We need