From 558bcaefb3b24b4c35bb94e34c9c78b13625030c Mon Sep 17 00:00:00 2001 From: BrandonAndre Date: Tue, 3 Dec 2024 13:18:24 -0500 Subject: [PATCH] Support #35284 - Add attachments on MolecularAnalysisRun - Started working on implementing this for the sanger workflow. - Tests will need to be updated. --- .../useMolecularAnalysisRun.tsx | 73 +++++++++++++++++-- .../useGenericMolecularAnalysisRun.tsx | 2 +- .../seqdb/seq-workflow/SangerRunStep.tsx | 35 ++++++++- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/packages/dina-ui/components/molecular-analysis/useMolecularAnalysisRun.tsx b/packages/dina-ui/components/molecular-analysis/useMolecularAnalysisRun.tsx index 475d62270..9d2551849 100644 --- a/packages/dina-ui/components/molecular-analysis/useMolecularAnalysisRun.tsx +++ b/packages/dina-ui/components/molecular-analysis/useMolecularAnalysisRun.tsx @@ -20,6 +20,7 @@ import { attachGenericMolecularAnalysisItems } from "../seqdb/molecular-analysis import { GenericMolecularAnalysisItem } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysisItem"; import { MolecularAnalysisRunItem } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem"; import { MolecularAnalysisRun } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRun"; +import { ResourceIdentifierObject } from "jsonapi-typescript"; export interface UseMolecularAnalysisRunProps { seqBatchId: string; @@ -88,6 +89,23 @@ export interface UseMolecularAnalysisRunReturn { sequencingRunItems?: SequencingRunItem[]; columns: ColumnDef[]; + + /** + * UUID of the sequencing run. + */ + sequencingRunId?: string; + + /** + * Displays the current attachments. This is used since the run not might exist yet and can't + * be saved directly. + */ + attachments: ResourceIdentifierObject[]; + + /** + * Set the current attachments. This is used since the run not might exist yet and can't + * be saved directly. + */ + setAttachments: (newMetadatas: ResourceIdentifierObject[]) => void; } /** @@ -222,7 +240,7 @@ export function useMolecularAnalysisRun({ performSave, setPerformSave }: UseMolecularAnalysisRunProps): UseMolecularAnalysisRunReturn { - const { bulkGet, save } = useApiClient(); + const { bulkGet, save, apiClient } = useApiClient(); const { formatMessage } = useDinaIntl(); const { compareByStringAndNumber } = useStringComparator(); const columns = getMolecularAnalysisRunColumns( @@ -244,6 +262,11 @@ export function useMolecularAnalysisRun({ const [sequencingRunItems, setSequencingRunItems] = useState(); + // Sequencing run attachments + const [attachments, setAttachments] = useState( + [] + ); + // Network Requests, starting with the SeqReaction useQuery( { @@ -305,6 +328,25 @@ export function useMolecularAnalysisRun({ if (firstSequencingRun) { setSequencingRun(firstSequencingRun); setSequencingRunName(firstSequencingRun.name); + await findMolecularAnalysisRunAttachments(firstSequencingRun); + } + } + + async function findMolecularAnalysisRunAttachments( + run: MolecularAnalysisRun + ) { + // Only perform the request if a sequencing run exists. + if (run?.id) { + const runQuery = await apiClient.get( + `seqdb-api/molecular-analysis-run/${run?.id}`, + { + include: "attachments" + } + ); + + if (runQuery && (runQuery as any)?.data?.attachments) { + setAttachments((runQuery as any)?.data?.attachments); + } } } @@ -365,8 +407,15 @@ export function useMolecularAnalysisRun({ resource: { type: "molecular-analysis-run", name: sequencingRunName, - group: groupName - } + group: groupName, + ...(attachments.length > 0 && { + relationships: { + attachments: { + data: attachments + } + } + }) + } as any } ]; const savedMolecularAnalysisRun = await save( @@ -444,7 +493,7 @@ export function useMolecularAnalysisRun({ } } - async function updateSequencingName() { + async function updateSequencingRun() { // Sequencing run needs an id to update. if (!sequencingRun?.id) { setPerformSave(false); @@ -461,8 +510,13 @@ export function useMolecularAnalysisRun({ resource: { id: sequencingRun.id, type: "molecular-analysis-run", - name: sequencingRunName - } + name: sequencingRunName, + relationships: { + attachments: { + data: attachments + } + } + } as any } ]; await save(molecularAnalysisRunSaveArg, { @@ -507,7 +561,7 @@ export function useMolecularAnalysisRun({ // Determine if a new run should be created or update the existing one. if (sequencingRun) { - updateSequencingName(); + updateSequencingRun(); } else { createNewRun(); } @@ -521,7 +575,10 @@ export function useMolecularAnalysisRun({ sequencingRunName, setSequencingRunName, sequencingRunItems, - columns + columns, + attachments, + setAttachments, + sequencingRunId: sequencingRun?.id }; } diff --git a/packages/dina-ui/components/seqdb/molecular-analysis-workflow/useGenericMolecularAnalysisRun.tsx b/packages/dina-ui/components/seqdb/molecular-analysis-workflow/useGenericMolecularAnalysisRun.tsx index fd12e2f9b..bbe093a44 100644 --- a/packages/dina-ui/components/seqdb/molecular-analysis-workflow/useGenericMolecularAnalysisRun.tsx +++ b/packages/dina-ui/components/seqdb/molecular-analysis-workflow/useGenericMolecularAnalysisRun.tsx @@ -239,7 +239,7 @@ export function useGenericMolecularAnalysisRun({ if (firstSequencingRun) { setSequencingRun(firstSequencingRun); setSequencingRunName(firstSequencingRun.name); - findMolecularAnalysisRunAttachments(firstSequencingRun); + await findMolecularAnalysisRunAttachments(firstSequencingRun); } } diff --git a/packages/dina-ui/components/seqdb/seq-workflow/SangerRunStep.tsx b/packages/dina-ui/components/seqdb/seq-workflow/SangerRunStep.tsx index b734e057c..ea7db7c8b 100644 --- a/packages/dina-ui/components/seqdb/seq-workflow/SangerRunStep.tsx +++ b/packages/dina-ui/components/seqdb/seq-workflow/SangerRunStep.tsx @@ -4,9 +4,11 @@ import { SequencingRunItem, useMolecularAnalysisRun } from "../../molecular-analysis/useMolecularAnalysisRun"; -import { LoadingSpinner, ReactTable } from "common-ui"; +import { DinaForm, LoadingSpinner, ReactTable } from "common-ui"; import { Alert } from "react-bootstrap"; import { DinaMessage } from "../../../intl/dina-ui-intl"; +import { AttachmentsEditor } from "../../object-store/attachment-list/AttachmentsField"; +import { AttachmentReadOnlySection } from "../../object-store/attachment-list/AttachmentReadOnlySection"; export interface SangerRunStepProps { seqBatchId: string; @@ -31,7 +33,10 @@ export function SangerRunStep({ setSequencingRunName, sequencingRunName, sequencingRunItems, - columns + columns, + attachments, + setAttachments, + sequencingRunId } = useMolecularAnalysisRun({ editMode, setEditMode, @@ -124,6 +129,32 @@ export function SangerRunStep({ sort={[{ id: "wellCoordinates", desc: false }]} /> +
+ + {editMode ? ( + + } + /> + ) : ( + <> + {sequencingRunId && ( + + } + /> + )} + + )} + +
) : (