-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app, react-api-client): handle failed analysis for RTP protocol o…
- Loading branch information
Showing
9 changed files
with
128 additions
and
10 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
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
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
54 changes: 54 additions & 0 deletions
54
react-api-client/src/protocols/useMostRecentSuccessfulAnalysisAsDocumentQuery.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,54 @@ | ||
import { useQuery } from 'react-query' | ||
import { getProtocolAnalysisAsDocument } from '@opentrons/api-client' | ||
import { useHost } from '../api' | ||
|
||
import type { UseQueryResult, UseQueryOptions } from 'react-query' | ||
import type { HostConfig } from '@opentrons/api-client' | ||
import type { | ||
CompletedProtocolAnalysis, | ||
ProtocolAnalysisSummary, | ||
} from '@opentrons/shared-data' | ||
|
||
const getMostRecentSuccessfulAnalysisId = async ( | ||
analysisSummaryIds: string[], | ||
host: HostConfig | null, | ||
protocolId: string | ||
): Promise<CompletedProtocolAnalysis | null> => { | ||
for (const analysisId of analysisSummaryIds) { | ||
const { data: analysis } = await getProtocolAnalysisAsDocument( | ||
host as HostConfig, | ||
protocolId, | ||
analysisId | ||
) | ||
if (analysis.errors.length === 0) { | ||
return analysis | ||
} | ||
} | ||
return null | ||
} | ||
|
||
export function useMostRecentSuccessfulAnalysisAsDocumentQuery<TError = Error>( | ||
protocolId: string, | ||
analysisSummaries: ProtocolAnalysisSummary[], | ||
options: UseQueryOptions<CompletedProtocolAnalysis | null, TError> = {} | ||
): UseQueryResult<CompletedProtocolAnalysis | null, TError> { | ||
const host = useHost() | ||
|
||
const query = useQuery<CompletedProtocolAnalysis | null, TError>( | ||
[host, 'protocols', protocolId, 'analyses', 'mostRecentSuccessful'], | ||
async () => { | ||
const analysisIds = analysisSummaries.map(summary => summary.id) | ||
|
||
const mostRecentSuccessfulAnalysis = await getMostRecentSuccessfulAnalysisId( | ||
analysisIds, | ||
host, | ||
protocolId | ||
) | ||
|
||
return mostRecentSuccessfulAnalysis | ||
}, | ||
options | ||
) | ||
|
||
return query | ||
} |