Skip to content

Commit

Permalink
Make testing for change in selection more robust to insignificant cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
arteymix committed Mar 19, 2024
1 parent 47e77b9 commit 193d063
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
22 changes: 11 additions & 11 deletions src/components/AnnotationSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ export default {
*/
computeSelectedAnnotations(newVal, selectedCategories) {
let sc = new Set(selectedCategories.map(sc => getCategoryId(sc)));
let selectedAnnotations = newVal
return newVal
// exclude annotations from selected categories
.filter(a => !sc.has(a.split(SEPARATOR, 2)[0]))
.map(a => this.annotationById[a]);
selectedAnnotations.forEach(a => {
if (!a) {
console.warn("Term is not selectable");
}
});
return selectedAnnotations.filter(a => a);
.map(id => {
let a = this.annotationById[id];
if (!a) {
console.warn(`Term ${id} is not selectable`);
}
return a;
})
.filter(a => a !== null);
},
/**
* Selected categories.
Expand Down Expand Up @@ -295,10 +295,10 @@ export default {
let sa = this.computeSelectedAnnotations(newVal, sc);
let scOld = this.computeSelectedCategories(oldVal);
let saOld = this.computeSelectedAnnotations(oldVal, scOld);
if (!isEqual(sa, saOld)) {
if (!isEqual(sa.map(this.getId), saOld.map(this.getId))) {
this.$emit("input", sa);
}
if (!isEqual(sc, scOld)) {
if (!isEqual(sc.map(getCategoryId), scOld.map(getCategoryId))) {
this.$emit("update:selectedCategories", sc);
}
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/TaxonSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
</template>

<script>
import { isEqual } from "lodash";
import { formatNumber } from "@/lib/utils";
import { isEqual } from "lodash";
export default {
name: "TaxonSelector",
Expand Down Expand Up @@ -84,6 +84,9 @@ export default {
items[0].children.push(taxonItem);
}
return items[0].children;
},
selectedTaxa() {
return this.taxon.filter(taxon => this.selectedTaxaIds.includes(taxon.id));
}
},
methods: {
Expand All @@ -102,9 +105,9 @@ export default {
value(newVal) {
this.selectedTaxaIds = newVal && newVal.map(t => t.id) || [];
},
selectedTaxaIds(newVal, oldVal) {
if (!isEqual(newVal, oldVal)) {
this.$emit("input", this.taxon.filter(taxon => newVal.includes(taxon.id)));
selectedTaxa(newVal, oldVal) {
if (!isEqual(newVal.map(t => t.id), oldVal.map(t => t.id))) {
this.$emit("input", newVal);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/TechnologyTypeSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
},
watch: {
value(newVal) {
this.selectedValues = newVal.map(t => t.id)
this.selectedValues = newVal.map(t => t.id);
},
selectedValues(newVal, oldVal) {
let ids = new Set(newVal.filter(id => !TECHNOLOGY_TYPES.includes(id)));
Expand All @@ -112,7 +112,7 @@ export default {
let oldIds = new Set(oldVal.filter(id => !TECHNOLOGY_TYPES.includes(id)));
let oldSelectedTechnologyTypes = this.computeSelectedTechnologyTypes(oldIds);
let oldSelectedPlatforms = this.computeSelectedPlatforms(oldIds, oldSelectedTechnologyTypes);
if (!isEqual(selectedPlatforms, oldSelectedPlatforms)) {
if (!isEqual(selectedPlatforms.map(p => p.id), oldSelectedPlatforms.map(p => p.id))) {
this.$emit("input", selectedPlatforms);
}
if (!isEqual(selectedTechnologyTypes, oldSelectedTechnologyTypes)) {
Expand Down

0 comments on commit 193d063

Please sign in to comment.