From b11618bcaf873916ba4eef697d800ce099c39483 Mon Sep 17 00:00:00 2001 From: James Hadfield Date: Fri, 19 Mar 2021 13:01:03 +1300 Subject: [PATCH] Allow node_traits to define their own URLs This extends our interpretation of dataset-supplied traits to allow them to define a URL as well as a value. If a url is specified, then the value (in the tip-clicked panel) is rendered as a link. Closes #1307 --- src/components/tree/infoPanels/click.js | 11 ++++++++--- src/util/treeMiscHelpers.js | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/components/tree/infoPanels/click.js b/src/components/tree/infoPanels/click.js index 06da7e1e6..913b9c318 100644 --- a/src/components/tree/infoPanels/click.js +++ b/src/components/tree/infoPanels/click.js @@ -96,8 +96,7 @@ const MutationTable = ({mutations}) => { const AccessionAndUrl = ({node}) => { - const accession = getAccessionFromNode(node); - const url = getUrlFromNode(node); + const {accession, url} = getAccessionFromNode(node); const genbank_accession = getTraitFromNode(node, "genbank_accession"); /* `gisaid_epi_isl` is a special value attached to nodes introduced during the 2019 nCoV outbreak. @@ -230,10 +229,16 @@ const Trait = ({node, trait, colorings}) => { value = Number.parseFloat(value_tmp).toPrecision(3); } } + if (!isValueValid(value)) return null; + const name = (colorings && colorings[trait] && colorings[trait].title) ? colorings[trait].title : trait; - return isValueValid(value) ? item(name, value) : null; + const url = getUrlFromNode(node, trait); + if (url) { + return ; + } + return item(name, value); }; /** diff --git a/src/util/treeMiscHelpers.js b/src/util/treeMiscHelpers.js index 6f003b4e7..b057084cd 100644 --- a/src/util/treeMiscHelpers.js +++ b/src/util/treeMiscHelpers.js @@ -69,15 +69,25 @@ export const getFullAuthorInfoFromNode = (node) => export const getAccessionFromNode = (node) => { /* see comment at top of this file */ - if (node.node_attrs && node.node_attrs.accession) { - return node.node_attrs.accession; + let accession, url; + if (node.node_attrs) { + if (isValueValid(node.node_attrs.accession)) { + accession = node.node_attrs.accession; + } + if (typeof node.node_attrs.url === "string") { + url = node.node_attrs.url; + } } - return undefined; + return {accession, url}; }; /* see comment at top of this file */ -export const getUrlFromNode = (node) => - (node.node_attrs && node.node_attrs.url) ? node.node_attrs.url : undefined; +export const getUrlFromNode = (node, trait) => { + if (node.node_attrs && node.node_attrs[trait] && typeof node.node_attrs[trait].url === "string") { + return node.node_attrs[trait].url; + } + return undefined; +}; /** * Traverses the tree and returns a set of genotype states such as