Skip to content

Commit

Permalink
Allow node_traits to define their own URLs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jameshadfield committed Mar 19, 2021
1 parent d7091fc commit b11618b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/components/tree/infoPanels/click.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 <Link title={name} url={formatURL(url)} value={value}/>;
}
return item(name, value);
};

/**
Expand Down
20 changes: 15 additions & 5 deletions src/util/treeMiscHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b11618b

Please sign in to comment.