Skip to content

Commit

Permalink
refactor(app): Add more host overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Jul 30, 2024
1 parent 45a722f commit 17871df
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
10 changes: 8 additions & 2 deletions app/src/resources/runs/useCurrentRunId.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@ import { useNotifyAllRunsQuery } from './useNotifyAllRunsQuery'
import type { AxiosError } from 'axios'
import type { UseAllRunsQueryOptions } from '@opentrons/react-api-client/src/runs/useAllRunsQuery'
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
import type { HostConfig } from '@opentrons/api-client'

export function useCurrentRunId(
options: QueryOptionsWithPolling<UseAllRunsQueryOptions, AxiosError> = {}
options: QueryOptionsWithPolling<UseAllRunsQueryOptions, AxiosError> = {},
hostOverride?: HostConfig | null
): string | null {
const { data: allRuns } = useNotifyAllRunsQuery({ pageLength: 0 }, options)
const { data: allRuns } = useNotifyAllRunsQuery(
{ pageLength: 0 },
options,
hostOverride
)
const currentRunLink = allRuns?.links?.current ?? null
return currentRunLink != null &&
typeof currentRunLink !== 'string' &&
Expand Down
20 changes: 13 additions & 7 deletions app/src/resources/runs/useNotifyRunQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,32 @@ import { useRunQuery } from '@opentrons/react-api-client'
import { useNotifyDataReady } from '../useNotifyDataReady'

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

export function useNotifyRunQuery<TError = Error>(
runId: string | null,
options: QueryOptionsWithPolling<Run, TError> = {}
options: QueryOptionsWithPolling<Run, TError> = {},
hostOverride?: HostConfig | null
): UseQueryResult<Run, TError> {
const isEnabled = options.enabled !== false && runId != null

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

const httpResponse = useRunQuery(runId, {
...options,
enabled: isEnabled && shouldRefetch,
onSettled: notifyOnSettled,
})
const httpResponse = useRunQuery(
runId,
{
...options,
enabled: isEnabled && shouldRefetch,
onSettled: notifyOnSettled,
},
hostOverride
)

return httpResponse
}
7 changes: 5 additions & 2 deletions react-api-client/src/runs/useRunQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import type { HostConfig, Run } from '@opentrons/api-client'

export function useRunQuery<TError = Error>(
runId: string | null,
options: UseQueryOptions<Run, TError> = {}
options: UseQueryOptions<Run, TError> = {},
hostOverride?: HostConfig | null
): UseQueryResult<Run, TError> {
const host = useHost()
const contextHost = useHost()
const host =
hostOverride != null ? { ...contextHost, ...hostOverride } : contextHost
const query = useQuery<Run, TError>(
[host, 'runs', runId, 'details'],
() =>
Expand Down

0 comments on commit 17871df

Please sign in to comment.