-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new api-client function for getting commands as preserialized lis…
…t, add react wrapper, utilize in runpreview
- Loading branch information
Showing
7 changed files
with
93 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { GET, request } from '../../request' | ||
|
||
import type { ResponsePromise } from '../../request' | ||
import type { HostConfig } from '../../types' | ||
import type { | ||
CommandsAsPreSerializedListData, | ||
GetCommandsParams, | ||
} from './types' | ||
|
||
export function getCommandsAsPreSerializedList( | ||
config: HostConfig, | ||
runId: string, | ||
params: GetCommandsParams | ||
): ResponsePromise<CommandsAsPreSerializedListData> { | ||
return request<CommandsAsPreSerializedListData>( | ||
GET, | ||
`/runs/${runId}/commandsAsPreSerializedList`, | ||
null, | ||
config, | ||
params | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
react-api-client/src/runs/useAllCommandsAsDocumentQuery.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { UseQueryResult, useQuery } from 'react-query' | ||
import { getCommandsAsPreSerializedList } from '@opentrons/api-client' | ||
import { useHost } from '../api' | ||
import type { UseQueryOptions } from 'react-query' | ||
import type { | ||
GetCommandsParams, | ||
HostConfig, | ||
CommandsAsPreSerializedListData, | ||
} from '@opentrons/api-client' | ||
|
||
const DEFAULT_PAGE_LENGTH = 30 | ||
export const DEFAULT_PARAMS: GetCommandsParams = { | ||
cursor: null, | ||
pageLength: DEFAULT_PAGE_LENGTH, | ||
} | ||
|
||
export function useAllCommandsAsPreSerializedList<TError = Error>( | ||
runId: string | null, | ||
params?: GetCommandsParams | null, | ||
options: UseQueryOptions<CommandsAsPreSerializedListData, TError> = {} | ||
): UseQueryResult<CommandsAsPreSerializedListData, TError> { | ||
const host = useHost() | ||
const nullCheckedParams = params ?? DEFAULT_PARAMS | ||
|
||
const allOptions: UseQueryOptions<CommandsAsPreSerializedListData, TError> = { | ||
...options, | ||
enabled: host !== null && runId != null && options.enabled !== false, | ||
} | ||
const { cursor, pageLength } = nullCheckedParams | ||
const query = useQuery<CommandsAsPreSerializedListData, TError>( | ||
[host, 'runs', runId, 'getCommandsAsPreSerializedList', cursor, pageLength], | ||
() => { | ||
return getCommandsAsPreSerializedList( | ||
host as HostConfig, | ||
runId as string, | ||
nullCheckedParams | ||
).then(response => response.data) | ||
}, | ||
allOptions | ||
) | ||
|
||
return query | ||
} |