From 2138543b7678a318874d2406a8742c96b923f146 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 16 Apr 2020 21:22:35 -0500 Subject: [PATCH] #1055: npm run lint; show selected tips download option only if any tips are selected --- src/components/download/downloadModal.js | 20 +++++++++++--------- src/components/download/helperFunctions.js | 5 ++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/components/download/downloadModal.js b/src/components/download/downloadModal.js index 17272da79..c0d042a09 100644 --- a/src/components/download/downloadModal.js +++ b/src/components/download/downloadModal.js @@ -158,11 +158,11 @@ class DownloadModal extends React.Component { return x; } getNumUniqueAuthors(nodes) { - const authors = nodes.map(n => getFullAuthorInfoFromNode(n)) - .filter(a => a && a.value); - const uniqueAuthors = new Set(authors.map(a => a.value)); + const authors = nodes.map((n) => getFullAuthorInfoFromNode(n)) + .filter((a) => a && a.value); + const uniqueAuthors = new Set(authors.map((a) => a.value)); return uniqueAuthors.size; - } + } downloadButtons() { // getNumSelectedTips() is redundant work with createSummaryWrapper() below, // and with the check done to make sure the node is visible in strainTSV(), @@ -179,11 +179,13 @@ class DownloadModal extends React.Component { ["TimeTree", "Phylogenetic tree in Newick format with branch lengths measured in years.", (), () => helpers.newick(this.props.dispatch, filePrefix, this.props.nodes[0], true)], ["All Metadata (TSV)", `Per-sample metadata for all samples in the dataset (n = ${this.props.metadata.mainTreeNumTips}).`, - (), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, this.props.metadata.colorings, false, null)], - ["Selected Metadata (TSV)", `Per-sample metadata for strains which are currently displayed (n = ${selectedTipsCount}/${this.props.metadata.mainTreeNumTips}).`, - (), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, - this.props.metadata.colorings, true, this.props.tree.visibility)] + (), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, this.props.metadata.colorings, false, null)] ]; + if (selectedTipsCount > 0) { + buttons.push(["Selected Metadata (TSV)", `Per-sample metadata for strains which are currently displayed (n = ${selectedTipsCount}/${this.props.metadata.mainTreeNumTips}).`, + (), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes, + this.props.metadata.colorings, true, this.props.tree.visibility)]); + } if (helpers.areAuthorsPresent(this.props.tree)) { buttons.push(["Author Metadata (TSV)", `Metadata for all samples in the dataset (n = ${this.props.metadata.mainTreeNumTips}) grouped by their ${uniqueAuthorCount} authors.`, (), () => helpers.authorTSV(this.props.dispatch, filePrefix, this.props.tree)]); @@ -207,7 +209,7 @@ class DownloadModal extends React.Component { - ))} + ))} ); diff --git a/src/components/download/helperFunctions.js b/src/components/download/helperFunctions.js index f2fcd57ac..1836e2f69 100644 --- a/src/components/download/helperFunctions.js +++ b/src/components/download/helperFunctions.js @@ -116,9 +116,8 @@ export const strainTSV = (dispatch, filePrefix, nodes, colorings, selectedNodesO for (const [i, node] of nodes.entries()) { if (node.hasChildren) continue; /* we only consider tips */ - if (selectedNodesOnly && nodeVisibilities - && (nodeVisibilities[i] !== NODE_VISIBLE || !node.inView)) - continue; /* skip unselected nodes if requested */ + if (selectedNodesOnly && nodeVisibilities && + (nodeVisibilities[i] !== NODE_VISIBLE || !node.inView)) {continue;} /* skip unselected nodes if requested */ tipTraitValues[node.name] = {Strain: node.name}; if (!node.node_attrs) continue; /* if this is not set then we don't have any node info! */