From df43bd68953557c64fa311c9ce417c027acda486 Mon Sep 17 00:00:00 2001 From: Erin Hoops <109251328+ehoops-cz@users.noreply.github.com> Date: Tue, 30 Jul 2024 12:59:55 -0700 Subject: [PATCH] feat: Update cell strain links. (#968) Resolves #912 Rather than adding additional logic to the InfoLink component that would only be used for cell strains, this adds a specific CellStrainInfoLink. This PR also moves the InfoLink components to their own files. Lastly, this PR uses the fractal file structure - it fits here anyway, but it would be great to know if there's broader buy in for using this pattern. If so, I'll move over the Hygen template from CZID so we won't have to manually set up the folder/file structure for each component we add. --- .../SampleAndExperimentConditionsTable.tsx | 39 ++-------------- .../components/InfoLink/InfoLink.tsx | 44 +++++++++++++++++++ .../components/InfoLink/index.ts | 1 + .../index.ts | 1 + .../app/constants/datasetInfoLinks.ts | 7 ++- 5 files changed, 56 insertions(+), 36 deletions(-) rename frontend/packages/data-portal/app/components/Dataset/{ => SampleAndExperimentConditionsTable}/SampleAndExperimentConditionsTable.tsx (71%) create mode 100644 frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/InfoLink.tsx create mode 100644 frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/index.ts create mode 100644 frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/index.ts diff --git a/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable.tsx b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/SampleAndExperimentConditionsTable.tsx similarity index 71% rename from frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable.tsx rename to frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/SampleAndExperimentConditionsTable.tsx index cbe46f465..5e13287cc 100644 --- a/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable.tsx +++ b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/SampleAndExperimentConditionsTable.tsx @@ -1,35 +1,9 @@ import { AccordionMetadataTable } from 'app/components/AccordionMetadataTable' -import { Link } from 'app/components/Link' -import { NIH, OBO } from 'app/constants/datasetInfoLinks' +import { DatasetType } from 'app/components/Dataset/type' import { useI18n } from 'app/hooks/useI18n' import { getTableData } from 'app/utils/table' -import { DatasetType } from './type' - -function InfoLink({ - value, - id, - isOBO, -}: { - value?: string | null - id?: string | null - isOBO?: boolean -}) { - if (!value) { - return -- - } - - if (id) { - const link = `${isOBO ? OBO : NIH}${isOBO ? id.replaceAll(':', '_') : id}` - return ( - - {value} - - ) - } - - return {value} -} +import { InfoLink } from './components/InfoLink' export function SampleAndExperimentConditionsTable({ dataset, @@ -57,18 +31,14 @@ export function SampleAndExperimentConditionsTable({ { label: t('tissueName'), renderValue: () => { - return ( - - ) + return }, values: [], }, { label: t('cellName'), renderValue: () => { - return ( - - ) + return }, values: [], }, @@ -91,7 +61,6 @@ export function SampleAndExperimentConditionsTable({ ) }, diff --git a/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/InfoLink.tsx b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/InfoLink.tsx new file mode 100644 index 000000000..a6f97ae26 --- /dev/null +++ b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/InfoLink.tsx @@ -0,0 +1,44 @@ +import { Link } from 'app/components/Link' +import { + NCBI, + NCBI_ONTOLOGY_PATTERN, + OBO, + OBO_PATTERN, + WORMBASE, + WORMBASE_PATTERN, +} from 'app/constants/datasetInfoLinks' + +export function InfoLink({ + value, + id, +}: { + value?: string | null + id?: string | null +}) { + if (!value) { + return -- + } + + if (id) { + let link + if (typeof id === 'number') { + link = `${NCBI}${id as number}` + } else if (id.match(NCBI_ONTOLOGY_PATTERN)) { + link = `${NCBI}${id.replace('NCBITaxon:', '')}` + } else if (id.match(WORMBASE_PATTERN)) { + link = `${WORMBASE}${id.replaceAll(':', '_')}` + } else if (id.match(OBO_PATTERN)) { + link = `${OBO}${id.replaceAll(':', '_')}` + } + // don't link if no patterns match + if (link) { + return ( + + {value} + + ) + } + } + + return {value} +} diff --git a/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/index.ts b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/index.ts new file mode 100644 index 000000000..f66cca4b8 --- /dev/null +++ b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/components/InfoLink/index.ts @@ -0,0 +1 @@ +export { InfoLink } from './InfoLink' diff --git a/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/index.ts b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/index.ts new file mode 100644 index 000000000..06ff086a3 --- /dev/null +++ b/frontend/packages/data-portal/app/components/Dataset/SampleAndExperimentConditionsTable/index.ts @@ -0,0 +1 @@ +export { SampleAndExperimentConditionsTable } from './SampleAndExperimentConditionsTable' diff --git a/frontend/packages/data-portal/app/constants/datasetInfoLinks.ts b/frontend/packages/data-portal/app/constants/datasetInfoLinks.ts index f1c9a29c6..4cd45374e 100644 --- a/frontend/packages/data-portal/app/constants/datasetInfoLinks.ts +++ b/frontend/packages/data-portal/app/constants/datasetInfoLinks.ts @@ -1,3 +1,8 @@ -export const NIH = +export const NCBI = 'https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=' export const OBO = 'http://purl.obolibrary.org/obo/' +export const WORMBASE = 'https://wormbase.org/species/c_elegans/strain/' + +export const NCBI_ONTOLOGY_PATTERN = /NCBITaxon:[0-9]+/ +export const OBO_PATTERN = /[a-zA-Z]+:[0-9]+/ +export const WORMBASE_PATTERN = /WBStrain[0-9]{8}/