diff --git a/api-client/src/runs/getRunLoadedLabwareDefintions.ts b/api-client/src/runs/getRunLoadedLabwareDefintions.ts new file mode 100644 index 00000000000..d96e7facf8f --- /dev/null +++ b/api-client/src/runs/getRunLoadedLabwareDefintions.ts @@ -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 { + return request( + GET, + `runs/${runId}/loaded_labware_definitions`, + null, + config + ) +} diff --git a/api-client/src/runs/index.ts b/api-client/src/runs/index.ts index fff1f303543..cbbe54999fa 100644 --- a/api-client/src/runs/index.ts +++ b/api-client/src/runs/index.ts @@ -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' diff --git a/api-client/src/runs/types.ts b/api-client/src/runs/types.ts index e41626b6448..ea24c040ebc 100644 --- a/api-client/src/runs/types.ts +++ b/api-client/src/runs/types.ts @@ -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' @@ -86,6 +89,10 @@ export interface LabwareOffset { vector: VectorOffset } +export interface RunLoadedLabwareDefinitions { + data: Array +} + export interface Run { data: RunData } diff --git a/react-api-client/src/runs/index.ts b/react-api-client/src/runs/index.ts index 77b487a84fc..f4fa6f00f84 100644 --- a/react-api-client/src/runs/index.ts +++ b/react-api-client/src/runs/index.ts @@ -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' diff --git a/react-api-client/src/runs/useRunLoadedLabwareDefinitions.ts b/react-api-client/src/runs/useRunLoadedLabwareDefinitions.ts new file mode 100644 index 00000000000..75715403244 --- /dev/null +++ b/react-api-client/src/runs/useRunLoadedLabwareDefinitions.ts @@ -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 = {}, + hostOverride?: HostConfig +): UseQueryResult { + const contextHost = useHost() + const host = + hostOverride != null ? { ...contextHost, ...hostOverride } : contextHost + + return useQuery( + [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, + } + ) +}