Skip to content

Commit

Permalink
nextstrain#1055: npm run lint; show selected tips download option onl…
Browse files Browse the repository at this point in the history
…y if any tips are selected
  • Loading branch information
frogsquire committed Apr 17, 2020
1 parent 8a7a649 commit 2138543
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
20 changes: 11 additions & 9 deletions src/components/download/downloadModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -179,11 +179,13 @@ class DownloadModal extends React.Component {
["TimeTree", "Phylogenetic tree in Newick format with branch lengths measured in years.",
(<RectangularTreeIcon width={iconWidth} selected />), () => 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}).`,
(<MetaIcon width={iconWidth} selected />), () => 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}).`,
(<MetaIcon width={iconWidth} selected />), () => helpers.strainTSV(this.props.dispatch, filePrefix, this.props.nodes,
this.props.metadata.colorings, true, this.props.tree.visibility)]
(<MetaIcon width={iconWidth} selected />), () => 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}).`,
(<MetaIcon width={iconWidth} selected />), () => 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.`,
(<MetaIcon width={iconWidth} selected />), () => helpers.authorTSV(this.props.dispatch, filePrefix, this.props.tree)]);
Expand All @@ -207,7 +209,7 @@ class DownloadModal extends React.Component {
<label style={buttonLabelStyle}>{data[1]}</label>
</div>
</div>
))}
))}
</div>
</div>
);
Expand Down
5 changes: 2 additions & 3 deletions src/components/download/helperFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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! */
Expand Down

0 comments on commit 2138543

Please sign in to comment.