Skip to content

Commit

Permalink
feat(api-client, react-api-client): Add bindings for `GET /runs/:runI…
Browse files Browse the repository at this point in the history
…d/loaded_labware_definitions` (#17066)

Closes EXEC-1049
  • Loading branch information
mjhuff authored Dec 9, 2024
1 parent 1eab936 commit db7e48a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api-client/src/runs/getRunLoadedLabwareDefintions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GET, request } from '../request'

import type { ResponsePromise } from '../request'
import type { HostConfig } from '../types'
import type { RunLoadedLabwareDefinitions } from './types'

export function getRunLoadedLabwareDefintions(
config: HostConfig,
runId: string
): ResponsePromise<RunLoadedLabwareDefinitions> {
return request<RunLoadedLabwareDefinitions>(
GET,
`runs/${runId}/loaded_labware_definitions`,
null,
config
)
}
1 change: 1 addition & 0 deletions api-client/src/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from './createLabwareDefinition'
export * from './constants'
export * from './updateErrorRecoveryPolicy'
export * from './getErrorRecoveryPolicy'
export * from './getRunLoadedLabwareDefintions'

export * from './types'
export type { CreateRunData } from './createRun'
7 changes: 7 additions & 0 deletions api-client/src/runs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import type {
RunTimeParameter,
NozzleLayoutConfig,
OnDeckLabwareLocation,
LabwareDefinition1,
LabwareDefinition2,
LabwareDefinition3,
} from '@opentrons/shared-data'
import type { ResourceLink, ErrorDetails } from '../types'
export * from './commands/types'
Expand Down Expand Up @@ -86,6 +89,10 @@ export interface LabwareOffset {
vector: VectorOffset
}

export interface RunLoadedLabwareDefinitions {
data: Array<LabwareDefinition1 | LabwareDefinition2 | LabwareDefinition3>
}

export interface Run {
data: RunData
}
Expand Down
1 change: 1 addition & 0 deletions react-api-client/src/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './useCreateLabwareOffsetMutation'
export * from './useCreateLabwareDefinitionMutation'
export * from './useUpdateErrorRecoveryPolicy'
export * from './useErrorRecoveryPolicy'
export * from './useRunLoadedLabwareDefinitions'

export type { UsePlayRunMutationResult } from './usePlayRunMutation'
export type { UsePauseRunMutationResult } from './usePauseRunMutation'
Expand Down
34 changes: 34 additions & 0 deletions react-api-client/src/runs/useRunLoadedLabwareDefinitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useQuery } from 'react-query'

import { getRunLoadedLabwareDefintions } from '@opentrons/api-client'

import { useHost } from '../api'

import type { UseQueryOptions, UseQueryResult } from 'react-query'
import type { AxiosError } from 'axios'
import type {
RunLoadedLabwareDefinitions,
HostConfig,
} from '@opentrons/api-client'

export function useRunLoadedLabwareDefinitions(
runId: string | null,
options: UseQueryOptions<RunLoadedLabwareDefinitions, AxiosError> = {},
hostOverride?: HostConfig
): UseQueryResult<RunLoadedLabwareDefinitions, AxiosError> {
const contextHost = useHost()
const host =
hostOverride != null ? { ...contextHost, ...hostOverride } : contextHost

return useQuery<RunLoadedLabwareDefinitions, AxiosError>(
[host, 'runs', runId, 'loaded_labware_definitions'],
() =>
getRunLoadedLabwareDefintions(host as HostConfig, runId as string).then(
response => response.data
),
{
enabled: host != null && runId != null && options.enabled !== false,
...options,
}
)
}

0 comments on commit db7e48a

Please sign in to comment.