From ed9f60e9fe18865076e250e07bcb15c1db8f6bbc Mon Sep 17 00:00:00 2001 From: John Phan Date: Fri, 29 Nov 2024 08:51:45 -0800 Subject: [PATCH] 35254 Add metagenomic workflow - Implemented Index Assignment Assign by grid that works with metagenomics batch item - Can select index, save, and load --- .../MetagenomicsIndexAssignmentTable.tsx | 8 +-- .../index-grid/MetagenomicsIndexGrid.tsx | 57 +++++++++++-------- .../useMetagenomicsIndexAssignmentAPI.ts | 10 ++-- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/packages/dina-ui/components/seqdb/ngs-workflow/MetagenomicsIndexAssignmentTable.tsx b/packages/dina-ui/components/seqdb/ngs-workflow/MetagenomicsIndexAssignmentTable.tsx index 63822b5a0..c200a8aa9 100644 --- a/packages/dina-ui/components/seqdb/ngs-workflow/MetagenomicsIndexAssignmentTable.tsx +++ b/packages/dina-ui/components/seqdb/ngs-workflow/MetagenomicsIndexAssignmentTable.tsx @@ -22,7 +22,7 @@ import { } from "./useMetagenomicsIndexAssignmentAPI"; interface MetagenomicsIndexAssignmentRow { - materialSample?: MaterialSampleSummary; + materialSampleSummary?: MaterialSampleSummary; metagenomicsIndexAssignmentResource?: MetagenomicsIndexAssignmentResource; pcrBatchItem?: PcrBatchItem; } @@ -41,7 +41,7 @@ export function MetagenomicsIndexAssignmentTable( setPerformSave, loading, metagenomicsIndexAssignmentResources, - materialSamples, + materialSampleSummaries, ngsIndexes, onSubmitTable } = props; @@ -153,13 +153,13 @@ export function MetagenomicsIndexAssignmentTable( ? metagenomicsIndexAssignmentResources.map( (prep) => ({ metagenomicsIndexAssignmentResource: prep, - materialSample: materialSamples?.find( + materialSampleSummary: materialSampleSummaries?.find( (samp) => samp.id === prep?.materialSampleSummary?.id ) }) ) : [], - [metagenomicsIndexAssignmentResources, materialSamples] + [metagenomicsIndexAssignmentResources, materialSampleSummaries] ); const initialValues = useMemo(() => { diff --git a/packages/dina-ui/components/seqdb/ngs-workflow/index-grid/MetagenomicsIndexGrid.tsx b/packages/dina-ui/components/seqdb/ngs-workflow/index-grid/MetagenomicsIndexGrid.tsx index d0066198c..f32cb358b 100644 --- a/packages/dina-ui/components/seqdb/ngs-workflow/index-grid/MetagenomicsIndexGrid.tsx +++ b/packages/dina-ui/components/seqdb/ngs-workflow/index-grid/MetagenomicsIndexGrid.tsx @@ -10,7 +10,10 @@ import { LibraryPrep } from "../../../../types/seqdb-api"; import { ColumnDef } from "@tanstack/react-table"; import { useSeqdbIntl } from "packages/dina-ui/intl/seqdb-intl"; import { MetagenomicsIndexAssignmentStepProps } from "../../metagenomics-workflow/MetagenomicsIndexAssignmentStep"; -import { UseMetagenomicsIndexAssignmentReturn } from "../useMetagenomicsIndexAssignmentAPI"; +import { + MetagenomicsIndexAssignmentResource, + UseMetagenomicsIndexAssignmentReturn +} from "../useMetagenomicsIndexAssignmentAPI"; interface CellData { row: number; @@ -23,19 +26,20 @@ interface MetagenomicsIndexGridProps export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) { const { pcrBatch, + metagenomicsBatch, editMode, performSave, setPerformSave, - loading: libraryPrepsLoading, - metagenomicsIndexAssignmentResources: libraryPreps, - materialSamples, + loading, + metagenomicsIndexAssignmentResources, + materialSampleSummaries, ngsIndexes, storageUnitType, onSubmitGrid } = props; const { formatMessage } = useSeqdbIntl(); - const { indexSet } = pcrBatch; + const { indexSet } = metagenomicsBatch; // Hidden button bar is used to submit the page from the button bar in a parent component. const hiddenButtonBar = ( @@ -46,7 +50,7 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) { /> ); - if (libraryPrepsLoading) { + if (loading) { return ; } @@ -58,14 +62,16 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) { ); } - if (libraryPreps) { - const libraryPrepsWithCoords = libraryPreps.filter( - (prep) => - prep.storageUnitUsage?.wellRow && prep.storageUnitUsage?.wellColumn - ); + if (metagenomicsIndexAssignmentResources) { + const indexAssignmentResourcesWithCoords = + metagenomicsIndexAssignmentResources.filter( + (indexAssignmentResource) => + indexAssignmentResource.storageUnitUsage?.wellRow && + indexAssignmentResource.storageUnitUsage?.wellColumn + ); // Display an error if no coordinates have been selected yet, nothing to edit. - if (libraryPrepsWithCoords.length === 0) { + if (indexAssignmentResourcesWithCoords.length === 0) { return (
{formatMessage("missingSelectedCoordinatesForAssignment")} @@ -73,11 +79,11 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) { ); } - const cellGrid: { [key: string]: LibraryPrep } = {}; - for (const prep of libraryPrepsWithCoords) { + const cellGrid: { [key: string]: MetagenomicsIndexAssignmentResource } = {}; + for (const resource of indexAssignmentResourcesWithCoords) { cellGrid[ - `${prep.storageUnitUsage?.wellRow}_${prep.storageUnitUsage?.wellColumn}` - ] = prep; + `${resource.storageUnitUsage?.wellRow}_${resource.storageUnitUsage?.wellColumn}` + ] = resource; } const columns: ColumnDef[] = []; @@ -134,26 +140,29 @@ export function MetagenomicsIndexGrid(props: MetagenomicsIndexGridProps) { cell: ({ row: { original } }) => { const rowLabel = String.fromCharCode(original.row + 65); const coords = `${rowLabel}_${columnLabel}`; - const prep = cellGrid[coords]; + const indexAssignmentResource: MetagenomicsIndexAssignmentResource = + cellGrid[coords]; - return prep ? ( + return indexAssignmentResource ? (
- {materialSamples?.find( - (sample) => sample.id === prep?.materialSample?.id + {materialSampleSummaries?.find( + (sample) => + sample.id === + indexAssignmentResource?.materialSampleSummary?.id )?.materialSampleName ?? ""}
- {prep.indexI5 && ( + {indexAssignmentResource.indexI5 && (
i5: - {prep.indexI5.name} + {indexAssignmentResource.indexI5.name}
)} - {prep.indexI7 && ( + {indexAssignmentResource.indexI7 && (
i7: - {prep.indexI7.name} + {indexAssignmentResource.indexI7.name}
)}
diff --git a/packages/dina-ui/components/seqdb/ngs-workflow/useMetagenomicsIndexAssignmentAPI.ts b/packages/dina-ui/components/seqdb/ngs-workflow/useMetagenomicsIndexAssignmentAPI.ts index 3a799a1c3..6f6f01b33 100644 --- a/packages/dina-ui/components/seqdb/ngs-workflow/useMetagenomicsIndexAssignmentAPI.ts +++ b/packages/dina-ui/components/seqdb/ngs-workflow/useMetagenomicsIndexAssignmentAPI.ts @@ -27,7 +27,7 @@ import { MetagenomicsBatchItem } from "packages/dina-ui/types/seqdb-api/resource export interface UseMetagenomicsIndexAssignmentReturn { loading: boolean; metagenomicsIndexAssignmentResources?: MetagenomicsIndexAssignmentResource[]; - materialSamples?: MaterialSampleSummary[]; + materialSampleSummaries?: MaterialSampleSummary[]; ngsIndexes?: NgsIndex[]; storageUnitType?: StorageUnitType; protocol?: Protocol; @@ -62,7 +62,7 @@ export function useMetagenomicsIndexAssignmentAPI({ metagenomicsIndexAssignmentResources, setMetagenomicsIndexAssignmentResources ] = useState([]); - const [materialSamples, setMaterialSamples] = + const [materialSampleSummaries, setMaterialSamples] = useState(); const [ngsIndexes, setNgsIndexes] = useState(); const [protocol, setProtocol] = useState(); @@ -274,8 +274,8 @@ export function useMetagenomicsIndexAssignmentAPI({ } const saveOps: SaveArgs[] = toPairs(edits).map(([id, prepEdit]) => ({ - resource: { id, type: "library-prep", ...prepEdit }, - type: "library-prep" + resource: { id, type: "metagenomics-batch-item", ...prepEdit }, + type: "metagenomics-batch-item" })); await save(saveOps, { apiBaseUrl: "/seqdb-api" }); @@ -354,7 +354,7 @@ export function useMetagenomicsIndexAssignmentAPI({ return { loading, metagenomicsIndexAssignmentResources, - materialSamples, + materialSampleSummaries, ngsIndexes, storageUnitType, protocol,