Skip to content

Commit

Permalink
feat(app): add PE analysis schema v6 adapter
Browse files Browse the repository at this point in the history
* feat(app): add PE analysis schema v6 adapter

#8661
  • Loading branch information
shlokamin authored Nov 9, 2021
1 parent dcb5a37 commit 31fcc98
Show file tree
Hide file tree
Showing 8 changed files with 6,558 additions and 48 deletions.
44 changes: 3 additions & 41 deletions api-client/src/protocols/types.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
import type { PipetteName, Command } from '@opentrons/shared-data'
import type { ProtocolResource } from '@opentrons/shared-data'
import type { ResourceLinks, ErrorDetails } from '../types'

export interface LoadedPipette {
id: string
pipetteName: PipetteName
mount: 'left' | 'right'
}

export interface LoadedLabware {
id: string
loadName: string
definitionUri: string
location: {
slot: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
}
}

export interface ProtocolMetadata {
protocolName?: string
author?: string
Expand All @@ -28,37 +13,14 @@ export interface ProtocolMetadata {
[key: string]: unknown
}

export interface PendingProtocolAnalysis {
id: string
status?: 'pending'
}

export interface CompletedProtocolAnalysis {
id: string
status?: 'completed'
result: 'ok' | 'not-ok' | 'error'
pipettes: LoadedPipette[]
labware: LoadedLabware[]
commands: Command[]
errors: string[]
}

export interface ProtocolData {
id: string
createdAt: string
protocolType: 'json' | 'python'
metadata: ProtocolMetadata
analyses: PendingProtocolAnalysis | CompletedProtocolAnalysis
}

export interface Protocol {
links?: ResourceLinks
data: ProtocolData
data: ProtocolResource
}

export interface Protocols {
links?: ResourceLinks
data: ProtocolData[]
data: ProtocolResource[]
}

export interface ProtocolFileInvalid extends ErrorDetails {
Expand Down
16 changes: 11 additions & 5 deletions app/src/organisms/RunDetails/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { useSelector } from 'react-redux'
import { getProtocolData, getProtocolName } from '../../redux/protocol'
import { getProtocolName } from '../../redux/protocol'
import { useCurrentProtocolRun } from '../ProtocolUpload/useCurrentProtocolRun'

import type { ProtocolFile } from '@opentrons/shared-data'
import { schemaV6Adapter, ProtocolFile } from '@opentrons/shared-data'
import type { State } from '../../redux/types'

interface ProtocolDetails {
Expand All @@ -10,9 +11,14 @@ interface ProtocolDetails {
}

export function useProtocolDetails(): ProtocolDetails {
const protocolData = useSelector((state: State) =>
getProtocolData(state)
) as ProtocolFile<{}> | null
let protocolData: ProtocolFile<{}> | null = null
const protocolAnalysis = useCurrentProtocolRun().protocolRecord?.data.analyses
if (protocolAnalysis != null) {
const lastProtocolAnalysis = protocolAnalysis[protocolAnalysis.length - 1]
if (lastProtocolAnalysis.status === 'completed') {
protocolData = schemaV6Adapter(lastProtocolAnalysis)
}
}
const displayName = useSelector((state: State) => getProtocolName(state))
return { displayName, protocolData }
}
12 changes: 11 additions & 1 deletion react-api-client/src/protocols/useCreateProtocolMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ export function useCreateProtocolMutation(
(protocolFiles: File[]) =>
createProtocol(host as HostConfig, protocolFiles).then(response => {
const protocolId = response.data.data.id
queryClient.setQueryData([host, 'protocols', protocolId], response.data)
queryClient
.invalidateQueries([host, 'protocols'])
.then(() =>
queryClient.setQueryData(
[host, 'protocols', protocolId],
response.data
)
)
.catch(e => {
console.error(e)
})
return response.data
}),
options
Expand Down
Loading

0 comments on commit 31fcc98

Please sign in to comment.