Skip to content

Commit 15343db

Browse files
authored
refactor(app): isNotifyEnabled -> shouldRefetch (#15264)
1 parent df62b9b commit 15343db

File tree

14 files changed

+68
-68
lines changed

14 files changed

+68
-68
lines changed

app/src/organisms/ApplyHistoricOffsets/hooks/__tests__/useOffsetCandidatesForAnalysis.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ vi.mock('../useAllHistoricOffsets')
2020
vi.mock('../getLabwareLocationCombos')
2121
vi.mock('@opentrons/shared-data')
2222
vi.mock('../../../../resources/runs')
23-
vi.mock('../../../../resources/useNotifyService')
23+
vi.mock('../../../../resources/useNotifyDataReady')
2424

2525
const mockLabwareDef = fixtureTiprack300ul as LabwareDefinition2
2626

app/src/organisms/ChooseProtocolSlideout/__tests__/ChooseProtocolSlideout.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ import {
1616
import { useTrackCreateProtocolRunEvent } from '../../../organisms/Devices/hooks'
1717
import { useCreateRunFromProtocol } from '../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol'
1818
import { ChooseProtocolSlideout } from '../'
19-
import { useNotifyService } from '../../../resources/useNotifyService'
19+
import { useNotifyDataReady } from '../../../resources/useNotifyDataReady'
2020
import type { ProtocolAnalysisOutput } from '@opentrons/shared-data'
2121

2222
vi.mock('../../ChooseRobotToRunProtocolSlideout/useCreateRunFromProtocol')
2323
vi.mock('../../../redux/protocol-storage')
2424
vi.mock('../../../organisms/Devices/hooks')
2525
vi.mock('../../../redux/config')
26-
vi.mock('../../../resources/useNotifyService')
26+
vi.mock('../../../resources/useNotifyDataReady')
2727

2828
const render = (props: React.ComponentProps<typeof ChooseProtocolSlideout>) => {
2929
return renderWithProviders(
@@ -66,7 +66,7 @@ describe('ChooseProtocolSlideout', () => {
6666
vi.mocked(useTrackCreateProtocolRunEvent).mockReturnValue({
6767
trackCreateProtocolRunEvent: mockTrackCreateProtocolRunEvent,
6868
})
69-
vi.mocked(useNotifyService).mockReturnValue({} as any)
69+
vi.mocked(useNotifyDataReady).mockReturnValue({} as any)
7070
})
7171

7272
it('renders slideout if showSlideout true', () => {

app/src/organisms/ChooseRobotSlideout/__tests__/ChooseRobotSlideout.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import {
2222
import { useFeatureFlag } from '../../../redux/config'
2323
import { getNetworkInterfaces } from '../../../redux/networking'
2424
import { ChooseRobotSlideout } from '..'
25-
import { useNotifyService } from '../../../resources/useNotifyService'
25+
import { useNotifyDataReady } from '../../../resources/useNotifyDataReady'
2626
import type { RunTimeParameter } from '@opentrons/shared-data'
2727

2828
vi.mock('../../../redux/discovery')
2929
vi.mock('../../../redux/robot-update')
3030
vi.mock('../../../redux/networking')
31-
vi.mock('../../../resources/useNotifyService')
31+
vi.mock('../../../resources/useNotifyDataReady')
3232
vi.mock('../../../redux/config')
3333
const render = (props: React.ComponentProps<typeof ChooseRobotSlideout>) => {
3434
return renderWithProviders(
@@ -111,7 +111,7 @@ describe('ChooseRobotSlideout', () => {
111111
wifi: null,
112112
ethernet: null,
113113
})
114-
vi.mocked(useNotifyService).mockReturnValue({} as any)
114+
vi.mocked(useNotifyDataReady).mockReturnValue({} as any)
115115
})
116116

117117
it('renders slideout if isExpanded true', () => {

app/src/organisms/ChooseRobotToRunProtocolSlideout/__tests__/ChooseRobotToRunProtocolSlideout.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { storedProtocolData as storedProtocolDataFixture } from '../../../redux/
3131
import { useCreateRunFromProtocol } from '../useCreateRunFromProtocol'
3232
import { useOffsetCandidatesForAnalysis } from '../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis'
3333
import { ChooseRobotToRunProtocolSlideout } from '../'
34-
import { useNotifyService } from '../../../resources/useNotifyService'
34+
import { useNotifyDataReady } from '../../../resources/useNotifyDataReady'
3535

3636
import type { State } from '../../../redux/types'
3737

@@ -44,7 +44,7 @@ vi.mock('../../../redux/networking')
4444
vi.mock('../../../redux/config')
4545
vi.mock('../useCreateRunFromProtocol')
4646
vi.mock('../../ApplyHistoricOffsets/hooks/useOffsetCandidatesForAnalysis')
47-
vi.mock('../../../resources/useNotifyService')
47+
vi.mock('../../../resources/useNotifyDataReady')
4848
vi.mock('../../../redux/config')
4949

5050
const render = (
@@ -128,7 +128,7 @@ describe('ChooseRobotToRunProtocolSlideout', () => {
128128
when(vi.mocked(getNetworkInterfaces))
129129
.calledWith({} as State, expect.any(String))
130130
.thenReturn({ wifi: null, ethernet: null })
131-
vi.mocked(useNotifyService).mockReturnValue({} as any)
131+
vi.mocked(useNotifyDataReady).mockReturnValue({} as any)
132132
})
133133
afterEach(() => {
134134
vi.resetAllMocks()

app/src/organisms/ProtocolUpload/hooks/useCurrentRunId.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useNotifyAllRunsQuery } from '../../../resources/runs'
22

33
import type { AxiosError } from 'axios'
44
import type { UseAllRunsQueryOptions } from '@opentrons/react-api-client/src/runs/useAllRunsQuery'
5-
import type { QueryOptionsWithPolling } from '../../../resources/useNotifyService'
5+
import type { QueryOptionsWithPolling } from '../../../resources/useNotifyDataReady'
66

77
export function useCurrentRunId(
88
options: QueryOptionsWithPolling<UseAllRunsQueryOptions, AxiosError> = {}

app/src/resources/__tests__/useNotifyService.test.ts renamed to app/src/resources/__tests__/useNotifyDataReady.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import { when } from 'vitest-when'
55

66
import { useHost } from '@opentrons/react-api-client'
77

8-
import { useNotifyService } from '../useNotifyService'
8+
import { useNotifyDataReady } from '../useNotifyDataReady'
99
import { appShellListener } from '../../redux/shell/remote'
1010
import { useTrackEvent } from '../../redux/analytics'
1111
import { notifySubscribeAction } from '../../redux/shell'
1212
import { useFeatureFlag } from '../../redux/config'
1313

1414
import type { Mock } from 'vitest'
1515
import type { HostConfig } from '@opentrons/api-client'
16-
import type { QueryOptionsWithPolling } from '../useNotifyService'
16+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
1717

18-
vi.unmock('../useNotifyService')
18+
vi.unmock('../useNotifyDataReady')
1919
vi.mock('react-redux')
2020
vi.mock('@opentrons/react-api-client')
2121
vi.mock('../../redux/analytics')
@@ -30,7 +30,7 @@ const MOCK_OPTIONS: QueryOptionsWithPolling<any, any> = {
3030
forceHttpPolling: false,
3131
}
3232

33-
describe('useNotifyService', () => {
33+
describe('useNotifyDataReady', () => {
3434
let mockDispatch: Mock
3535
let mockTrackEvent: Mock
3636
let mockHTTPRefetch: Mock
@@ -54,12 +54,12 @@ describe('useNotifyService', () => {
5454

5555
it('should trigger an HTTP refetch and subscribe action on a successful initial mount', () => {
5656
const { result } = renderHook(() =>
57-
useNotifyService({
57+
useNotifyDataReady({
5858
topic: MOCK_TOPIC,
5959
options: MOCK_OPTIONS,
6060
} as any)
6161
)
62-
expect(result.current.isNotifyEnabled).toEqual(true)
62+
expect(result.current.shouldRefetch).toEqual(true)
6363
expect(mockDispatch).toHaveBeenCalledWith(
6464
notifySubscribeAction(MOCK_HOST_CONFIG.hostname, MOCK_TOPIC)
6565
)
@@ -68,36 +68,36 @@ describe('useNotifyService', () => {
6868

6969
it('should not subscribe to notifications if forceHttpPolling is true', () => {
7070
const { result } = renderHook(() =>
71-
useNotifyService({
71+
useNotifyDataReady({
7272
topic: MOCK_TOPIC,
7373
options: { ...MOCK_OPTIONS, forceHttpPolling: true },
7474
} as any)
7575
)
76-
expect(result.current.isNotifyEnabled).toEqual(true)
76+
expect(result.current.shouldRefetch).toEqual(true)
7777
expect(appShellListener).not.toHaveBeenCalled()
7878
expect(mockDispatch).not.toHaveBeenCalled()
7979
})
8080

8181
it('should not subscribe to notifications if enabled is false', () => {
8282
const { result } = renderHook(() =>
83-
useNotifyService({
83+
useNotifyDataReady({
8484
topic: MOCK_TOPIC,
8585
options: { ...MOCK_OPTIONS, enabled: false },
8686
} as any)
8787
)
88-
expect(result.current.isNotifyEnabled).toEqual(true)
88+
expect(result.current.shouldRefetch).toEqual(true)
8989
expect(appShellListener).not.toHaveBeenCalled()
9090
expect(mockDispatch).not.toHaveBeenCalled()
9191
})
9292

9393
it('should not subscribe to notifications if staleTime is Infinity', () => {
9494
const { result } = renderHook(() =>
95-
useNotifyService({
95+
useNotifyDataReady({
9696
topic: MOCK_TOPIC,
9797
options: { ...MOCK_OPTIONS, staleTime: Infinity },
9898
} as any)
9999
)
100-
expect(result.current.isNotifyEnabled).toEqual(true)
100+
expect(result.current.shouldRefetch).toEqual(true)
101101
expect(appShellListener).not.toHaveBeenCalled()
102102
expect(mockDispatch).not.toHaveBeenCalled()
103103
})
@@ -108,14 +108,14 @@ describe('useNotifyService', () => {
108108
errorSpy.mockImplementation(() => {})
109109

110110
const { result } = renderHook(() =>
111-
useNotifyService({
111+
useNotifyDataReady({
112112
topic: MOCK_TOPIC,
113113
setRefetch: mockHTTPRefetch,
114114
options: MOCK_OPTIONS,
115115
} as any)
116116
)
117117

118-
expect(result.current.isNotifyEnabled).toEqual(true)
118+
expect(result.current.shouldRefetch).toEqual(true)
119119
})
120120

121121
it('should return set HTTP refetch to always and fire an analytics reporting event if the connection was refused', () => {
@@ -126,15 +126,15 @@ describe('useNotifyService', () => {
126126
callback('ECONNREFUSED')
127127
})
128128
const { rerender, result } = renderHook(() =>
129-
useNotifyService({
129+
useNotifyDataReady({
130130
topic: MOCK_TOPIC,
131131
setRefetch: mockHTTPRefetch,
132132
options: MOCK_OPTIONS,
133133
} as any)
134134
)
135135
expect(mockTrackEvent).toHaveBeenCalled()
136136
rerender()
137-
expect(result.current.isNotifyEnabled).toEqual(true)
137+
expect(result.current.shouldRefetch).toEqual(true)
138138
})
139139

140140
it('should trigger a single HTTP refetch if the refetch flag was returned', () => {
@@ -145,14 +145,14 @@ describe('useNotifyService', () => {
145145
callback({ refetch: true })
146146
})
147147
const { rerender, result } = renderHook(() =>
148-
useNotifyService({
148+
useNotifyDataReady({
149149
topic: MOCK_TOPIC,
150150
setRefetch: mockHTTPRefetch,
151151
options: MOCK_OPTIONS,
152152
} as any)
153153
)
154154
rerender()
155-
expect(result.current.isNotifyEnabled).toEqual(true)
155+
expect(result.current.shouldRefetch).toEqual(true)
156156
})
157157

158158
it('should trigger a single HTTP refetch if the unsubscribe flag was returned', () => {
@@ -163,18 +163,18 @@ describe('useNotifyService', () => {
163163
callback({ unsubscribe: true })
164164
})
165165
const { rerender, result } = renderHook(() =>
166-
useNotifyService({
166+
useNotifyDataReady({
167167
topic: MOCK_TOPIC,
168168
options: MOCK_OPTIONS,
169169
} as any)
170170
)
171171
rerender()
172-
expect(result.current.isNotifyEnabled).toEqual(true)
172+
expect(result.current.shouldRefetch).toEqual(true)
173173
})
174174

175175
it('should clean up the listener on dismount', () => {
176176
const { unmount } = renderHook(() =>
177-
useNotifyService({
177+
useNotifyDataReady({
178178
topic: MOCK_TOPIC,
179179
options: MOCK_OPTIONS,
180180
})
@@ -185,7 +185,7 @@ describe('useNotifyService', () => {
185185

186186
it('should still clean up the listener if the hostname changes to null after subscribing', () => {
187187
const { unmount, rerender } = renderHook(() =>
188-
useNotifyService({
188+
useNotifyDataReady({
189189
hostOverride: MOCK_HOST_CONFIG,
190190
topic: MOCK_TOPIC,
191191
options: MOCK_OPTIONS,
@@ -204,13 +204,13 @@ describe('useNotifyService', () => {
204204
.thenReturn(true)
205205

206206
const { result } = renderHook(() =>
207-
useNotifyService({
207+
useNotifyDataReady({
208208
topic: MOCK_TOPIC,
209209
options: MOCK_OPTIONS,
210210
} as any)
211211
)
212212

213-
expect(result.current.isNotifyEnabled).toEqual(true)
213+
expect(result.current.shouldRefetch).toEqual(true)
214214
expect(appShellListener).not.toHaveBeenCalled()
215215
})
216216
})

app/src/resources/deck_configuration/useNotifyDeckConfigurationQuery.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { useDeckConfigurationQuery } from '@opentrons/react-api-client'
22

3-
import { useNotifyService } from '../useNotifyService'
3+
import { useNotifyDataReady } from '../useNotifyDataReady'
44

55
import type { UseQueryResult } from 'react-query'
66
import type { DeckConfiguration } from '@opentrons/shared-data'
7-
import type { QueryOptionsWithPolling } from '../useNotifyService'
7+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
88

99
export function useNotifyDeckConfigurationQuery(
1010
options: QueryOptionsWithPolling<DeckConfiguration, unknown> = {}
1111
): UseQueryResult<DeckConfiguration> {
12-
const { notifyOnSettled, isNotifyEnabled } = useNotifyService({
12+
const { notifyOnSettled, shouldRefetch } = useNotifyDataReady({
1313
topic: 'robot-server/deck_configuration',
1414
options,
1515
})
1616

1717
const httpQueryResult = useDeckConfigurationQuery({
1818
...options,
19-
enabled: options?.enabled !== false && isNotifyEnabled,
19+
enabled: options?.enabled !== false && shouldRefetch,
2020
onSettled: notifyOnSettled,
2121
})
2222

app/src/resources/maintenance_runs/useNotifyCurrentMaintenanceRun.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
import { useCurrentMaintenanceRun } from '@opentrons/react-api-client'
22

3-
import { useNotifyService } from '../useNotifyService'
3+
import { useNotifyDataReady } from '../useNotifyDataReady'
44

55
import type { UseQueryResult } from 'react-query'
66
import type { MaintenanceRun } from '@opentrons/api-client'
7-
import type { QueryOptionsWithPolling } from '../useNotifyService'
7+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
88

99
export function useNotifyCurrentMaintenanceRun(
1010
options: QueryOptionsWithPolling<MaintenanceRun, Error> = {}
1111
): UseQueryResult<MaintenanceRun> | UseQueryResult<MaintenanceRun, Error> {
12-
const { notifyOnSettled, isNotifyEnabled } = useNotifyService({
12+
const { notifyOnSettled, shouldRefetch } = useNotifyDataReady({
1313
topic: 'robot-server/maintenance_runs/current_run',
1414
options,
1515
})
1616

1717
const httpQueryResult = useCurrentMaintenanceRun({
1818
...options,
19-
enabled: options?.enabled !== false && isNotifyEnabled,
19+
enabled: options?.enabled !== false && shouldRefetch,
2020
onSettled: notifyOnSettled,
2121
})
2222

app/src/resources/runs/useNotifyAllCommandsAsPreSerializedList.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { useAllCommandsAsPreSerializedList } from '@opentrons/react-api-client'
22

3-
import { useNotifyService } from '../useNotifyService'
3+
import { useNotifyDataReady } from '../useNotifyDataReady'
44

55
import type { UseQueryResult } from 'react-query'
66
import type { AxiosError } from 'axios'
77
import type { CommandsData, GetCommandsParams } from '@opentrons/api-client'
8-
import type { QueryOptionsWithPolling } from '../useNotifyService'
8+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
99

1010
export function useNotifyAllCommandsAsPreSerializedList(
1111
runId: string | null,
1212
params?: GetCommandsParams | null,
1313
options: QueryOptionsWithPolling<CommandsData, AxiosError> = {}
1414
): UseQueryResult<CommandsData, AxiosError> {
15-
const { notifyOnSettled, isNotifyEnabled } = useNotifyService({
15+
const { notifyOnSettled, shouldRefetch } = useNotifyDataReady({
1616
topic: `robot-server/runs/pre_serialized_commands/${runId}`,
1717
options,
1818
})
1919

2020
const httpResponse = useAllCommandsAsPreSerializedList(runId, params, {
2121
...options,
22-
enabled: options?.enabled !== false && isNotifyEnabled,
22+
enabled: options?.enabled !== false && shouldRefetch,
2323
onSettled: notifyOnSettled,
2424
})
2525

app/src/resources/runs/useNotifyAllCommandsQuery.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { useAllCommandsQuery } from '@opentrons/react-api-client'
22

3-
import { useNotifyService } from '../useNotifyService'
3+
import { useNotifyDataReady } from '../useNotifyDataReady'
44

55
import type { UseQueryResult } from 'react-query'
66
import type { CommandsData, GetCommandsParams } from '@opentrons/api-client'
7-
import type { QueryOptionsWithPolling } from '../useNotifyService'
7+
import type { QueryOptionsWithPolling } from '../useNotifyDataReady'
88

99
export function useNotifyAllCommandsQuery<TError = Error>(
1010
runId: string | null,
1111
params?: GetCommandsParams | null,
1212
options: QueryOptionsWithPolling<CommandsData, TError> = {}
1313
): UseQueryResult<CommandsData, TError> {
14-
const { notifyOnSettled, isNotifyEnabled } = useNotifyService({
14+
const { notifyOnSettled, shouldRefetch } = useNotifyDataReady({
1515
topic: 'robot-server/runs/current_command', // only updates to the current command cause all commands to change
1616
options,
1717
})
1818

1919
const httpResponse = useAllCommandsQuery(runId, params, {
2020
...options,
21-
enabled: options?.enabled !== false && isNotifyEnabled,
21+
enabled: options?.enabled !== false && shouldRefetch,
2222
onSettled: notifyOnSettled,
2323
})
2424

0 commit comments

Comments
 (0)