-
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(app): add Deck configuration screen to ProtocolSetup (#13808)
* feat(app): add Deck configuration screen to ProtocolSetup
- Loading branch information
Showing
13 changed files
with
474 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
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
76 changes: 76 additions & 0 deletions
76
...rganisms/ProtocolSetupDeckConfiguration/__tests__/ProtocolSetupDeckConfiguration.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,76 @@ | ||
import * as React from 'react' | ||
import { when, resetAllWhenMocks } from 'jest-when' | ||
|
||
import { renderWithProviders, DeckConfigurator } from '@opentrons/components' | ||
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client' | ||
|
||
import { i18n } from '../../../i18n' | ||
import { useMostRecentCompletedAnalysis } from '../../LabwarePositionCheck/useMostRecentCompletedAnalysis' | ||
import { ProtocolSetupDeckConfiguration } from '..' | ||
|
||
jest.mock('@opentrons/components/src/hardware-sim/DeckConfigurator/index') | ||
jest.mock('@opentrons/react-api-client') | ||
jest.mock('../../LabwarePositionCheck/useMostRecentCompletedAnalysis') | ||
|
||
const mockSetSetupScreen = jest.fn() | ||
const mockUpdateDeckConfiguration = jest.fn() | ||
const PROTOCOL_DETAILS = { | ||
displayName: 'fake protocol', | ||
protocolData: [], | ||
protocolKey: 'fakeProtocolKey', | ||
robotType: 'OT-3 Standard' as const, | ||
} | ||
|
||
const mockDeckConfigurator = DeckConfigurator as jest.MockedFunction< | ||
typeof DeckConfigurator | ||
> | ||
const mockUseMostRecentCompletedAnalysis = useMostRecentCompletedAnalysis as jest.MockedFunction< | ||
typeof useMostRecentCompletedAnalysis | ||
> | ||
const mockUseUpdateDeckConfigurationMutation = useUpdateDeckConfigurationMutation as jest.MockedFunction< | ||
typeof useUpdateDeckConfigurationMutation | ||
> | ||
|
||
const render = ( | ||
props: React.ComponentProps<typeof ProtocolSetupDeckConfiguration> | ||
) => { | ||
return renderWithProviders(<ProtocolSetupDeckConfiguration {...props} />, { | ||
i18nInstance: i18n, | ||
}) | ||
} | ||
|
||
describe('ProtocolSetupDeckConfiguration', () => { | ||
let props: React.ComponentProps<typeof ProtocolSetupDeckConfiguration> | ||
|
||
beforeEach(() => { | ||
props = { | ||
fixtureLocation: 'D3', | ||
runId: 'mockRunId', | ||
setSetupScreen: mockSetSetupScreen, | ||
providedFixtureOptions: [], | ||
} | ||
mockDeckConfigurator.mockReturnValue(<div>mock DeckConfigurator</div>) | ||
when(mockUseMostRecentCompletedAnalysis) | ||
.calledWith('mockRunId') | ||
.mockReturnValue(PROTOCOL_DETAILS.protocolData as any) | ||
mockUseUpdateDeckConfigurationMutation.mockReturnValue({ | ||
updateDeckConfiguration: mockUpdateDeckConfiguration, | ||
} as any) | ||
}) | ||
|
||
afterEach(() => { | ||
resetAllWhenMocks() | ||
}) | ||
|
||
it('should render text, button, and DeckConfigurator', () => { | ||
const [{ getByText }] = render(props) | ||
getByText('Deck configuration') | ||
getByText('mock DeckConfigurator') | ||
}) | ||
|
||
it('should call a mock function when tapping the back button', () => { | ||
const [{ getByTestId }] = render(props) | ||
getByTestId('ChildNavigation_Back_Button').click() | ||
expect(mockSetSetupScreen).toHaveBeenCalledWith('modules') | ||
}) | ||
}) |
152 changes: 152 additions & 0 deletions
152
app/src/organisms/ProtocolSetupDeckConfiguration/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,152 @@ | ||
import * as React from 'react' | ||
import { useTranslation } from 'react-i18next' | ||
|
||
import { | ||
DeckConfigurator, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
JUSTIFY_CENTER, | ||
SPACING, | ||
} from '@opentrons/components' | ||
import { useUpdateDeckConfigurationMutation } from '@opentrons/react-api-client' | ||
import { | ||
STANDARD_SLOT_LOAD_NAME, | ||
WASTE_CHUTE_LOAD_NAME, | ||
} from '@opentrons/shared-data' | ||
|
||
import { ChildNavigation } from '../ChildNavigation' | ||
import { AddFixtureModal } from '../DeviceDetailsDeckConfiguration/AddFixtureModal' | ||
import { DeckConfigurationDiscardChangesModal } from '../DeviceDetailsDeckConfiguration/DeckConfigurationDiscardChangesModal' | ||
import { useMostRecentCompletedAnalysis } from '../LabwarePositionCheck/useMostRecentCompletedAnalysis' | ||
import { Portal } from '../../App/portal' | ||
|
||
import type { | ||
Cutout, | ||
DeckConfiguration, | ||
Fixture, | ||
FixtureLoadName, | ||
LoadFixtureRunTimeCommand, | ||
} from '@opentrons/shared-data' | ||
import type { SetupScreens } from '../../pages/OnDeviceDisplay/ProtocolSetup' | ||
|
||
interface ProtocolSetupDeckConfigurationProps { | ||
fixtureLocation: Cutout | ||
runId: string | ||
setSetupScreen: React.Dispatch<React.SetStateAction<SetupScreens>> | ||
providedFixtureOptions: FixtureLoadName[] | ||
} | ||
|
||
export function ProtocolSetupDeckConfiguration({ | ||
fixtureLocation, | ||
runId, | ||
setSetupScreen, | ||
providedFixtureOptions, | ||
}: ProtocolSetupDeckConfigurationProps): JSX.Element { | ||
const { t } = useTranslation(['protocol_setup', 'devices_landing', 'shared']) | ||
|
||
const [ | ||
showConfigurationModal, | ||
setShowConfigurationModal, | ||
] = React.useState<boolean>(true) | ||
const [ | ||
targetFixtureLocation, | ||
setTargetFixtureLocation, | ||
] = React.useState<Cutout>(fixtureLocation) | ||
const [ | ||
showDiscardChangeModal, | ||
setShowDiscardChangeModal, | ||
] = React.useState<boolean>(false) | ||
|
||
const mostRecentAnalysis = useMostRecentCompletedAnalysis(runId) | ||
const STUBBED_LOAD_FIXTURE: LoadFixtureRunTimeCommand = { | ||
id: 'stubbed_load_fixture', | ||
commandType: 'loadFixture', | ||
params: { | ||
fixtureId: 'stubbedFixtureId', | ||
loadName: WASTE_CHUTE_LOAD_NAME, | ||
location: { cutout: 'D3' }, | ||
}, | ||
createdAt: 'fakeTimestamp', | ||
startedAt: 'fakeTimestamp', | ||
completedAt: 'fakeTimestamp', | ||
status: 'succeeded', | ||
} | ||
|
||
const requiredFixtureDetails = | ||
mostRecentAnalysis?.commands != null | ||
? [ | ||
// parseInitialLoadedFixturesByCutout(mostRecentAnalysis.commands), | ||
STUBBED_LOAD_FIXTURE, | ||
] | ||
: [] | ||
|
||
const deckConfig = | ||
(requiredFixtureDetails.map( | ||
(fixture): Fixture | false => | ||
fixture.params.fixtureId != null && { | ||
fixtureId: fixture.params.fixtureId, | ||
fixtureLocation: fixture.params.location.cutout, | ||
loadName: fixture.params.loadName, | ||
} | ||
) as DeckConfiguration) ?? [] | ||
|
||
const { updateDeckConfiguration } = useUpdateDeckConfigurationMutation() | ||
|
||
const handleClickAdd = (fixtureLocation: Cutout): void => { | ||
setTargetFixtureLocation(fixtureLocation) | ||
setShowConfigurationModal(true) | ||
} | ||
|
||
const handleClickRemove = (fixtureLocation: Cutout): void => { | ||
updateDeckConfiguration({ | ||
fixtureLocation, | ||
loadName: STANDARD_SLOT_LOAD_NAME, | ||
}) | ||
} | ||
|
||
const handleClickConfirm = (): void => { | ||
// ToDo (kk:10/17/2023) add a function for the confirmation in a following PR for RAUT-804 | ||
} | ||
|
||
return ( | ||
<> | ||
<Portal level="top"> | ||
{showDiscardChangeModal ? ( | ||
<DeckConfigurationDiscardChangesModal | ||
setShowConfirmationModal={setShowDiscardChangeModal} | ||
/> | ||
) : null} | ||
{showConfigurationModal && | ||
(fixtureLocation != null || targetFixtureLocation != null) ? ( | ||
<AddFixtureModal | ||
fixtureLocation={targetFixtureLocation} | ||
setShowAddFixtureModal={setShowConfigurationModal} | ||
providedFixtureOptions={providedFixtureOptions} | ||
isOnDevice | ||
/> | ||
) : null} | ||
</Portal> | ||
<Flex flexDirection={DIRECTION_COLUMN}> | ||
<ChildNavigation | ||
header={t('devices_landing:deck_configuration')} | ||
onClickBack={() => setSetupScreen('modules')} | ||
buttonText={t('shared:confirm')} | ||
onClickButton={handleClickConfirm} | ||
/> | ||
<Flex | ||
marginTop="7.75rem" | ||
paddingX={SPACING.spacing40} | ||
paddingBottom={SPACING.spacing40} | ||
justifyContent={JUSTIFY_CENTER} | ||
> | ||
{/* DeckConfigurator will be replaced by BaseDeck when RAUT-793 is ready */} | ||
<DeckConfigurator | ||
deckConfig={deckConfig} | ||
handleClickAdd={handleClickAdd} | ||
handleClickRemove={handleClickRemove} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</> | ||
) | ||
} |
Oops, something went wrong.