Skip to content

Commit

Permalink
Support #35284 - Add attachments on MolecularAnalysisRun
Browse files Browse the repository at this point in the history
- Started working on implementing this for the sanger workflow.
- Tests will need to be updated.
  • Loading branch information
brandonandre committed Dec 3, 2024
1 parent 3f2119a commit 558bcae
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,6 +89,23 @@ export interface UseMolecularAnalysisRunReturn {
sequencingRunItems?: SequencingRunItem[];

columns: ColumnDef<SequencingRunItem>[];

/**
* 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;
}

/**
Expand Down Expand Up @@ -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(
Expand All @@ -244,6 +262,11 @@ export function useMolecularAnalysisRun({
const [sequencingRunItems, setSequencingRunItems] =
useState<SequencingRunItem[]>();

// Sequencing run attachments
const [attachments, setAttachments] = useState<ResourceIdentifierObject[]>(
[]
);

// Network Requests, starting with the SeqReaction
useQuery<SeqReaction[]>(
{
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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, {
Expand Down Expand Up @@ -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();
}
Expand All @@ -521,7 +575,10 @@ export function useMolecularAnalysisRun({
sequencingRunName,
setSequencingRunName,
sequencingRunItems,
columns
columns,
attachments,
setAttachments,
sequencingRunId: sequencingRun?.id
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export function useGenericMolecularAnalysisRun({
if (firstSequencingRun) {
setSequencingRun(firstSequencingRun);
setSequencingRunName(firstSequencingRun.name);
findMolecularAnalysisRunAttachments(firstSequencingRun);
await findMolecularAnalysisRunAttachments(firstSequencingRun);
}
}

Expand Down
35 changes: 33 additions & 2 deletions packages/dina-ui/components/seqdb/seq-workflow/SangerRunStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +33,10 @@ export function SangerRunStep({
setSequencingRunName,
sequencingRunName,
sequencingRunItems,
columns
columns,
attachments,
setAttachments,
sequencingRunId
} = useMolecularAnalysisRun({
editMode,
setEditMode,
Expand Down Expand Up @@ -124,6 +129,32 @@ export function SangerRunStep({
sort={[{ id: "wellCoordinates", desc: false }]}
/>
</div>
<div className="col-12 mt-3">
<DinaForm initialValues={{}}>
{editMode ? (
<AttachmentsEditor
attachmentPath={``}
name="attachments"
onChange={setAttachments}
value={attachments}
title={
<DinaMessage id="molecularAnalysisRunStep_attachments" />
}
/>
) : (
<>
{sequencingRunId && (
<AttachmentReadOnlySection
attachmentPath={`seqdb-api/molecular-analysis-run/${sequencingRunId}/attachments`}
title={
<DinaMessage id="molecularAnalysisRunStep_attachments" />
}
/>
)}
</>
)}
</DinaForm>
</div>
</div>
) : (
<div className="row">
Expand Down

0 comments on commit 558bcae

Please sign in to comment.