-
Notifications
You must be signed in to change notification settings - Fork 175
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
refactor(app): add and use deck map component in interventionmodal #15570
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ecd3295
fix a logic error that prevented recovery from running
sfoster1 340dc82
refactor(app): separate StandIn story util
sfoster1 ef2cde7
feat(app): add DeckMapContent
sfoster1 7b2d00b
and after all, why not? it's mine, isn't it?
sfoster1 eb1b5d5
refactor: use intervention map in drop tip wizard
sfoster1 f11485d
refactor: use deckmap in error recovery
sfoster1 c060b23
fix up remaining tests
sfoster1 ea5c4be
fix up some render issues
sfoster1 67a36a8
docs page: allow non-specified onSelect
sfoster1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
157 changes: 157 additions & 0 deletions
157
app/src/molecules/InterventionModal/DeckMapContent.stories.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,157 @@ | ||
import * as React from 'react' | ||
|
||
import { css } from 'styled-components' | ||
import { DeckMapContent } from '.' | ||
import { Box, RESPONSIVENESS, BORDERS } from '@opentrons/components' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { | ||
FLEX_ROBOT_TYPE, | ||
OT2_ROBOT_TYPE, | ||
fixture96Plate, | ||
fixtureTiprack1000ul, | ||
HEATERSHAKER_MODULE_V1, | ||
MAGNETIC_BLOCK_V1, | ||
TEMPERATURE_MODULE_V2, | ||
THERMOCYCLER_MODULE_V2, | ||
} from '@opentrons/shared-data' | ||
import type { ModuleLocation, LabwareDefinition2 } from '@opentrons/shared-data' | ||
import { | ||
EXTENDED_DECK_CONFIG_FIXTURE, | ||
STANDARD_SLOT_DECK_CONFIG_FIXTURE, | ||
WASTE_CHUTE_DECK_CONFIG_FIXTURE, | ||
} from './__fixtures__' | ||
import { TwoColumn } from './TwoColumn' | ||
import { StandInContent } from './story-utils/StandIn' | ||
|
||
const DEFAULT_MODULES_ON_DECK = [ | ||
{ | ||
moduleLocation: { slotName: 'B1' }, | ||
moduleModel: THERMOCYCLER_MODULE_V2, | ||
nestedLabwareDef: fixture96Plate as LabwareDefinition2, | ||
innerProps: { lidMotorState: 'open' }, | ||
}, | ||
{ | ||
moduleLocation: { slotName: 'D1' }, | ||
moduleModel: TEMPERATURE_MODULE_V2, | ||
nestedLabwareDef: fixture96Plate as LabwareDefinition2, | ||
}, | ||
{ | ||
moduleLocation: { slotName: 'B3' }, | ||
moduleModel: HEATERSHAKER_MODULE_V1, | ||
nestedLabwareDef: fixture96Plate as LabwareDefinition2, | ||
}, | ||
{ | ||
moduleLocation: { slotName: 'D2' }, | ||
moduleModel: MAGNETIC_BLOCK_V1, | ||
nestedLabwareDef: fixture96Plate as LabwareDefinition2, | ||
}, | ||
] | ||
|
||
const DEFAULT_LABWARE_ON_DECK = [ | ||
{ | ||
labwareLocation: { slotName: 'C2' }, | ||
definition: fixture96Plate as LabwareDefinition2, | ||
}, | ||
{ | ||
labwareLocation: { slotName: 'C3' }, | ||
definition: fixtureTiprack1000ul as LabwareDefinition2, | ||
}, | ||
] | ||
|
||
const CONSOLE_LOG_ON_SELECT = (location: ModuleLocation): void => { | ||
console.log(`selected location is ${location?.slotName}`) | ||
} | ||
|
||
const meta: Meta<React.ComponentProps<typeof DeckMapContent>> = { | ||
title: 'App/Molecules/InterventionModal/DeckMapContent', | ||
component: DeckMapContent, | ||
argTypes: { | ||
robotType: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: [OT2_ROBOT_TYPE, FLEX_ROBOT_TYPE], | ||
default: FLEX_ROBOT_TYPE, | ||
}, | ||
kind: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: ['intervention', 'deck-config'], | ||
}, | ||
setSelectedLocation: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: ['print-to-console'], | ||
mapping: { | ||
'print-to-console': CONSOLE_LOG_ON_SELECT, | ||
}, | ||
if: { arg: 'kind', eq: 'deck-config' }, | ||
}, | ||
deckConfig: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: ['staging-area', 'waste-chute', 'standard'], | ||
mapping: { | ||
'staging-area': EXTENDED_DECK_CONFIG_FIXTURE, | ||
'waste-chute': WASTE_CHUTE_DECK_CONFIG_FIXTURE, | ||
standard: STANDARD_SLOT_DECK_CONFIG_FIXTURE, | ||
}, | ||
if: { arg: 'kind', eq: 'intervention' }, | ||
}, | ||
labwareOnDeck: { | ||
if: { arg: 'kind', eq: 'intervention' }, | ||
}, | ||
modulesOnDeck: { | ||
if: { arg: 'kind', eq: 'intervention' }, | ||
}, | ||
highlightLabwareEventuallyIn: { | ||
if: { arg: 'kind', eq: 'intervention' }, | ||
}, | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<Box | ||
css={css` | ||
border: 4px solid #000000; | ||
border-radius: ${BORDERS.borderRadius8}; | ||
max-width: 47rem; | ||
@media ${RESPONSIVENESS.touchscreenMediaQuerySpecs} { | ||
max-width: 62rem; | ||
max-height: 33.5rem; | ||
} | ||
`} | ||
> | ||
<TwoColumn> | ||
<StandInContent /> | ||
<Story /> | ||
</TwoColumn> | ||
</Box> | ||
), | ||
], | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof DeckMapContent> | ||
|
||
export const InterventionMap: Story = { | ||
args: { | ||
kind: 'intervention', | ||
robotType: FLEX_ROBOT_TYPE, | ||
deckConfig: EXTENDED_DECK_CONFIG_FIXTURE, | ||
labwareOnDeck: DEFAULT_LABWARE_ON_DECK, | ||
modulesOnDeck: DEFAULT_MODULES_ON_DECK, | ||
highlightLabwareEventuallyIn: ['thermocyclerModuleV2', 'C3'], | ||
}, | ||
} | ||
|
||
export const DeckConfigMap: Story = { | ||
args: { | ||
kind: 'deck-config', | ||
robotType: FLEX_ROBOT_TYPE, | ||
setSelectedLocation: CONSOLE_LOG_ON_SELECT, | ||
}, | ||
} |
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,176 @@ | ||
import * as React from 'react' | ||
import { css } from 'styled-components' | ||
import { | ||
Box, | ||
BaseDeck, | ||
RobotCoordsForeignDiv, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
DISPLAY_FLEX, | ||
JUSTIFY_FLEX_END, | ||
useDeckLocationSelect, | ||
} from '@opentrons/components' | ||
|
||
import type { | ||
LabwareDefinition2, | ||
RobotType, | ||
ModuleLocation, | ||
LabwareLocation, | ||
} from '@opentrons/shared-data' | ||
|
||
export type MapKind = 'intervention' | 'deck-config' | ||
|
||
export interface InterventionStyleDeckMapContentProps | ||
extends Pick< | ||
React.ComponentProps<typeof BaseDeck>, | ||
'deckConfig' | 'robotType' | 'labwareOnDeck' | 'modulesOnDeck' | ||
> { | ||
kind: 'intervention' | ||
highlightLabwareEventuallyIn: string[] | ||
} | ||
|
||
export interface DeckConfigStyleDeckMapContentProps { | ||
kind: 'deck-config' | ||
robotType: RobotType | ||
setSelectedLocation: (location: ModuleLocation) => void | ||
} | ||
|
||
export type DeckMapContentProps = | ||
| DeckConfigStyleDeckMapContentProps | ||
| InterventionStyleDeckMapContentProps | ||
|
||
export const DeckMapContent: ( | ||
props: DeckMapContentProps | ||
) => JSX.Element = props => | ||
props.kind === 'intervention' ? ( | ||
<InterventionStyleDeckMapContent {...props} /> | ||
) : ( | ||
<DeckConfigStyleDeckMapContent {...props} /> | ||
) | ||
|
||
function InterventionStyleDeckMapContent( | ||
props: InterventionStyleDeckMapContentProps | ||
): JSX.Element { | ||
const labwareWithHighlights = | ||
props.labwareOnDeck?.map(labwareOnDeck => | ||
props.highlightLabwareEventuallyIn.reduce( | ||
(found, locationToMatch) => | ||
found || | ||
getIsLabwareMatch(labwareOnDeck.labwareLocation, locationToMatch), | ||
false | ||
) | ||
? { | ||
...labwareOnDeck, | ||
labwareChildren: ( | ||
<LabwareHighlight | ||
highlight={true} | ||
definition={labwareOnDeck.definition} | ||
/> | ||
), | ||
} | ||
: labwareOnDeck | ||
) ?? [] | ||
const modulesWithHighlights = | ||
props.modulesOnDeck?.map(module => | ||
props.highlightLabwareEventuallyIn.reduce( | ||
(found, locationToMatch) => | ||
found || getIsLabwareMatch(module.moduleLocation, locationToMatch), | ||
false | ||
) | ||
? { | ||
...module, | ||
moduleChildren: | ||
module?.nestedLabwareDef != null ? ( | ||
<LabwareHighlight | ||
highlight={true} | ||
definition={module.nestedLabwareDef} | ||
/> | ||
) : undefined, | ||
} | ||
: module | ||
) ?? [] | ||
return ( | ||
<BaseDeck | ||
deckConfig={props.deckConfig} | ||
robotType={props.robotType} | ||
labwareOnDeck={labwareWithHighlights} | ||
modulesOnDeck={modulesWithHighlights} | ||
/> | ||
) | ||
} | ||
|
||
function DeckConfigStyleDeckMapContent({ | ||
robotType, | ||
setSelectedLocation, | ||
}: DeckConfigStyleDeckMapContentProps): JSX.Element { | ||
const { DeckLocationSelect, selectedLocation } = useDeckLocationSelect( | ||
robotType, | ||
'default' | ||
) | ||
React.useEffect(() => { | ||
setSelectedLocation != null && setSelectedLocation(selectedLocation) | ||
}, [selectedLocation, setSelectedLocation]) | ||
return <>{DeckLocationSelect}</> | ||
} | ||
|
||
export function LabwareHighlight({ | ||
highlight, | ||
definition, | ||
}: { | ||
highlight: boolean | ||
definition: LabwareDefinition2 | ||
}): JSX.Element { | ||
const width = definition.dimensions.xDimension | ||
const height = definition.dimensions.yDimension | ||
|
||
return ( | ||
<RobotCoordsForeignDiv | ||
x={definition.cornerOffsetFromSlot.x} | ||
y={definition.cornerOffsetFromSlot.y} | ||
{...{ width, height }} | ||
innerDivProps={{ | ||
display: DISPLAY_FLEX, | ||
flexDirection: DIRECTION_COLUMN, | ||
justifyContent: JUSTIFY_FLEX_END, | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
<Box | ||
width="100%" | ||
height="100%" | ||
css={highlight ? HIGHLIGHT_STYLE : undefined} | ||
/> | ||
</RobotCoordsForeignDiv> | ||
) | ||
} | ||
|
||
const HIGHLIGHT_STYLE = css` | ||
border-radius: 7.04px; | ||
border: 3px solid ${COLORS.blue50}; | ||
box-shadow: 0 0 4px 3px #74b0ff; | ||
` | ||
|
||
export function getIsLabwareMatch( | ||
locationToCheck: LabwareLocation | ModuleLocation, | ||
deckRootLocation: string | ||
): boolean { | ||
if (typeof locationToCheck === 'string') { | ||
// This is the "off deck" case, which we do not render (and therefore return false). | ||
return false | ||
} else if ('slotName' in locationToCheck) { | ||
// This is if we're checking a module or a labware loaded on a slot | ||
return locationToCheck.slotName === deckRootLocation | ||
} else if ('addressableAreaName' in locationToCheck) { | ||
// This is if we're loaded on an AA like a staging slot | ||
return locationToCheck.addressableAreaName === deckRootLocation | ||
} else { | ||
// Defaulted cases: | ||
// if ('moduleId' in locationToCheck), e.g. on a module: | ||
// this should never happen because labware that is loaded on a module wouldn't be | ||
// in onDeckLabware, and onDeckModules is for modules not labware. | ||
// if ('labwareId' in locationToCheck), e.g. stacked labware: | ||
// this should never happen because we don't really render it properly here | ||
return false | ||
} | ||
} |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!