From 5f94111fc59d23d4d273dcc1959b94186ab6a152 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Thu, 27 Jun 2024 11:12:11 +1200 Subject: [PATCH 1/2] [second tree control] Refactor filter fn The previous code used `.filter` in a rather strange way! There should be no changes here, although the new code does ensure the displayed options don't include any duplicates and accounts for situations where the `secondTreeOptions` key is not defined. --- src/components/controls/choose-second-tree.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/components/controls/choose-second-tree.js b/src/components/controls/choose-second-tree.js index 296c9d8a3..73267b83f 100644 --- a/src/components/controls/choose-second-tree.js +++ b/src/components/controls/choose-second-tree.js @@ -26,14 +26,12 @@ class ChooseSecondTree extends React.Component { .replace(/\/$/, '') .split(':')[0]; - let options = []; - this.props.available.datasets - .filter((dataset) => { - if (dataset.request === displayedDataset) { - options = [...dataset.secondTreeOptions]; - } - return null; - }); + const options = [...new Set( + this.props.available.datasets + .filter((dataset) => dataset.request === displayedDataset) + .flatMap((dataset) => dataset.secondTreeOptions) + .filter((opt) => !!opt) // .secondTreeOptions is not required + )] if (this.props.showTreeToo) options.unshift("REMOVE"); From e626f99d9d0baf93626c26392ab97b7d5ca32798 Mon Sep 17 00:00:00 2001 From: james hadfield Date: Thu, 27 Jun 2024 11:20:13 +1200 Subject: [PATCH 2/2] [second tree control] show only when available Don't display the sidebar UI if we're just going to display an empty dropdown! See for context --- CHANGELOG.md | 3 +++ src/components/controls/choose-second-tree.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index be0ecf2e8..c720c0b0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +* We no longer show the "second tree" sidebar dropdown when there are no available options. The possible options are defined by [the charon/getAvailable API](https://docs.nextstrain.org/projects/auspice/en/stable/server/api.html) response and as such vary depending on the server in use. ([#1795](https://github.com/nextstrain/auspice/pull/1795)) + + ## version 2.55.1 - 2024/06/25 diff --git a/src/components/controls/choose-second-tree.js b/src/components/controls/choose-second-tree.js index 73267b83f..b7a8766ba 100644 --- a/src/components/controls/choose-second-tree.js +++ b/src/components/controls/choose-second-tree.js @@ -33,6 +33,9 @@ class ChooseSecondTree extends React.Component { .filter((opt) => !!opt) // .secondTreeOptions is not required )] + // Don't display the sidebar UI if we're just going to display an empty dropdown! + if (!options.length) return null; + if (this.props.showTreeToo) options.unshift("REMOVE"); const selectOptions = options.map((opt) => ({value: opt, label: opt}));