-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(protocol-designer): add modal to add a pause after set temp (#5182)
Closes #5117 * refactor add/select step selectors for mocking, and add tests
- Loading branch information
Showing
17 changed files
with
803 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 73 additions & 35 deletions
108
protocol-designer/src/components/StepEditForm/ButtonRow/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,99 @@ | ||
// @flow | ||
import React from 'react' | ||
import React, { useCallback, useState } from 'react' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import cx from 'classnames' | ||
import { OutlineButton, PrimaryButton } from '@opentrons/components' | ||
|
||
import { AutoAddPauseUntilTempStepModal } from '../../modals/AutoAddPauseUntilTempStepModal' | ||
import { actions as steplistActions } from '../../../steplist' | ||
import { actions as stepFormActions } from '../../../step-forms' | ||
import { actions as stepsActions } from '../../../ui/steps' | ||
|
||
import { getCurrentFormCanBeSaved } from '../../../step-forms/selectors' | ||
import { | ||
getCurrentFormCanBeSaved, | ||
getUnsavedForm, | ||
getUnsavedFormIsPristineSetTempForm, | ||
} from '../../../step-forms/selectors' | ||
|
||
import type { BaseState } from '../../../types' | ||
|
||
import modalStyles from '../../modals/modal.css' | ||
import styles from './styles.css' | ||
|
||
const { cancelStepForm } = steplistActions | ||
const { saveStepForm } = stepFormActions | ||
|
||
type Props = {| | ||
onClickMoreOptions: (event: SyntheticEvent<>) => mixed, | ||
onDelete?: (event: SyntheticEvent<>) => mixed, | ||
|} | ||
|
||
export const ButtonRow = ({ onDelete, onClickMoreOptions }: Props) => { | ||
const [ | ||
showAddPauseUntilTempStepModal, | ||
setShowAddPauseUntilTempStepModal, | ||
] = useState<boolean>(false) | ||
|
||
const dispatch = useDispatch() | ||
const canSave = useSelector((state: BaseState): boolean => | ||
getCurrentFormCanBeSaved(state) | ||
) | ||
const dispatch = useDispatch() | ||
const unsavedForm = useSelector(getUnsavedForm) | ||
const shouldShowPauseUntilTempStepModal = useSelector( | ||
getUnsavedFormIsPristineSetTempForm | ||
) | ||
|
||
const handleClickSave = useCallback(() => { | ||
if (!canSave) { | ||
return | ||
} | ||
if (shouldShowPauseUntilTempStepModal) { | ||
setShowAddPauseUntilTempStepModal(true) | ||
} else { | ||
dispatch(stepsActions.saveStepForm()) | ||
} | ||
}, [canSave, shouldShowPauseUntilTempStepModal, dispatch]) | ||
|
||
return ( | ||
<div className={cx(modalStyles.button_row_divided, styles.form_wrapper)}> | ||
<div> | ||
<OutlineButton className={styles.form_button} onClick={onDelete}> | ||
Delete | ||
</OutlineButton> | ||
<OutlineButton | ||
className={styles.form_button} | ||
onClick={onClickMoreOptions} | ||
> | ||
Notes | ||
</OutlineButton> | ||
</div> | ||
<div> | ||
<PrimaryButton | ||
className={styles.form_button} | ||
onClick={() => dispatch(cancelStepForm())} | ||
> | ||
Close | ||
</PrimaryButton> | ||
<PrimaryButton | ||
className={styles.form_button} | ||
disabled={!canSave} | ||
onClick={canSave ? () => dispatch(saveStepForm()) : undefined} | ||
> | ||
Save | ||
</PrimaryButton> | ||
<> | ||
{showAddPauseUntilTempStepModal && ( | ||
<AutoAddPauseUntilTempStepModal | ||
displayTemperature={unsavedForm?.targetTemperature ?? '?'} | ||
handleCancelClick={() => { | ||
setShowAddPauseUntilTempStepModal(false) | ||
// save normally | ||
dispatch(stepsActions.saveStepForm()) | ||
}} | ||
handleContinueClick={() => { | ||
setShowAddPauseUntilTempStepModal(false) | ||
// save this form and add a subsequent pause | ||
dispatch(stepsActions.saveSetTempFormWithAddedPauseUntilTemp()) | ||
}} | ||
/> | ||
)} | ||
<div className={cx(modalStyles.button_row_divided, styles.form_wrapper)}> | ||
<div> | ||
<OutlineButton className={styles.form_button} onClick={onDelete}> | ||
Delete | ||
</OutlineButton> | ||
<OutlineButton | ||
className={styles.form_button} | ||
onClick={onClickMoreOptions} | ||
> | ||
Notes | ||
</OutlineButton> | ||
</div> | ||
<div> | ||
<PrimaryButton | ||
className={styles.form_button} | ||
onClick={() => dispatch(steplistActions.cancelStepForm())} | ||
> | ||
Close | ||
</PrimaryButton> | ||
<PrimaryButton | ||
className={styles.form_button} | ||
disabled={!canSave} | ||
onClick={handleClickSave} | ||
> | ||
Save | ||
</PrimaryButton> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
protocol-designer/src/components/modals/AutoAddPauseUntilTempStepModal.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
@import '@opentrons/components'; | ||
|
||
.header { | ||
@apply --font-header-dark; | ||
|
||
margin-bottom: 1rem; | ||
} | ||
|
||
.body { | ||
@apply --font-body-2-dark; | ||
} | ||
|
||
.later_button { | ||
width: 16rem; | ||
} | ||
|
||
.now_button { | ||
width: 15rem; | ||
margin-left: 1rem; | ||
} |
44 changes: 44 additions & 0 deletions
44
protocol-designer/src/components/modals/AutoAddPauseUntilTempStepModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// @flow | ||
import React from 'react' | ||
import { AlertModal, OutlineButton, PrimaryButton } from '@opentrons/components' | ||
import { i18n } from '../../localization' | ||
import modalStyles from './modal.css' | ||
import styles from './AutoAddPauseUntilTempStepModal.css' | ||
|
||
type Props = {| | ||
displayTemperature: string, | ||
handleCancelClick: () => mixed, | ||
handleContinueClick: () => mixed, | ||
|} | ||
|
||
export const AutoAddPauseUntilTempStepModal = (props: Props) => ( | ||
<AlertModal | ||
className={modalStyles.modal} | ||
contentsClassName={modalStyles.modal_contents} | ||
> | ||
<div className={styles.header}> | ||
{i18n.t('modal.auto_add_pause_until_temp_step.title', { | ||
temperature: props.displayTemperature, | ||
})} | ||
</div> | ||
<p className={styles.body}> | ||
{i18n.t('modal.auto_add_pause_until_temp_step.body', { | ||
temperature: props.displayTemperature, | ||
})} | ||
</p> | ||
<div className={modalStyles.button_row}> | ||
<OutlineButton | ||
className={styles.later_button} | ||
onClick={props.handleCancelClick} | ||
> | ||
{i18n.t('modal.auto_add_pause_until_temp_step.later_button')} | ||
</OutlineButton> | ||
<PrimaryButton | ||
className={styles.now_button} | ||
onClick={props.handleContinueClick} | ||
> | ||
{i18n.t('modal.auto_add_pause_until_temp_step.now_button')} | ||
</PrimaryButton> | ||
</div> | ||
</AlertModal> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,3 @@ | ||
// @flow | ||
import { getUnsavedForm } from '../selectors' | ||
import type { Dispatch } from 'redux' | ||
import type { StepIdType } from '../../form-types' | ||
import type { GetState } from '../../types' | ||
|
||
export * from './modules' | ||
export * from './pipettes' | ||
|
||
export const SAVE_STEP_FORM: 'SAVE_STEP_FORM' = 'SAVE_STEP_FORM' | ||
|
||
export type SaveStepFormAction = {| | ||
type: typeof SAVE_STEP_FORM, | ||
payload: { id: StepIdType }, | ||
|} | ||
|
||
export const saveStepForm = () => (dispatch: Dispatch<*>, getState: GetState) => | ||
dispatch({ type: SAVE_STEP_FORM, payload: getUnsavedForm(getState()) }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.