-
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, components): add SlotInformation component (#…
…16043) * feat(protocol-designer, components): add SlotInformation component
- Loading branch information
Showing
9 changed files
with
247 additions
and
10 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
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
70 changes: 70 additions & 0 deletions
70
protocol-designer/src/organisms/SlotInformation/SlotInformation.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,70 @@ | ||
import * as React from 'react' | ||
import { Flex } from '@opentrons/components' | ||
import { I18nextProvider } from 'react-i18next' | ||
import { i18n } from '../../localization' | ||
import { SlotInformation as SlotInformationComponent } from '.' | ||
|
||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
const mockLocations = [ | ||
'A1', | ||
'A2', | ||
'A3', | ||
'B1', | ||
'B2', | ||
'B3', | ||
'C1', | ||
'C2', | ||
'C3', | ||
'D1', | ||
'D2', | ||
'D3', | ||
] | ||
|
||
const mockLiquids = ['Mastermix', 'Ethanol', 'Water'] | ||
const mockLabwares = ['96 Well Plate', 'Adapter'] | ||
const mockModules = ['Thermocycler Module Gen2', 'Heater-Shaker Module'] | ||
|
||
const meta: Meta<typeof SlotInformationComponent> = { | ||
title: 'Protocol-Designer/Organisms/SlotInformation', | ||
component: SlotInformationComponent, | ||
argTypes: { | ||
location: { | ||
control: { | ||
type: 'select', | ||
}, | ||
options: mockLocations, | ||
}, | ||
}, | ||
decorators: [ | ||
Story => ( | ||
<I18nextProvider i18n={i18n}> | ||
<Flex width="21rem"> | ||
<Story /> | ||
</Flex> | ||
</I18nextProvider> | ||
), | ||
], | ||
} | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof SlotInformationComponent> | ||
|
||
export const SlotInformation: Story = { | ||
args: { | ||
location: 'A1', | ||
liquids: mockLiquids, | ||
labwares: mockLabwares, | ||
modules: mockModules, | ||
}, | ||
} | ||
|
||
export const SlotInformationEmpty: Story = { | ||
args: { | ||
location: 'A1', | ||
liquids: [], | ||
labwares: [], | ||
modules: [], | ||
}, | ||
} |
65 changes: 65 additions & 0 deletions
65
protocol-designer/src/organisms/SlotInformation/__tests__/SlotInformation.test.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,65 @@ | ||
import * as React from 'react' | ||
import { describe, it, beforeEach, expect } from 'vitest' | ||
import { screen } from '@testing-library/react' | ||
|
||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../localization' | ||
|
||
import { SlotInformation } from '..' | ||
|
||
const mockLiquids = ['Mastermix', 'Ethanol', 'Water'] | ||
const mockLabwares = ['96 Well Plate', 'Adapter'] | ||
const mockModules = ['Thermocycler Module Gen2', 'Heater-Shaker Module'] | ||
|
||
const render = (props: React.ComponentProps<typeof SlotInformation>) => { | ||
return renderWithProviders(<SlotInformation {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('SlotInformation', () => { | ||
let props: React.ComponentProps<typeof SlotInformation> | ||
|
||
beforeEach(() => { | ||
props = { | ||
location: 'A1', | ||
liquids: [], | ||
labwares: [], | ||
modules: [], | ||
} | ||
}) | ||
|
||
it('should render DeckInfoLabel and title', () => { | ||
render(props) | ||
screen.getByText('A1') | ||
screen.getByText('Slot Stack Information') | ||
}) | ||
|
||
it('should render liquid, labware, and module', () => { | ||
render(props) | ||
screen.getByText('Liquid') | ||
screen.getByText('Labware') | ||
screen.getByText('Module') | ||
expect(screen.getAllByText('None').length).toBe(3) | ||
}) | ||
|
||
it('should render info of liquid, labware, and module', () => { | ||
props = { | ||
...props, | ||
liquids: mockLiquids, | ||
labwares: mockLabwares, | ||
modules: mockModules, | ||
} | ||
render(props) | ||
expect(screen.getAllByText('Liquid').length).toBe(mockLiquids.length) | ||
expect(screen.getAllByText('Labware').length).toBe(mockLabwares.length) | ||
expect(screen.getAllByText('Module').length).toBe(mockModules.length) | ||
screen.getByText('Mastermix') | ||
screen.getByText('Ethanol') | ||
screen.getByText('Water') | ||
screen.getByText('96 Well Plate') | ||
screen.getByText('Adapter') | ||
screen.getByText('Thermocycler Module Gen2') | ||
screen.getByText('Heater-Shaker Module') | ||
}) | ||
}) |
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,88 @@ | ||
import React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
import { | ||
ALIGN_CENTER, | ||
DeckInfoLabel, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
ListItem, | ||
ListItemDescriptor, | ||
SPACING, | ||
StyledText, | ||
} from '@opentrons/components' | ||
|
||
interface SlotInformationProps { | ||
location: string | ||
liquids?: string[] | ||
labwares?: string[] | ||
modules?: string[] | ||
} | ||
|
||
export const SlotInformation: React.FC<SlotInformationProps> = ({ | ||
location, | ||
liquids = [], | ||
labwares = [], | ||
modules = [], | ||
}) => { | ||
const { t } = useTranslation('shared') | ||
return ( | ||
<Flex | ||
flexDirection={DIRECTION_COLUMN} | ||
gridGap={SPACING.spacing12} | ||
width="100%" | ||
> | ||
<Flex gridGap={SPACING.spacing8} alignItems={ALIGN_CENTER}> | ||
<DeckInfoLabel deckLabel={location} /> | ||
<StyledText desktopStyle="headingSmallBold"> | ||
{t('slot_stack_information')} | ||
</StyledText> | ||
</Flex> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}> | ||
<StackInfoList title={t('liquid')} items={liquids} /> | ||
<StackInfoList title={t('labware')} items={labwares} /> | ||
<StackInfoList title={t('module')} items={modules} /> | ||
</Flex> | ||
</Flex> | ||
) | ||
} | ||
|
||
interface StackInfoListProps { | ||
title: string | ||
items: string[] | ||
} | ||
|
||
function StackInfoList({ title, items }: StackInfoListProps): JSX.Element { | ||
return ( | ||
<> | ||
{items.length > 0 ? ( | ||
items.map((item, index) => ( | ||
<StackInfo | ||
key={`${title}_${index}`} | ||
title={title} | ||
stackInformation={item} | ||
/> | ||
)) | ||
) : ( | ||
<StackInfo title={title} /> | ||
)} | ||
</> | ||
) | ||
} | ||
|
||
interface StackInfoProps { | ||
title: string | ||
stackInformation?: string | ||
} | ||
|
||
function StackInfo({ title, stackInformation }: StackInfoProps): JSX.Element { | ||
const { t } = useTranslation('shared') | ||
return ( | ||
<ListItem type="noActive"> | ||
<ListItemDescriptor | ||
type="mini" | ||
content={stackInformation ?? t('none')} | ||
description={title} | ||
/> | ||
</ListItem> | ||
) | ||
} |
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 +1 @@ | ||
console.log('organisms for new components') | ||
export * from './SlotInformation' |