Skip to content

Commit

Permalink
Support #35538 - Molecular Analysis Run view page bug and test coverage
Browse files Browse the repository at this point in the history
- Created an enum for the different usage types for molecular analysis run items.
- Refactored all usage types to use the new enums.
- Added a mock for the run items.
- Tweaked what should happen if no run items are loaded in.
  • Loading branch information
brandonandre committed Jan 14, 2025
1 parent 6394cfb commit aac4766
Show file tree
Hide file tree
Showing 16 changed files with 216 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { PcrBatchItem } from "../../types/seqdb-api";
import { MolecularAnalysisRunItem } from "../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import { useEffect, useState } from "react";
import {
BulkGetOptions,
Expand Down Expand Up @@ -405,7 +408,8 @@ export function useMetagenomicsWorkflowMolecularAnalysisRun({
type: "molecular-analysis-run-item",
resource: {
type: "molecular-analysis-run-item",
usageType: "metagenomics-batch-item",
usageType:
MolecularAnalysisRunItemUsageType.METAGENOMICS_BATCH_ITEM,
...(molecularAnalysisRunItemName && {
name: molecularAnalysisRunItemName
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { KitsuResource, PersistedResource } from "kitsu";
import { MaterialSampleSummary } from "../../types/collection-api";
import { useDinaIntl } from "../../intl/dina-ui-intl";
import { ColumnDef } from "@tanstack/react-table";
import { MolecularAnalysisRunItem } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../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";
import { useMolecularAnalysisRunColumns } from "./useMolecularAnalysisRunColumns";
Expand Down Expand Up @@ -440,7 +443,7 @@ export function useMolecularAnalysisRun({
type: "molecular-analysis-run-item",
resource: {
type: "molecular-analysis-run-item",
usageType: "seq-reaction",
usageType: MolecularAnalysisRunItemUsageType.SEQ_REACTION,
...(molecularAnalysisRunItemName && {
name: molecularAnalysisRunItemName
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { filterBy, useApiClient, useQuery } from "common-ui";
import { PersistedResource } from "kitsu";
import { attachGenericMolecularAnalysisItems } from "../seqdb/molecular-analysis-workflow/useGenericMolecularAnalysisRun";
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 {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import { MetagenomicsBatchItem } from "packages/dina-ui/types/seqdb-api/resources/metagenomics/MetagenomicsBatchItem";
import {
attachMaterialSampleSummaryMetagenomics,
Expand Down Expand Up @@ -35,18 +38,24 @@ export function useMolecularAnalysisRunView({
molecularAnalysisRunId
}: UseMolecularAnalysisRunViewProps) {
const { apiClient, bulkGet } = useApiClient();

const [columns, setColumns] = useState<any[]>([]);

// Run Items
const [sequencingRunItems, setSequencingRunItems] =
useState<SequencingRunItem[]>();

const [loading, setLoading] = useState<boolean>(true);

// Quality control items
const [qualityControls, setQualityControls] = useState<QualityControl[]>([]);

// Quality control type vocabulary options, mainly used for localization.
const { loading: loadingVocabularyItems, vocabOptions: qualityControlTypes } =
useVocabularyOptions({
path: "seqdb-api/vocabulary/qualityControlType"
});

const molecularAnalysisRunItemQuery = useQuery<MolecularAnalysisRunItem[]>(
{
path: `seqdb-api/molecular-analysis-run-item`,
Expand Down Expand Up @@ -77,7 +86,11 @@ export function useMolecularAnalysisRunView({

async function fetchGenericMolecularAnalysisItems() {
const fetchPaths = molecularAnalysisRunItems
.filter((runItem) => runItem.usageType !== "quality-control")
.filter(
(runItem) =>
runItem.usageType !==
MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
)
.map(
(molecularAnalysisRunItem) =>
`seqdb-api/generic-molecular-analysis-item?include=storageUnitUsage,materialSample,molecularAnalysisRunItem&filter[rsql]=molecularAnalysisRunItem.uuid==${molecularAnalysisRunItem.id}`
Expand Down Expand Up @@ -111,14 +124,13 @@ export function useMolecularAnalysisRunView({
return metagenomicsBatchItems;
}

const usageType = molecularAnalysisRunItems.filter(
(runItem) => runItem.usageType !== "quality-control"
)?.[0]?.usageType;

if (!usageType) {
setLoading(false);
return;
}
const usageType =
molecularAnalysisRunItems.filter(
(runItem) =>
runItem.usageType !==
MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
)?.[0]?.usageType ??
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM;

setColumns(
useMolecularAnalysisRunColumns({
Expand All @@ -127,7 +139,7 @@ export function useMolecularAnalysisRunView({
})
);

if (usageType === "seq-reaction") {
if (usageType === MolecularAnalysisRunItemUsageType.SEQ_REACTION) {
let seqReactions = await fetchSeqReactions();
seqReactions = seqReactions.filter((item) => item !== undefined);

Expand All @@ -150,7 +162,10 @@ export function useMolecularAnalysisRunView({
// All finished loading.
setSequencingRunItems(sequencingRunItemsChain);
setLoading(false);
} else if (usageType === "generic-molecular-analysis-item") {
} else if (
usageType ===
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM
) {
let genericMolecularAnalysisItems =
await fetchGenericMolecularAnalysisItems();
genericMolecularAnalysisItems = genericMolecularAnalysisItems.filter(
Expand All @@ -172,7 +187,9 @@ export function useMolecularAnalysisRunView({
);

const qualityControlRunItems = molecularAnalysisRunItems.filter(
(runItem) => runItem.usageType === "quality-control"
(runItem) =>
runItem.usageType ===
MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
);

// Get quality controls
Expand Down Expand Up @@ -212,7 +229,10 @@ export function useMolecularAnalysisRunView({
// All finished loading.
setSequencingRunItems(sequencingRunItemsChain);
setLoading(false);
} else if (usageType === "metagenomics-batch-item") {
} else if (
usageType ===
MolecularAnalysisRunItemUsageType.METAGENOMICS_BATCH_ITEM
) {
let metagenomicsBatchItems = await fetchMetagenomicsBatchItems();
metagenomicsBatchItems = metagenomicsBatchItems.filter(
(item) => item !== undefined
Expand Down Expand Up @@ -242,6 +262,7 @@ export function useMolecularAnalysisRunView({
}
}
);

return {
loading:
molecularAnalysisRunItemQuery.loading ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import { SeqdbMessage } from "../../../intl/seqdb-intl";
import { useMaterialSampleRelationshipColumns } from "../../collection/material-sample/useMaterialSampleRelationshipColumns";
import { GenericMolecularAnalysis } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysis";
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 {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";

export interface MolecularAnalysisSampleSelectionStepProps {
molecularAnalysisId: string;
Expand Down Expand Up @@ -235,7 +238,8 @@ export function MolecularAnalysisSampleSelectionStep({
itemsToCreate.map((_) => ({
resource: {
type: "molecular-analysis-run-item",
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
relationships: {
run: {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import { Metadata } from "packages/dina-ui/types/objectstore-api";
import { GenericMolecularAnalysis } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysis";
import { GenericMolecularAnalysisItem } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysisItem";
import { MolecularAnalysisRun } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRun";
import { MolecularAnalysisRunItem } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import { QualityControl } from "packages/dina-ui/types/seqdb-api/resources/QualityControl";
import { Group } from "packages/dina-ui/types/user-api";

Expand Down Expand Up @@ -609,14 +612,14 @@ export const TEST_QUALITY_CONTROL_RUN_ITEMS: PersistedResource<MolecularAnalysis
type: "molecular-analysis-run-item",
createdBy: "dina-admin",
createdOn: "2024-12-11T20:52:48.43824Z",
usageType: "quality-control"
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
},
{
id: "e9e39b72-ece7-454b-893a-2fc2d075e7b7",
type: "molecular-analysis-run-item",
createdBy: "dina-admin",
createdOn: "2024-12-11T20:52:48.43824Z",
usageType: "quality-control"
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import "@testing-library/jest-dom";
import { waitForElementToBeRemoved } from "@testing-library/react";
import { useState, useEffect } from "react";
import userEvent from "@testing-library/user-event";
import { MolecularAnalysisRunItemUsageType } from "../../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";

const onSavedMock = jest.fn();
const mockSetEditMode = jest.fn();
Expand Down Expand Up @@ -284,7 +285,8 @@ describe("Molecular Analysis Workflow - Step 3 - Molecular Analysis Coordinate S
type: "storage-unit"
},
type: "storage-unit-usage",
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
wellColumn: 1,
wellRow: "A"
},
Expand All @@ -298,7 +300,8 @@ describe("Molecular Analysis Workflow - Step 3 - Molecular Analysis Coordinate S
type: "storage-unit"
},
type: "storage-unit-usage",
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
wellColumn: 2,
wellRow: "A"
},
Expand All @@ -312,7 +315,8 @@ describe("Molecular Analysis Workflow - Step 3 - Molecular Analysis Coordinate S
type: "storage-unit"
},
type: "storage-unit-usage",
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
wellColumn: 3,
wellRow: "A"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
MolecularAnalysisRunStep,
MolecularAnalysisRunStepProps
} from "../MolecularAnalysisRunStep";
import { MolecularAnalysisRunItemUsageType } from "../../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";

const mockGet = jest.fn<any, any>(async (path, params) => {
switch (path) {
Expand All @@ -51,7 +52,8 @@ const mockGet = jest.fn<any, any>(async (path, params) => {
switch (params.filter.rsql) {
case "run.uuid==" +
TEST_MOLECULAR_ANALYSIS_RUN_ID +
";usageType==quality-control":
";usageType==" +
MolecularAnalysisRunItemUsageType.QUALITY_CONTROL:
return { data: TEST_QUALITY_CONTROL_RUN_ITEMS };
}

Expand Down Expand Up @@ -365,7 +367,8 @@ describe("Molecular Analysis Workflow - Step 4 - Molecular Analysis Run Step", (
}
}
},
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
type: "molecular-analysis-run-item"
},
type: "molecular-analysis-run-item"
Expand All @@ -381,7 +384,8 @@ describe("Molecular Analysis Workflow - Step 4 - Molecular Analysis Run Step", (
}
}
},
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
type: "molecular-analysis-run-item"
},
type: "molecular-analysis-run-item"
Expand All @@ -396,7 +400,8 @@ describe("Molecular Analysis Workflow - Step 4 - Molecular Analysis Run Step", (
}
}
},
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
type: "molecular-analysis-run-item"
},
type: "molecular-analysis-run-item"
Expand Down Expand Up @@ -475,7 +480,7 @@ describe("Molecular Analysis Workflow - Step 4 - Molecular Analysis Run Step", (
}
},
type: "molecular-analysis-run-item",
usageType: "quality-control"
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
},
type: "molecular-analysis-run-item"
}
Expand Down Expand Up @@ -644,7 +649,7 @@ describe("Molecular Analysis Workflow - Step 4 - Molecular Analysis Run Step", (
}
},
type: "molecular-analysis-run-item",
usageType: "quality-control"
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
},
type: "molecular-analysis-run-item"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TEST_MOLECULAR_ANALYSIS_RUN_ID,
TEST_SEARCH_RESPONSE
} from "../__mocks__/MolecularAnalysisMocks";
import { MolecularAnalysisRunItemUsageType } from "../../../../types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";

const onSavedMock = jest.fn();
const mockSetEditMode = jest.fn();
Expand Down Expand Up @@ -266,7 +267,8 @@ describe("Molecular Analysis Workflow - Step 2 - Molecular Analysis Sample Selec
}
},
type: "molecular-analysis-run-item",
usageType: "generic-molecular-analysis-item"
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM
},
type: "molecular-analysis-run-item"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { MaterialSampleSummary } from "packages/dina-ui/types/collection-api";
import { useDinaIntl } from "../../../intl/dina-ui-intl";
import { GenericMolecularAnalysisItem } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysisItem";
import { GenericMolecularAnalysis } from "packages/dina-ui/types/seqdb-api/resources/GenericMolecularAnalysis";
import { MolecularAnalysisRunItem } from "packages/dina-ui/types/seqdb-api/resources/molecular-analysis/MolecularAnalysisRunItem";
import {
MolecularAnalysisRunItem,
MolecularAnalysisRunItemUsageType
} from "../../../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";
import { QualityControl } from "packages/dina-ui/types/seqdb-api/resources/QualityControl";
Expand Down Expand Up @@ -437,7 +440,7 @@ export function useGenericMolecularAnalysisRun({
group: "",
name: "",
qcType: "",
type: "quality-control"
type: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
}
]);
}
Expand Down Expand Up @@ -526,7 +529,7 @@ export function useGenericMolecularAnalysisRun({
{
selector: "usageType",
comparison: "==",
arguments: "quality-control"
arguments: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL
}
]
})("")
Expand Down Expand Up @@ -621,7 +624,8 @@ export function useGenericMolecularAnalysisRun({
type: "molecular-analysis-run-item",
resource: {
type: "molecular-analysis-run-item",
usageType: "generic-molecular-analysis-item",
usageType:
MolecularAnalysisRunItemUsageType.GENERIC_MOLECULAR_ANALYSIS_ITEM,
...(molecularAnalysisRunItemName && {
name: molecularAnalysisRunItemName
}),
Expand Down Expand Up @@ -668,7 +672,7 @@ export function useGenericMolecularAnalysisRun({
type: "molecular-analysis-run-item",
resource: {
type: "molecular-analysis-run-item",
usageType: "quality-control",
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL,
relationships: {
run: {
data: {
Expand Down Expand Up @@ -808,7 +812,7 @@ export function useGenericMolecularAnalysisRun({
type: "molecular-analysis-run-item",
resource: {
type: "molecular-analysis-run-item",
usageType: "quality-control",
usageType: MolecularAnalysisRunItemUsageType.QUALITY_CONTROL,
relationships: {
run: {
data: {
Expand Down
Loading

0 comments on commit aac4766

Please sign in to comment.