Skip to content

Commit

Permalink
feat(api-client, react-api-client): Wire up `/runs/:runId/currentStat…
Browse files Browse the repository at this point in the history
…e` (#16417)

Works towards RSQ-161
  • Loading branch information
mjhuff authored Oct 4, 2024
1 parent 8e1dabe commit 1a73679
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions api-client/src/runs/getRunCurrentState.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 { RunCurrentState } from './types'

export function getRunCurrentState(
config: HostConfig,
runId: string
): ResponsePromise<RunCurrentState> {
return request<RunCurrentState>(
GET,
`/runs/${runId}/currentState`,
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 @@ -10,6 +10,7 @@ export { getCommands } from './commands/getCommands'
export { getCommandsAsPreSerializedList } from './commands/getCommandsAsPreSerializedList'
export { createRunAction } from './createRunAction'
export { getRunCommandErrors } from './commands/getRunCommandErrors'
export { getRunCurrentState } from './getRunCurrentState'
export * from './createLabwareOffset'
export * from './createLabwareDefinition'
export * from './constants'
Expand Down
28 changes: 28 additions & 0 deletions api-client/src/runs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,24 @@ export interface Run {
data: RunData
}

export interface RunCurrentState {
data: RunCurrentStateData
links: RunCommandLink
}

export interface RunsLinks {
current?: ResourceLink
}

export interface RunCommandLink {
current: CommandLinkNoMeta
}

export interface CommandLinkNoMeta {
id: string
href: string
}

export interface GetRunsParams {
pageLength?: number // the number of items to include
}
Expand All @@ -100,6 +114,10 @@ export interface Runs {
links: RunsLinks
}

export interface RunCurrentStateData {
activeNozzleLayouts: Record<string, NozzleLayoutValues> // keyed by pipetteId
}

export const RUN_ACTION_TYPE_PLAY: 'play' = 'play'
export const RUN_ACTION_TYPE_PAUSE: 'pause' = 'pause'
export const RUN_ACTION_TYPE_STOP: 'stop' = 'stop'
Expand Down Expand Up @@ -173,3 +191,13 @@ export interface UpdateErrorRecoveryPolicyRequest {
}

export type UpdateErrorRecoveryPolicyResponse = Record<string, never>

/**
* Current Run State Data
*/
export interface NozzleLayoutValues {
startingNozzle: string
activeNozzles: string[]
config: NozzleLayoutConfig
}
export type NozzleLayoutConfig = 'column' | 'row' | 'full' | 'subrect'
1 change: 1 addition & 0 deletions react-api-client/src/runs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { useAllRunsQuery } from './useAllRunsQuery'
export { useRunQuery } from './useRunQuery'
export { useRunCurrentState } from './useRunCurrentState'
export { useCreateRunMutation } from './useCreateRunMutation'
export { useDeleteRunMutation } from './useDeleteRunMutation'
export { useCreateCommandMutation } from './useCreateCommandMutation'
Expand Down
28 changes: 28 additions & 0 deletions react-api-client/src/runs/useRunCurrentState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useQuery } from 'react-query'
import type { AxiosError } from 'axios'
import type { RunCurrentState, HostConfig } from '@opentrons/api-client'
import type { UseQueryOptions, UseQueryResult } from 'react-query'
import { useHost } from '../api'
import { getRunCurrentState } from '@opentrons/api-client'

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

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

0 comments on commit 1a73679

Please sign in to comment.