Skip to content

Commit efa83d4

Browse files
authored
fix(app): rm analyzing state in run header for historical runs (#11122)
1 parent 94c32a7 commit efa83d4

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

app/src/atoms/Banner/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TYPOGRAPHY,
1212
BORDERS,
1313
Btn,
14+
SIZE_1,
1415
} from '@opentrons/components'
1516

1617
import type { StyleProps } from '@opentrons/components'
@@ -31,6 +32,8 @@ export interface BannerProps extends StyleProps {
3132
onCloseClick?: (() => unknown) | React.MouseEventHandler<HTMLButtonElement>
3233
/** Override the default Alert Icon */
3334
icon?: IconProps
35+
/** some banner onCloseClicks fire events, this allows a spinner after click but before event finishes */
36+
isCloseActionLoading?: boolean
3437
}
3538

3639
const BANNER_PROPS_BY_TYPE: Record<
@@ -65,7 +68,14 @@ const BANNER_PROPS_BY_TYPE: Record<
6568
}
6669

6770
export function Banner(props: BannerProps): JSX.Element {
68-
const { type, onCloseClick, icon, children, ...styleProps } = props
71+
const {
72+
type,
73+
onCloseClick,
74+
icon,
75+
children,
76+
isCloseActionLoading,
77+
...styleProps
78+
} = props
6979
const bannerProps = BANNER_PROPS_BY_TYPE[type]
7080

7181
const iconProps = {
@@ -98,7 +108,7 @@ export function Banner(props: BannerProps): JSX.Element {
98108
<Flex flex="1" alignItems={ALIGN_CENTER}>
99109
{props.children}
100110
</Flex>
101-
{props.onCloseClick && (
111+
{onCloseClick && !isCloseActionLoading && (
102112
<Btn
103113
data-testid="Banner_close-button"
104114
onClick={props.onCloseClick}
@@ -108,6 +118,9 @@ export function Banner(props: BannerProps): JSX.Element {
108118
<Icon name="close" aria-label="close_icon" />
109119
</Btn>
110120
)}
121+
{isCloseActionLoading && (
122+
<Icon name="ot-spinner" size={SIZE_1} aria-label={`ot-spinner`} spin />
123+
)}
111124
</Flex>
112125
)
113126
}

app/src/organisms/Devices/ProtocolRun/ProtocolRunHeader.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ export function ProtocolRunHeader({
127127
const isHeaterShakerInProtocol = useIsHeaterShakerInProtocol()
128128
const configHasHeaterShakerAttached = useSelector(getIsHeaterShakerAttached)
129129
const createdAtTimestamp = useRunCreatedAtTimestamp(runId)
130-
const { protocolData, displayName, protocolKey } = useProtocolDetailsForRun(
131-
runId
132-
)
130+
const {
131+
protocolData,
132+
displayName,
133+
protocolKey,
134+
isProtocolAnalyzing,
135+
} = useProtocolDetailsForRun(runId)
133136
const { trackProtocolRunEvent } = useTrackProtocolRunEvent(runId)
134137
const robotAnalyticsData = useRobotAnalyticsData(robotName)
135138
const isRobotViewable = useIsRobotViewable(robotName)
136-
const isProtocolAnalyzing = protocolData == null && isRobotViewable
137139
const runStatus = useRunStatus(runId)
138140
const { analysisErrors } = useProtocolAnalysisErrors(runId)
139141
const isRunCurrent = Boolean(useRunQuery(runId)?.data?.data?.current)
@@ -280,6 +282,7 @@ export function ProtocolRunHeader({
280282
isMutationLoading ||
281283
isRobotBusy ||
282284
isProtocolAnalyzing ||
285+
protocolData == null ||
283286
runStatus === RUN_STATUS_FINISHING ||
284287
runStatus === RUN_STATUS_PAUSE_REQUESTED ||
285288
runStatus === RUN_STATUS_STOP_REQUESTED ||
@@ -376,7 +379,11 @@ export function ProtocolRunHeader({
376379
switch (runStatus) {
377380
case RUN_STATUS_FAILED: {
378381
clearProtocolBanner = (
379-
<Banner type="error" onCloseClick={handleClearClick}>
382+
<Banner
383+
type="error"
384+
onCloseClick={handleClearClick}
385+
isCloseActionLoading={isClosingCurrentRun}
386+
>
380387
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} width="100%">
381388
{`${t('run_failed')}.`}
382389
</Flex>
@@ -386,7 +393,11 @@ export function ProtocolRunHeader({
386393
}
387394
case RUN_STATUS_SUCCEEDED: {
388395
clearProtocolBanner = (
389-
<Banner type="success" onCloseClick={handleClearClick}>
396+
<Banner
397+
type="success"
398+
onCloseClick={handleClearClick}
399+
isCloseActionLoading={isClosingCurrentRun}
400+
>
390401
<Flex justifyContent={JUSTIFY_SPACE_BETWEEN} width="100%">
391402
{`${t('run_completed')}.`}
392403
</Flex>

app/src/organisms/Devices/ProtocolRun/__tests__/ProtocolRunHeader.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const PROTOCOL_DETAILS = {
177177
displayName: PROTOCOL_NAME,
178178
protocolData: simpleV6Protocol,
179179
protocolKey: 'fakeProtocolKey',
180+
isProtocolAnalyzing: false,
180181
}
181182

182183
const mockMovingHeaterShaker = {
@@ -344,6 +345,7 @@ describe('ProtocolRunHeader', () => {
344345
displayName: null,
345346
protocolData: null,
346347
protocolKey: null,
348+
isProtocolAnalyzing: true,
347349
})
348350

349351
const [{ getByRole }] = render()
@@ -735,4 +737,16 @@ describe('ProtocolRunHeader', () => {
735737
expect(mockPush).toHaveBeenCalledWith('/devices')
736738
})
737739
})
740+
it('renders banner with spinner if currently closing current run', async () => {
741+
when(mockUseRunStatus)
742+
.calledWith(RUN_ID)
743+
.mockReturnValue(RUN_STATUS_SUCCEEDED)
744+
when(mockUseCloseCurrentRun).calledWith().mockReturnValue({
745+
isClosingCurrentRun: true,
746+
closeCurrentRun: mockCloseCurrentRun,
747+
})
748+
const [{ getByText, getByLabelText }] = render()
749+
getByText('Run completed.')
750+
getByLabelText('ot-spinner')
751+
})
738752
})

app/src/organisms/Devices/hooks/__tests__/useProtocolDetailsForRun.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ describe('useProtocolDetailsForRun hook', () => {
7979
displayName: null,
8080
protocolData: null,
8181
protocolKey: null,
82+
isProtocolAnalyzing: false,
8283
})
8384
})
8485

@@ -111,6 +112,7 @@ describe('useProtocolDetailsForRun hook', () => {
111112
displayName: 'fake protocol',
112113
protocolData: simpleV6Protocol,
113114
protocolKey: 'fakeProtocolKey',
115+
isProtocolAnalyzing: false,
114116
})
115117
})
116118
})

app/src/organisms/Devices/hooks/useProtocolDetailsForRun.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ProtocolDetails {
1313
displayName: string | null
1414
protocolData: ProtocolAnalysisFile<{}> | null
1515
protocolKey: string | null
16+
isProtocolAnalyzing?: boolean
1617
}
1718

1819
export function useProtocolDetailsForRun(
@@ -56,5 +57,7 @@ export function useProtocolDetailsForRun(
5657
protocolData:
5758
mostRecentAnalysis != null ? schemaV6Adapter(mostRecentAnalysis) : null,
5859
protocolKey: protocolRecord?.data.key ?? null,
60+
isProtocolAnalyzing:
61+
mostRecentAnalysis != null && mostRecentAnalysis?.status === 'pending',
5962
}
6063
}

0 commit comments

Comments
 (0)