diff --git a/frontend/packages/data-portal/app/components/Deposition/MethodLinks/common.tsx b/frontend/packages/data-portal/app/components/Deposition/MethodLinks/common.tsx index 0996c9fef..91ab2ed6a 100644 --- a/frontend/packages/data-portal/app/components/Deposition/MethodLinks/common.tsx +++ b/frontend/packages/data-portal/app/components/Deposition/MethodLinks/common.tsx @@ -1,8 +1,10 @@ import { Icon } from '@czi-sds/components' import { ReactNode } from 'react' +import { Annotation_Method_Link_Type_Enum } from 'app/__generated_v2__/graphql' import { SourceCodeIcon, WeightsIcon } from 'app/components/icons' import { VariantLinkProps } from 'app/components/Link' +import { AnnotationMethodLink } from 'app/types/gql/genericTypes' import { I18nKeys } from 'app/types/i18n' import { METHOD_LINK_TYPES, MethodLinkDataType, MethodLinkType } from './type' @@ -81,3 +83,26 @@ export function generateMethodLinks( ) .map((props) => methodLinkFromVariant(props)) } + +export function generateMethodLinksV2( + links: AnnotationMethodLink[], +): MethodLinkProps[] { + return links + .sort( + (a, b) => + METHOD_LINK_TYPES.indexOf(getLinkType(a)) - + METHOD_LINK_TYPES.indexOf(getLinkType(b)), + ) + .map((link) => ({ + title: link.name ?? '', + url: link.link ?? '', + icon: ICON_MAP[getLinkType(link)], + i18nLabel: METHOD_TYPE_TO_I18N_KEY[getLinkType(link)], + })) +} + +function getLinkType( + link: AnnotationMethodLink, +): Annotation_Method_Link_Type_Enum { + return link.linkType ?? Annotation_Method_Link_Type_Enum.Other +} diff --git a/frontend/packages/data-portal/app/components/Download/ConfigureAnnotationDownloadContent.tsx b/frontend/packages/data-portal/app/components/Download/ConfigureAnnotationDownloadContent.tsx index 20b3b76f0..dccefcdea 100644 --- a/frontend/packages/data-portal/app/components/Download/ConfigureAnnotationDownloadContent.tsx +++ b/frontend/packages/data-portal/app/components/Download/ConfigureAnnotationDownloadContent.tsx @@ -1,51 +1,34 @@ -import { useMemo } from 'react' -import { DeepPartial } from 'utility-types' - -import { AnnotationFileEdge } from 'app/__generated_v2__/graphql' import { useDownloadModalContext } from 'app/context/DownloadModal.context' import { useDownloadModalQueryParamState } from 'app/hooks/useDownloadModalQueryParamState' -import { useRunById } from 'app/hooks/useRunById' import { AnnotationAlignmentCallout } from './AnnotationAlignmentCallout' import { FileFormatDropdown } from './FileFormatDropdown' export function ConfigureAnnotationDownloadContent() { - const { objectShapeType, fileFormat } = useDownloadModalQueryParamState() - const { annotationToDownload, allTomograms } = useDownloadModalContext() - - const fileFormats = useMemo( - () => - annotationToDownload?.files - .filter((annotation) => annotation.shape_type === objectShapeType) - .map((annotation) => annotation.format) ?? [], - [annotationToDownload?.files, objectShapeType], - ) - - const { annotationShapes } = useRunById() - - const isMatchingFormat = (file: DeepPartial) => - file?.node?.format === fileFormat - - const alignmentId = - annotationShapes - .find( - (shape) => - shape.annotation?.id === annotationToDownload?.id && - shape.shapeType === objectShapeType && - shape.annotationFiles.edges.some(isMatchingFormat), - ) - ?.annotationFiles.edges.find(isMatchingFormat)?.node.alignmentId ?? 0 + const { fileFormat } = useDownloadModalQueryParamState() + const { annotationShapeToDownload, allTomograms } = useDownloadModalContext() + + const fileFormats = + annotationShapeToDownload?.annotationFiles.edges.map( + (file) => file.node.format, + ) ?? [] + const annotationFileAlignmentId = + annotationShapeToDownload?.annotationFiles.edges.find( + (file) => file.node.format === fileFormat, + )?.node.alignmentId ?? undefined return ( <> - tomogram.alignment?.id !== alignmentId, - )} - /> + {annotationFileAlignmentId !== undefined && ( + tomogram.alignment?.id !== annotationFileAlignmentId, + )} + /> + )} ) } diff --git a/frontend/packages/data-portal/app/components/Download/ConfigureDownloadContent.tsx b/frontend/packages/data-portal/app/components/Download/ConfigureDownloadContent.tsx index 8094ccbec..c59917df3 100644 --- a/frontend/packages/data-portal/app/components/Download/ConfigureDownloadContent.tsx +++ b/frontend/packages/data-portal/app/components/Download/ConfigureDownloadContent.tsx @@ -9,13 +9,16 @@ import { ConfigureTomogramDownloadContent } from './ConfigureTomogramDownloadCon export function ConfigureDownloadContent() { const { t } = useI18n() - - const { annotationName, annotationId, objectShapeType } = + const { annotationName, annotationId, fileFormat, objectShapeType } = useDownloadModalQueryParamState() - - const { annotationToDownload, datasetTitle, runName, objectName } = + const { annotationShapeToDownload, datasetTitle, runName, objectName } = useDownloadModalContext() + const annotationFileAlignmentId = + annotationShapeToDownload?.annotationFiles.edges.find( + (file) => file.node.format === fileFormat, + )?.node.alignmentId ?? undefined + return ( <> @@ -35,10 +38,10 @@ export function ConfigureDownloadContent() { {objectShapeType && ( )} - {annotationToDownload !== undefined && ( + {annotationFileAlignmentId !== undefined && ( )} diff --git a/frontend/packages/data-portal/app/components/Download/ConfigureTomogramDownloadContent.tsx b/frontend/packages/data-portal/app/components/Download/ConfigureTomogramDownloadContent.tsx index fbe9db468..455efd07c 100644 --- a/frontend/packages/data-portal/app/components/Download/ConfigureTomogramDownloadContent.tsx +++ b/frontend/packages/data-portal/app/components/Download/ConfigureTomogramDownloadContent.tsx @@ -29,7 +29,7 @@ export function ConfigureTomogramDownloadContent() { const { tomogramToDownload, - allAnnotationFiles = [], + allAnnotationShapes = [], allTomograms = [], runId, } = useDownloadModalContext() @@ -84,7 +84,7 @@ export function ConfigureTomogramDownloadContent() { tomogram.id.toString() === referenceTomogramId, ) + const annotationFileAlignmentId = + annotationShapeToDownload?.annotationFiles.edges.find( + (file) => file.node.format === fileFormat, + )?.node.alignmentId ?? undefined const DownloadTabContent = DOWNLOAD_TAB_MAP[selectedTab] return ( @@ -115,16 +119,10 @@ export function DownloadOptionsContent() { value={getTomogramName(referenceTomogram)} /> )} - {annotationToDownload && tomogramToDownload?.alignment && ( + {annotationFileAlignmentId !== undefined && ( - )} - {annotationToDownload && ( - )} {fileFormat && ( @@ -163,11 +161,16 @@ export function DownloadOptionsContent() { - {annotationToDownload !== undefined && tomogramToDownload?.alignment ? ( + {annotationFileAlignmentId !== undefined ? ( + tomogram.alignment?.id !== annotationFileAlignmentId, + ) ?? [] + } /> ) : ( diff --git a/frontend/packages/data-portal/app/components/Download/FileFormatDropdown.tsx b/frontend/packages/data-portal/app/components/Download/FileFormatDropdown.tsx index ad4d7c26e..f5d52411a 100644 --- a/frontend/packages/data-portal/app/components/Download/FileFormatDropdown.tsx +++ b/frontend/packages/data-portal/app/components/Download/FileFormatDropdown.tsx @@ -21,6 +21,17 @@ const FILE_FORMAT_TOOLTIP_I18N: Record = { } export const FILE_FORMAT_ORDER = ['mrc', 'zarr', 'ndjson'] +export function getDefaultFileFormat( + availableFormats: string[], +): string | undefined { + for (const fileFormat of FILE_FORMAT_ORDER) { + if (availableFormats.includes(fileFormat)) { + return fileFormat + } + } + + return undefined +} /** * Renders select dropdown with file formats specified in the `fileFormats` @@ -41,7 +52,6 @@ export function FileFormatDropdown({ const matchingFileFormats = FILE_FORMAT_ORDER.filter((format) => fileFormats.includes(format), ) - const defaultFormat = matchingFileFormats[0] const fileFormatOptions = useMemo( () => @@ -53,7 +63,8 @@ export function FileFormatDropdown({ [matchingFileFormats, t], ) - const selectedFormat = fileFormat ?? defaultFormat + const selectedFormat = + fileFormat ?? getDefaultFileFormat(matchingFileFormats)! return (