-
Notifications
You must be signed in to change notification settings - Fork 178
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): foundation for batch edit and multi-select (#…
- Loading branch information
Showing
11 changed files
with
443 additions
and
31 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
protocol-designer/src/assets/localization/en/protocol_steps.json
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
3 changes: 3 additions & 0 deletions
3
protocol-designer/src/pages/Designer/ProtocolSteps/BatchEditToolbox/BatchEditMixTools.tsx
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,3 @@ | ||
export function BatchEditMixTools(): JSX.Element { | ||
return <div>Todo: wire this up</div> | ||
} |
3 changes: 3 additions & 0 deletions
3
...l-designer/src/pages/Designer/ProtocolSteps/BatchEditToolbox/BatchEditMoveLiquidTools.tsx
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,3 @@ | ||
export function BatchEditMoveLiquidTools(): JSX.Element { | ||
return <div>Todo: wire this up</div> | ||
} |
90 changes: 90 additions & 0 deletions
90
protocol-designer/src/pages/Designer/ProtocolSteps/BatchEditToolbox/index.tsx
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,90 @@ | ||
import { useTranslation } from 'react-i18next' | ||
import { useDispatch, useSelector } from 'react-redux' | ||
import { Icon, PrimaryButton, StyledText, Toolbox } from '@opentrons/components' | ||
import { | ||
getBatchEditSelectedStepTypes, | ||
getMultiSelectDisabledFields, | ||
getMultiSelectFieldValues, | ||
getMultiSelectItemIds, | ||
} from '../../../../ui/steps/selectors' | ||
import { useKitchen } from '../../../../organisms/Kitchen/hooks' | ||
import { deselectAllSteps } from '../../../../ui/steps/actions/actions' | ||
import { | ||
// changeBatchEditField, | ||
resetBatchEditFieldChanges, | ||
saveStepFormsMulti, | ||
} from '../../../../step-forms/actions' | ||
import { BatchEditMoveLiquidTools } from './BatchEditMoveLiquidTools' | ||
import { BatchEditMixTools } from './BatchEditMixTools' | ||
// import { maskField } from '../../../../steplist/fieldLevel' | ||
|
||
// import type { StepFieldName } from '../../../../steplist/fieldLevel' | ||
import type { ThunkDispatch } from 'redux-thunk' | ||
import type { BaseState } from '../../../../types' | ||
|
||
export const BatchEditToolbox = (): JSX.Element | null => { | ||
const { t } = useTranslation(['tooltip', 'protocol_steps', 'shared']) | ||
const { makeSnackbar } = useKitchen() | ||
const dispatch = useDispatch<ThunkDispatch<BaseState, any, any>>() | ||
const fieldValues = useSelector(getMultiSelectFieldValues) | ||
const stepTypes = useSelector(getBatchEditSelectedStepTypes) | ||
const disabledFields = useSelector(getMultiSelectDisabledFields) | ||
const selectedStepIds = useSelector(getMultiSelectItemIds) | ||
|
||
// const handleChangeFormInput = (name: StepFieldName, value: unknown): void => { | ||
// const maskedValue = maskField(name, value) | ||
// dispatch(changeBatchEditField({ [name]: maskedValue })) | ||
// } | ||
|
||
const handleSave = (): void => { | ||
dispatch(saveStepFormsMulti(selectedStepIds)) | ||
makeSnackbar(t('batch_edits_saved') as string) | ||
dispatch(deselectAllSteps('EXIT_BATCH_EDIT_MODE_BUTTON_PRESS')) | ||
} | ||
|
||
const handleCancel = (): void => { | ||
dispatch(resetBatchEditFieldChanges()) | ||
dispatch(deselectAllSteps('EXIT_BATCH_EDIT_MODE_BUTTON_PRESS')) | ||
} | ||
|
||
const stepType = stepTypes.length === 1 ? stepTypes[0] : null | ||
|
||
if (stepType !== null && fieldValues !== null && disabledFields !== null) { | ||
// const propsForFields = makeBatchEditFieldProps( | ||
// fieldValues, | ||
// disabledFields, | ||
// handleChangeFormInput, | ||
// t | ||
// ) | ||
if (stepType === 'moveLiquid' || stepType === 'mix') { | ||
return ( | ||
<Toolbox | ||
height="calc(100vh - 64px)" | ||
title={ | ||
<StyledText desktopStyle="bodyLargeSemiBold"> | ||
{t('protocol_steps:batch_edit')} | ||
</StyledText> | ||
} | ||
childrenPadding="0" | ||
onCloseClick={handleCancel} | ||
closeButton={<Icon size="2rem" name="close" />} | ||
confirmButton={ | ||
<PrimaryButton onClick={handleSave} width="100%"> | ||
{t('shared:save')} | ||
</PrimaryButton> | ||
} | ||
> | ||
{stepType === 'moveLiquid' ? ( | ||
<BatchEditMoveLiquidTools /> | ||
) : ( | ||
<BatchEditMixTools /> | ||
)} | ||
</Toolbox> | ||
) | ||
} else { | ||
return null | ||
} | ||
} else { | ||
return null | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
protocol-designer/src/pages/Designer/ProtocolSteps/BatchEditToolbox/utils.ts
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,48 @@ | ||
import noop from 'lodash/noop' | ||
import { | ||
getFieldDefaultTooltip, | ||
getFieldIndeterminateTooltip, | ||
} from '../StepForm/utils' | ||
import type { | ||
DisabledFields, | ||
MultiselectFieldValues, | ||
} from '../../../../ui/steps/selectors' | ||
import type { StepFieldName } from '../../../../form-types' | ||
import type { FieldPropsByName } from '../StepForm/types' | ||
export const makeBatchEditFieldProps = ( | ||
fieldValues: MultiselectFieldValues, | ||
disabledFields: DisabledFields, | ||
handleChangeFormInput: (name: string, value: unknown) => void, | ||
t: any | ||
): FieldPropsByName => { | ||
const fieldNames: StepFieldName[] = Object.keys(fieldValues) | ||
return fieldNames.reduce<FieldPropsByName>((acc, name) => { | ||
const defaultTooltip = getFieldDefaultTooltip(name, t) | ||
const isIndeterminate = fieldValues[name].isIndeterminate | ||
const indeterminateTooltip = getFieldIndeterminateTooltip(name, t) | ||
let tooltipContent = defaultTooltip // Default to the default content (or blank) | ||
|
||
if (isIndeterminate && indeterminateTooltip) { | ||
tooltipContent = indeterminateTooltip | ||
} | ||
|
||
if (name in disabledFields) { | ||
tooltipContent = disabledFields[name] // Use disabled content if field is disabled, override indeterminate tooltip if applicable | ||
} | ||
|
||
acc[name] = { | ||
disabled: name in disabledFields, | ||
name, | ||
updateValue: value => { | ||
handleChangeFormInput(name, value) | ||
}, | ||
value: fieldValues[name].value, | ||
errorToShow: null, | ||
onFieldBlur: noop, | ||
onFieldFocus: noop, | ||
isIndeterminate: isIndeterminate, | ||
tooltipContent: tooltipContent, | ||
} | ||
return acc | ||
}, {}) | ||
} |
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.