-
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.
refactor(app): Use run loaded labware defs in Error Recovery (#17074)
Closes EXEC-761 and EXEC-1050 This PR wires up the GET /run/:runId/loaded_labware_definitions to Error Recovery, cutting down on command scanning just a little bit further. Some additional error handling is added to the existing getLabwareDefURI.
- Loading branch information
Showing
5 changed files
with
80 additions
and
25 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
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
31 changes: 31 additions & 0 deletions
31
app/src/resources/runs/__tests__/useRunLoadedLabwareDefintionsByUri.test.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,31 @@ | ||
import { describe, expect, it, beforeEach, vi } from 'vitest' | ||
import { renderHook } from '@testing-library/react' | ||
|
||
import { useRunLoadedLabwareDefinitions } from '@opentrons/react-api-client' | ||
import { fixture96Plate } from '@opentrons/shared-data' | ||
|
||
import { useRunLoadedLabwareDefinitionsByUri } from '/app/resources/runs' | ||
|
||
import type { LabwareDefinition2 } from '@opentrons/shared-data' | ||
|
||
vi.mock('@opentrons/react-api-client') | ||
|
||
const mockLabwareDef = fixture96Plate as LabwareDefinition2 | ||
|
||
describe('useRunLoadedLabwareDefinitionsByUri', () => { | ||
beforeEach(() => { | ||
vi.mocked(useRunLoadedLabwareDefinitions).mockReturnValue({ | ||
data: { data: [mockLabwareDef] }, | ||
} as any) | ||
}) | ||
|
||
it('returns a record of labware definitions keyed by URI', () => { | ||
const { result } = renderHook(() => | ||
useRunLoadedLabwareDefinitionsByUri('mockId') | ||
) | ||
|
||
expect(result.current).toEqual({ | ||
'fixture/fixture_96_plate/1': mockLabwareDef, | ||
}) | ||
}) | ||
}) |
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
40 changes: 40 additions & 0 deletions
40
app/src/resources/runs/useRunLoadedLabwareDefinitionsByUri.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,40 @@ | ||
import { useMemo } from 'react' | ||
|
||
import { useRunLoadedLabwareDefinitions } from '@opentrons/react-api-client' | ||
import { getLabwareDefURI } from '@opentrons/shared-data' | ||
|
||
import type { UseQueryOptions } from 'react-query' | ||
import type { AxiosError } from 'axios' | ||
import type { | ||
HostConfig, | ||
RunLoadedLabwareDefinitions, | ||
} from '@opentrons/api-client' | ||
import type { LabwareDefinition2 } from '@opentrons/shared-data' | ||
|
||
export type RunLoadedLabwareDefinitionsByUri = Record< | ||
string, | ||
LabwareDefinition2 | ||
> | ||
|
||
// Returns a record of labware definitions keyed by URI for the labware that | ||
// has been loaded with a "loadLabware" command. Errors if the run is not the current run. | ||
export function useRunLoadedLabwareDefinitionsByUri( | ||
runId: string | null, | ||
options: UseQueryOptions<RunLoadedLabwareDefinitions, AxiosError> = {}, | ||
hostOverride?: HostConfig | ||
): RunLoadedLabwareDefinitionsByUri { | ||
const { data } = useRunLoadedLabwareDefinitions(runId, options, hostOverride) | ||
|
||
return useMemo(() => { | ||
const result: Record<string, LabwareDefinition2> = {} | ||
// @ts-expect-error TODO(jh, 10-12-24): Update the app's typing to support LabwareDefinition3. | ||
data?.data.forEach((def: LabwareDefinition2) => { | ||
if ('schemaVersion' in def) { | ||
const lwUri = getLabwareDefURI(def) | ||
result[lwUri] = def | ||
} | ||
}) | ||
|
||
return result | ||
}, [data]) | ||
} |