Skip to content

Commit 8966802

Browse files
feat(app): Use notifications for labware offsets instead of polling (#17832)
## Overview The client-side half of EXEC-1342. ## Test Plan and Hands on Testing * [x] I guess at this point we can turn on the feature flag and try this out by entering LPC on one client and changing offsets on another? * Tested with a merge of this PR, #17853, #17817, and #17850. ## Changelog The client was polling `POST /labwareOffsets/searches`. This switches it to only happen when the client receives a notification from the server that offsets have changed, with a polling fallback. I'm entirely cargo-culting the patterns from the existing `useNotify___()` hooks. ## Risk assessment Medium. I don't think we have a good way to integration-test this kind of thing, so there are risks of things like missed updates, or inadvertent polling.
1 parent bb82e49 commit 8966802

File tree

8 files changed

+46
-15
lines changed

8 files changed

+46
-15
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ module.exports = {
5656
'useCurrentMaintenanceRun',
5757
'useDeckConfigurationQuery',
5858
'useAllCommandsAsPreSerializedList',
59+
'useSearchLabwareOffsets',
5960
],
6061
message:
6162
'HTTP hook deprecated. Use the equivalent notification wrapper (useNotifyXYZ).',

api-client/src/labwareOffsets/searchLabwareOffsets.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
} from '../types'
88
import type { ANY_LOCATION, StoredLabwareOffset } from './types'
99

10-
export interface SearchLabwareOffsetsData {
10+
export interface SearchLabwareOffsetsRequest {
1111
/** Filters are ORed together. Within a single filter, criteria are ANDed together. */
1212
filters: Array<{
1313
id?: string
@@ -31,10 +31,10 @@ export interface SearchLabwareOffsetsResponse {
3131
*/
3232
export function searchLabwareOffsets(
3333
config: HostConfig,
34-
data: SearchLabwareOffsetsData
34+
data: SearchLabwareOffsetsRequest
3535
): ResponsePromise<SearchLabwareOffsetsResponse> {
3636
return request<
3737
SearchLabwareOffsetsResponse,
38-
{ data: SearchLabwareOffsetsData }
38+
{ data: SearchLabwareOffsetsRequest }
3939
>(POST, '/labwareOffsets/searches', { data }, config)
4040
}

app/src/organisms/LabwarePositionCheck/LPCFlows/hooks/useLPCLabwareInfo/getLPCSearchParams.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { ANY_LOCATION } from '@opentrons/api-client'
22

3-
import type { SearchLabwareOffsetsData } from '@opentrons/api-client'
3+
import type { SearchLabwareOffsetsRequest } from '@opentrons/api-client'
44
import type { LabwareLocationInfo } from '/app/redux/protocol-runs'
55

66
// For location combos that require LPC consideration, prepare params for searching
77
// for the existing offsets for those location combos.
88
export function getLPCSearchParams(
99
lwLocCombos: LabwareLocationInfo[]
10-
): SearchLabwareOffsetsData {
10+
): SearchLabwareOffsetsRequest {
1111
const locationSpecificOffsetSearchData = lwLocCombos.map(combo => ({
1212
definitionUri: combo.definitionUri,
1313
locationSequence: combo.lwOffsetLocSeq,

app/src/organisms/LabwarePositionCheck/LPCFlows/hooks/useLPCLabwareInfo/index.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useMemo } from 'react'
22

3-
import { useSearchLabwareOffsets } from '@opentrons/react-api-client'
43
import { FLEX_ROBOT_TYPE, OT2_ROBOT_TYPE } from '@opentrons/shared-data'
54
import { RUN_STATUS_IDLE } from '@opentrons/api-client'
65

76
import { getUniqueValidLwLocationInfoByAnalysis } from './getUniqueValidLwLocationInfoByAnalysis'
87
import { getLPCLabwareInfoFrom } from './getLPCLabwareInfoFrom'
98
import { getLPCSearchParams } from './getLPCSearchParams'
9+
import { useNotifySearchLabwareOffsets } from '/app/resources/labware_offsets'
1010
import { useNotifyRunQuery, useRunStatus } from '/app/resources/runs'
1111

1212
import type { LabwareOffset, StoredLabwareOffset } from '@opentrons/api-client'
@@ -65,11 +65,7 @@ function useFlexLPCLabwareInfo({
6565
[lwLocationCombos.length]
6666
)
6767

68-
// TODO(jh, 03-14-25): Add this search route to notifications.
69-
70-
// We have to poll, because it's possible for a user to update the
71-
// offsets on a different app while a view utilizing this data is active.
72-
const { data: lwOffsetsData } = useSearchLabwareOffsets(
68+
const { data: lwOffsetsData } = useNotifySearchLabwareOffsets(
7369
searchLwOffsetsParams,
7470
{
7571
enabled:

app/src/redux/shell/types.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,14 @@ export interface RobotMassStorageDeviceRemoved {
146146

147147
export type NotifyTopic =
148148
| 'ALL_TOPICS'
149+
| `robot-server/clientData/${string}`
150+
| 'robot-server/deck_configuration'
151+
| 'robot-server/labwareOffsets'
149152
| 'robot-server/maintenance_runs/current_run'
150153
| 'robot-server/runs/commands_links'
151154
| 'robot-server/runs'
152155
| `robot-server/runs/${string}`
153-
| 'robot-server/deck_configuration'
154156
| `robot-server/runs/pre_serialized_commands/${string}`
155-
| `robot-server/clientData/${string}`
156157

157158
export interface NotifySubscribeAction {
158159
type: 'shell:NOTIFY_SUBSCRIBE'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './useNotifySearchLabwareOffsets'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { useSearchLabwareOffsets } from '@opentrons/react-api-client'
2+
3+
import { useNotifyDataReady } from '../useNotifyDataReady'
4+
5+
import type {
6+
SearchLabwareOffsetsRequest,
7+
SearchLabwareOffsetsResponse,
8+
} from '@opentrons/api-client'
9+
import type { AxiosError } from 'axios'
10+
import type { UseQueryResult } from 'react-query'
11+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
12+
13+
export function useNotifySearchLabwareOffsets(
14+
request: SearchLabwareOffsetsRequest,
15+
options: QueryOptionsWithPolling<
16+
SearchLabwareOffsetsResponse,
17+
AxiosError
18+
> = {}
19+
): UseQueryResult<SearchLabwareOffsetsResponse> {
20+
const { shouldRefetch, queryOptionsNotify } = useNotifyDataReady({
21+
topic: 'robot-server/labwareOffsets',
22+
options,
23+
})
24+
25+
const httpQueryResult = useSearchLabwareOffsets(request, queryOptionsNotify)
26+
27+
if (shouldRefetch) {
28+
void httpQueryResult.refetch()
29+
}
30+
31+
return httpQueryResult
32+
}

react-api-client/src/labwareOffsets/useSearchLabwareOffsets.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import type { UseQueryOptions, UseQueryResult } from 'react-query'
88
import type { AxiosError } from 'axios'
99
import type {
1010
HostConfig,
11-
SearchLabwareOffsetsData,
11+
SearchLabwareOffsetsRequest,
1212
SearchLabwareOffsetsResponse,
1313
} from '@opentrons/api-client'
1414

1515
export function useSearchLabwareOffsets(
16-
data: SearchLabwareOffsetsData,
16+
data: SearchLabwareOffsetsRequest,
1717
options: UseQueryOptions<SearchLabwareOffsetsResponse, AxiosError> = {}
1818
): UseQueryResult<SearchLabwareOffsetsResponse, AxiosError> {
1919
const host = useHost()

0 commit comments

Comments
 (0)