Skip to content

Commit 17871df

Browse files
committed
refactor(app): Add more host overrides
1 parent 45a722f commit 17871df

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

app/src/resources/runs/useCurrentRunId.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@ import { useNotifyAllRunsQuery } from './useNotifyAllRunsQuery'
33
import type { AxiosError } from 'axios'
44
import type { UseAllRunsQueryOptions } from '@opentrons/react-api-client/src/runs/useAllRunsQuery'
55
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
6+
import type { HostConfig } from '@opentrons/api-client'
67

78
export function useCurrentRunId(
8-
options: QueryOptionsWithPolling<UseAllRunsQueryOptions, AxiosError> = {}
9+
options: QueryOptionsWithPolling<UseAllRunsQueryOptions, AxiosError> = {},
10+
hostOverride?: HostConfig | null
911
): string | null {
10-
const { data: allRuns } = useNotifyAllRunsQuery({ pageLength: 0 }, options)
12+
const { data: allRuns } = useNotifyAllRunsQuery(
13+
{ pageLength: 0 },
14+
options,
15+
hostOverride
16+
)
1117
const currentRunLink = allRuns?.links?.current ?? null
1218
return currentRunLink != null &&
1319
typeof currentRunLink !== 'string' &&

app/src/resources/runs/useNotifyRunQuery.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,32 @@ import { useRunQuery } from '@opentrons/react-api-client'
33
import { useNotifyDataReady } from '../useNotifyDataReady'
44

55
import type { UseQueryResult } from 'react-query'
6-
import type { Run } from '@opentrons/api-client'
6+
import type { Run, HostConfig } from '@opentrons/api-client'
77
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
88
import type { NotifyTopic } from '../../redux/shell/types'
99

1010
export function useNotifyRunQuery<TError = Error>(
1111
runId: string | null,
12-
options: QueryOptionsWithPolling<Run, TError> = {}
12+
options: QueryOptionsWithPolling<Run, TError> = {},
13+
hostOverride?: HostConfig | null
1314
): UseQueryResult<Run, TError> {
1415
const isEnabled = options.enabled !== false && runId != null
1516

1617
const { notifyOnSettled, shouldRefetch } = useNotifyDataReady({
1718
topic: `robot-server/runs/${runId}` as NotifyTopic,
1819
options: { ...options, enabled: options.enabled != null && runId != null },
20+
hostOverride,
1921
})
2022

21-
const httpResponse = useRunQuery(runId, {
22-
...options,
23-
enabled: isEnabled && shouldRefetch,
24-
onSettled: notifyOnSettled,
25-
})
23+
const httpResponse = useRunQuery(
24+
runId,
25+
{
26+
...options,
27+
enabled: isEnabled && shouldRefetch,
28+
onSettled: notifyOnSettled,
29+
},
30+
hostOverride
31+
)
2632

2733
return httpResponse
2834
}

react-api-client/src/runs/useRunQuery.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ import type { HostConfig, Run } from '@opentrons/api-client'
77

88
export function useRunQuery<TError = Error>(
99
runId: string | null,
10-
options: UseQueryOptions<Run, TError> = {}
10+
options: UseQueryOptions<Run, TError> = {},
11+
hostOverride?: HostConfig | null
1112
): UseQueryResult<Run, TError> {
12-
const host = useHost()
13+
const contextHost = useHost()
14+
const host =
15+
hostOverride != null ? { ...contextHost, ...hostOverride } : contextHost
1316
const query = useQuery<Run, TError>(
1417
[host, 'runs', runId, 'details'],
1518
() =>

0 commit comments

Comments
 (0)