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

fix(protocol-designer): retain timeline data when overwriting protocol via import #17476

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion protocol-designer/src/configureStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ export function configureStore(): StoreType {
/* preloadedState, */
composeEnhancers(
applyMiddleware(
thunk,
timelineMiddleware as Middleware<BaseState, Record<string, any>, any>,
thunk,
trackEventMiddleware as Middleware<BaseState, Record<string, any>, any>
)
) as StoreEnhancer<unknown, unknown>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -51,7 +51,10 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
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) {
Expand All @@ -63,10 +66,13 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
const needsRecompute = hasChanged(nextSelectorResults, prevTimelineArgs)
// update memoized values
prevTimelineArgs = nextSelectorResults
return needsRecompute
return needsRecompute || actionType === 'LOAD_FILE'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to explicitly recompute when you load a file now? previously, did hasChanged() return true when you upload a file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wait, seeing your comments, i guess this was always broken??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it returns true when you upload a new file. this is because the protocol actually contains different information. if you upload the same exact protocol the timeline does not get recomputed. the problem though is that the load file action wipes out timeline data, so you're left with a step forms but no timeline

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its crazy to me that we never noticed this before. i guess its not common for someone to reimport the same protocol that is currently loaded

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know right lol

}

const substepsNeedsRecompute = (state: BaseState): boolean => {
const substepsNeedsRecompute = (
state: BaseState,
actionType: string
): boolean => {
if (prevSubstepsArgs === null) {
// initial call, must populate memoized value
prevSubstepsArgs = getSubstepsArgs(state)
Expand All @@ -80,18 +86,20 @@ export const makeTimelineMiddleware: () => Middleware<BaseState, any> = () => {
)
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
Expand Down
Loading