From 46ac729bff5928a085a454248e89ef40e5b0f6ef Mon Sep 17 00:00:00 2001 From: Jethary Date: Sun, 29 Sep 2024 11:20:31 -0400 Subject: [PATCH] select step on double click --- .../Timeline/ConnectedStepInfo.tsx | 7 ++++--- .../ProtocolSteps/Timeline/StepContainer.tsx | 8 +++++++- .../src/ui/steps/actions/actions.ts | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/ConnectedStepInfo.tsx b/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/ConnectedStepInfo.tsx index 545f2de0ff78..1a13e910c63f 100644 --- a/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/ConnectedStepInfo.tsx +++ b/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/ConnectedStepInfo.tsx @@ -60,6 +60,8 @@ export function ConnectedStepInfo(props: ConnectedStepInfoProps): JSX.Element { const selectStep = (): ThunkAction => dispatch(stepsActions.selectStep(stepId)) + const selectStepOnDoubleClick = (): ThunkAction => + dispatch(stepsActions.selectStepOnDoubleClick(stepId)) const highlightStep = (): HoverOnStepAction => dispatch(stepsActions.hoverOnStep(stepId)) const unhighlightStep = (): HoverOnStepAction => @@ -74,9 +76,8 @@ export function ConnectedStepInfo(props: ConnectedStepInfoProps): JSX.Element { stepId={stepId} onMouseLeave={unhighlightStep} selected={selected} - onClick={() => { - selectStep() - }} + onDoubleClick={selectStepOnDoubleClick} + onClick={selectStep} hovered={hoveredStep === stepId && !hoveredSubstep} onMouseEnter={highlightStep} iconName={hasError || hasWarnings ? 'alert-circle' : iconName} diff --git a/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/StepContainer.tsx b/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/StepContainer.tsx index 2b5bee633d92..a39ab1125623 100644 --- a/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/StepContainer.tsx +++ b/protocol-designer/src/pages/Designer/ProtocolSteps/Timeline/StepContainer.tsx @@ -1,5 +1,5 @@ import * as React from 'react' -import { useSelector } from 'react-redux' +import { useDispatch, useSelector } from 'react-redux' import { createPortal } from 'react-dom' import { ALIGN_CENTER, @@ -24,6 +24,8 @@ import { StepOverflowMenu } from './StepOverflowMenu' import { capitalizeFirstLetterAfterNumber } from './utils' import type { IconName } from '@opentrons/components' +import { cancelStepForm } from '../../../../steplist/actions' +import { ThunkDispatch } from '../../../../types' const STARTING_DECK_STATE = 'Starting deck state' const FINAL_DECK_STATE = 'Final deck state' @@ -34,6 +36,7 @@ export interface StepContainerProps { stepId?: string iconColor?: string onClick?: (event: React.MouseEvent) => void + onDoubleClick?: (event: React.MouseEvent) => void onMouseEnter?: (event: React.MouseEvent) => void onMouseLeave?: (event: React.MouseEvent) => void selected?: boolean @@ -46,6 +49,7 @@ export function StepContainer(props: StepContainerProps): JSX.Element { const { stepId, iconName, + onDoubleClick, onMouseEnter, onMouseLeave, selected, @@ -57,6 +61,7 @@ export function StepContainer(props: StepContainerProps): JSX.Element { isStepAfterError = false, } = props const formData = useSelector(getUnsavedForm) + const dispatch = useDispatch>() const [top, setTop] = React.useState(0) const menuRootRef = React.useRef(null) const [stepOverflowMenu, setStepOverflowMenu] = React.useState(false) @@ -121,6 +126,7 @@ export function StepContainer(props: StepContainerProps): JSX.Element { }} > => ( resetScrollElements() } +export const selectStepOnDoubleClick = ( + stepId: StepIdType +): ThunkAction => (dispatch: ThunkDispatch, getState: GetState) => { + const selectStepAction: SelectStepAction = { + type: 'SELECT_STEP', + payload: stepId, + } + dispatch(selectStepAction) + const state = getState() + const formData = { ...stepFormSelectors.getSavedStepForms(state)[stepId] } + dispatch({ + type: 'POPULATE_FORM', + payload: formData, + }) + resetScrollElements() +} + // NOTE(sa, 2020-12-11): this is a thunk so that we can populate the batch edit form with things later export const selectMultipleSteps = ( stepIds: StepIdType[],