Skip to content

Commit

Permalink
feat(app): add loading state to LPC when applying offsets (#13702)
Browse files Browse the repository at this point in the history
closes RQA-1220
  • Loading branch information
shlokamin authored Oct 6, 2023
1 parent a3a033a commit 2fd0ecf
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/src/atoms/buttons/SmallButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ interface SmallButtonProps extends StyleProps {
onClick: React.MouseEventHandler
buttonType?: SmallButtonTypes
buttonText: React.ReactNode
iconPlacement?: IconPlacement
iconName?: IconName
iconPlacement?: IconPlacement | null
iconName?: IconName | null
buttonCategory?: ButtonCategory // if not specified, it will be 'default'
disabled?: boolean
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface LabwarePositionCheckModalProps {
protocolName: string
caughtError?: Error
setMaintenanceRunId: (id: string | null) => void
isDeletingMaintenanceRun: boolean
}

export const LabwarePositionCheckComponent = (
Expand All @@ -62,6 +63,7 @@ export const LabwarePositionCheckComponent = (
maintenanceRunId,
setMaintenanceRunId,
protocolName,
isDeletingMaintenanceRun,
} = props
const { t } = useTranslation(['labware_position_check', 'shared'])
const isOnDevice = useSelector(getIsOnDevice)
Expand Down Expand Up @@ -102,6 +104,9 @@ export const LabwarePositionCheckComponent = (
])

const [fatalError, setFatalError] = React.useState<string | null>(null)
const [isApplyingOffsets, setIsApplyingOffsets] = React.useState<boolean>(

Check warning on line 107 in app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx#L107

Added line #L107 was not covered by tests
false
)
const [
{ workingOffsets, tipPickUpOffset },
registerPosition,
Expand Down Expand Up @@ -295,12 +300,15 @@ export const LabwarePositionCheckComponent = (
}

const handleApplyOffsets = (offsets: LabwareOffsetCreateData[]): void => {
setIsApplyingOffsets(true)

Check warning on line 303 in app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx#L303

Added line #L303 was not covered by tests
Promise.all(offsets.map(data => createLabwareOffset({ runId, data })))
.then(() => {
onCloseClick()
setIsApplyingOffsets(false)

Check warning on line 307 in app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx#L307

Added line #L307 was not covered by tests
})
.catch((e: Error) => {
setFatalError(`error applying labware offsets: ${e.message}`)
setIsApplyingOffsets(false)

Check warning on line 311 in app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/organisms/LabwarePositionCheck/LabwarePositionCheckComponent.tsx#L311

Added line #L311 was not covered by tests
})
}

Expand Down Expand Up @@ -356,7 +364,13 @@ export const LabwarePositionCheckComponent = (
<ResultsSummary
{...currentStep}
protocolData={protocolData}
{...{ workingOffsets, existingOffsets, handleApplyOffsets }}
{...{
workingOffsets,
existingOffsets,
handleApplyOffsets,
isApplyingOffsets,
isDeletingMaintenanceRun,
}}
/>
)
}
Expand Down
28 changes: 26 additions & 2 deletions app/src/organisms/LabwarePositionCheck/ResultsSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
MODULE_ICON_NAME_BY_TYPE,
BORDERS,
ALIGN_FLEX_END,
Icon,
LocationIcon,
} from '@opentrons/components'
import { PythonLabwareOffsetSnippet } from '../../molecules/PythonLabwareOffsetSnippet'
Expand Down Expand Up @@ -55,6 +56,8 @@ interface ResultsSummaryProps extends ResultsSummaryStep {
workingOffsets: WorkingOffset[]
existingOffsets: LabwareOffset[]
handleApplyOffsets: (offsets: LabwareOffsetCreateData[]) => void
isApplyingOffsets: boolean
isDeletingMaintenanceRun: boolean
}
export const ResultsSummary = (
props: ResultsSummaryProps
Expand All @@ -65,10 +68,13 @@ export const ResultsSummary = (
workingOffsets,
handleApplyOffsets,
existingOffsets,
isApplyingOffsets,
isDeletingMaintenanceRun,
} = props
const labwareDefinitions = getLabwareDefinitionsFromCommands(
protocolData.commands
)
const isSubmittingAndClosing = isApplyingOffsets || isDeletingMaintenanceRun
const isLabwareOffsetCodeSnippetsOn = useSelector(
getIsLabwareOffsetCodeSnippetsOn
)
Expand Down Expand Up @@ -168,6 +174,9 @@ export const ResultsSummary = (
alignSelf={ALIGN_FLEX_END}
onClick={() => handleApplyOffsets(offsetsToApply)}
buttonText={i18n.format(t('apply_offsets'), 'capitalize')}
iconName={isSubmittingAndClosing ? 'ot-spinner' : null}
iconPlacement={isSubmittingAndClosing ? 'startIcon' : null}
disabled={isSubmittingAndClosing}
/>
) : (
<Flex
Expand All @@ -177,8 +186,23 @@ export const ResultsSummary = (
alignItems={ALIGN_CENTER}
>
<NeedHelpLink href={LPC_HELP_LINK_URL} />
<PrimaryButton onClick={() => handleApplyOffsets(offsetsToApply)}>
{i18n.format(t('apply_offsets'), 'capitalize')}
<PrimaryButton
onClick={() => handleApplyOffsets(offsetsToApply)}
disabled={isSubmittingAndClosing}
>
<Flex>
{isSubmittingAndClosing ? (
<Icon
size="1rem"
spin
name="ot-spinner"
marginRight={SPACING.spacing8}
/>
) : null}
<StyledText>
{i18n.format(t('apply_offsets'), 'capitalize')}
</StyledText>
</Flex>
</PrimaryButton>
</Flex>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ describe('ResultsSummary', () => {
protocolData: mockCompletedAnalysis,
workingOffsets: mockWorkingOffsets,
existingOffsets: mockExistingOffsets,
isApplyingOffsets: false,
isDeletingMaintenanceRun: false,
handleApplyOffsets: jest.fn(),
}
})
Expand All @@ -54,6 +56,22 @@ describe('ResultsSummary', () => {
getByRole('button', { name: 'Apply offsets' }).click()
expect(props.handleApplyOffsets).toHaveBeenCalled()
})
it('does disables the CTA to apply offsets when offsets are already being applied', () => {
props.isApplyingOffsets = true
const { getByRole } = render(props)
const button = getByRole('button', { name: 'Apply offsets' })
expect(button).toBeDisabled()
button.click()
expect(props.handleApplyOffsets).not.toHaveBeenCalled()
})
it('does disables the CTA to apply offsets when the maintenance run is being deleted', () => {
props.isDeletingMaintenanceRun = true
const { getByRole } = render(props)
const button = getByRole('button', { name: 'Apply offsets' })
expect(button).toBeDisabled()
button.click()
expect(props.handleApplyOffsets).not.toHaveBeenCalled()
})
it('renders a row per offset to apply', () => {
const { getByRole, queryAllByRole } = render(props)
expect(
Expand Down
1 change: 1 addition & 0 deletions app/src/organisms/LabwarePositionCheck/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface LabwarePositionCheckModalProps {
protocolName: string
caughtError?: Error
setMaintenanceRunId: (id: string | null) => void
isDeletingMaintenanceRun: boolean
}

// We explicitly wrap LabwarePositionCheckComponent in an ErrorBoundary because an error might occur while pulling in
Expand Down
6 changes: 5 additions & 1 deletion app/src/organisms/LabwarePositionCheck/useLaunchLPC.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function useLaunchLPC(
const {
createTargetedMaintenanceRun,
} = useCreateTargetedMaintenanceRunMutation()
const { deleteMaintenanceRun } = useDeleteMaintenanceRunMutation()
const {
deleteMaintenanceRun,
isLoading: isDeletingMaintenanceRun,
} = useDeleteMaintenanceRunMutation()
const mostRecentAnalysis = useMostRecentCompletedAnalysis(runId)
const [maintenanceRunId, setMaintenanceRunId] = React.useState<string | null>(
null
Expand Down Expand Up @@ -74,6 +77,7 @@ export function useLaunchLPC(
maintenanceRunId={maintenanceRunId}
setMaintenanceRunId={setMaintenanceRunId}
protocolName={protocolName ?? ''}
isDeletingMaintenanceRun={isDeletingMaintenanceRun}
/>
) : null,
}
Expand Down

0 comments on commit 2fd0ecf

Please sign in to comment.