Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selection of any term in the DatasetPreview component #65

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/components/AnnotationSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,15 @@ 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');
}
.map(a => this.annotationById[a] || {
classUri: a.split(SEPARATOR, 2)[0],
className: "",
termUri: a.split(SEPARATOR, 2)[1],
termName: ""
});

return selectedAnnotations.filter(a => a)
},
/**
* Selected categories.
Expand Down
47 changes: 31 additions & 16 deletions src/components/DatasetPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
<div class="py-3">
<h3>{{ dataset.name }}</h3>
<template v-for="term in includedTerms">
<v-chip v-if="isClickable(term)"
<v-chip
:key="getId(term)"
@click="isClickable(term) && handleChipClick(term) || null"
@click="handleChipClick(term)"
small :color="getChipColor(term.objectClass)"
:title="getTitle(term)"
class="mb-1 mr-1">
{{ term.termName }}
<v-icon v-if="isClickable(term)" right>mdi-plus</v-icon>
</v-chip>
<v-chip v-else :key="getId(term)"
small :color="getChipColor(term.objectClass)"
:title="getTitle(term)"
class="mb-1 mr-1">
class="text-capitalize mb-1 mr-1">
{{ term.termName }}
<v-icon v-if="isSelectable(term)" right>mdi-plus</v-icon>
<v-icon v-else-if="isUnselectable(term)" right>mdi-minus</v-icon>
</v-chip>
</template>
<div v-html="this.description"></div>
Expand Down Expand Up @@ -51,6 +46,7 @@ export default {
selectedAnnotations: Array,
availableAnnotations: Array
},
events: ["annotation-selected", "annotation-unselected"],
data() {
return {
includedTerms: []
Expand Down Expand Up @@ -126,13 +122,20 @@ export default {
* @param term
* @returns {boolean}
*/
isClickable(term) {
return this.availableAnnotationIds.has(this.getId(term))
&& !this.selectedCategoryIds.has(getCategoryId(term))
&& !this.selectedAnnotationIds.has(this.getId(term));
isSelectable(term) {
return !this.selectedCategoryIds.has(getCategoryId(term)) && !this.selectedAnnotationIds.has(this.getId(term));
},
isUnselectable(term) {
return this.selectedAnnotationIds.has(this.getId(term));
},
handleChipClick(term) {
this.$emit("chip-clicked", term);
if (this.isSelectable(term)) {
this.$emit("annotation-selected", term);
} else if (this.isUnselectable(term)) {
this.$emit("annotation-unselected", term);
} else {
console.warn(`Term ${term} cannot be unselected.`, term);
}
},
getChipColor(objectClass) {
return this.chipColorMap[objectClass] || "orange";
Expand All @@ -144,7 +147,19 @@ export default {
updateTerms() {
this.includedTerms = [];
this.getTerms().then(terms => {
this.includedTerms = terms.sort((a, b) => OBJECT_CLASS_PRIORITY[a.objectClass] - OBJECT_CLASS_PRIORITY[b.objectClass]);
// we don't display the same term from different object classes
let seenIds = new Set();
this.includedTerms = terms
.sort((a, b) => OBJECT_CLASS_PRIORITY[a.objectClass] - OBJECT_CLASS_PRIORITY[b.objectClass])
.filter(term => {
let id = this.getId(term);
if (seenIds.has(id)) {
console.log("Skipped already seen term");
return true;
}
seenIds.add(id);
return true;
});
});
}
},
Expand Down
44 changes: 33 additions & 11 deletions src/views/Browser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
:selected-categories="searchSettings.categories"
:selected-annotations="searchSettings.annotations"
:available-annotations="datasetsAnnotations"
@chip-clicked="handleChipClicked"></DatasetPreview>
@annotation-selected="selectTerm"
@annotation-unselected="unselectTerm"/>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, one could use add a sync prop, bind it to searchSettings.annotations and let the component alter the selection itself.

</td>
</template>
<template v-slot:footer.prepend>
Expand Down Expand Up @@ -101,7 +102,7 @@
<script>
import SearchSettings from "@/components/SearchSettings";
import { ExpressionExperimentType, SearchSettings as SearchSettingsModel } from "@/models";
import { baseUrl, excludedCategories, excludedTerms, marked, HIGHLIGHT_LABELS } from "@/config/gemma";
import { baseUrl, excludedCategories, excludedTerms, HIGHLIGHT_LABELS, marked } from "@/config/gemma";
import { chain, debounce, escapeRegExp, isEqual, sumBy } from "lodash";
import DatasetPreview from "@/components/DatasetPreview.vue";
import { highlight } from "@/search-utils";
Expand All @@ -120,8 +121,8 @@ import Error from "@/components/Error.vue";
import { mapMutations, mapState } from "vuex";

const MAX_URIS_IN_CLAUSE = 200;
const MAX_TERMS_PER_CATEGORY = 200;
const MAX_PLATFORMS = 200;
const MAX_TERMS_PER_CATEGORY = process.env.NODE_ENV !== "production" ? 20 : 200;;
const MAX_PLATFORMS = process.env.NODE_ENV !== "production" ? 50 : 200;

function quoteIfNecessary(s) {
if (s.match(/[(), "]/) || s.length === 0) {
Expand Down Expand Up @@ -564,8 +565,16 @@ export default {
let mFilter = filter;
if (mFilter) {
mFilter = mFilter.map(clause => clause
.filter(subClause => !disallowedPrefixes.some(p => subClause.startsWith(p))))
.filter(clause => clause.length > 0);
.map(subClause => {
for (let p of disallowedPrefixes) {
if (subClause.startsWith(p)) {
// this will render the clause always true and preserve the term URI for retainMentionedTerms to work
subClause = `${subClause} or ${p}id > 0`;
break;
}
}
return subClause;
}));
}
return compressFilter(mFilter).then(compressedFilter => {
let payload = {
Expand All @@ -580,6 +589,7 @@ export default {
if (excludedTerms !== undefined) {
payload["excludedTerms"] = excludedTerms;
}
payload["retainMentionedTerms"] = true;
if (this.myself) {
payload["gid"] = this.myself.group;
}
Expand Down Expand Up @@ -706,12 +716,24 @@ export default {
.join(" ");
},
...mapMutations(["setTitle", "setFilterSummary", "setFilterDescription", "setLastError"]),
handleChipClicked(previewTerm) {
this.searchSettings.annotations.push({
classUri: previewTerm.classUri,
selectTerm(previewTerm) {
this.searchSettings.annotations.push({
classUri: previewTerm.classUri,
className: previewTerm.className,
termUri: previewTerm.termUri,
termName: previewTerm.termName})
termUri: previewTerm.termUri,
termName: previewTerm.termName
});
},
unselectTerm(previewTerm) {
let categoryId = getCategoryId(previewTerm);
let termId = getTermId(previewTerm);
for (let [i, a] of this.searchSettings.annotations.entries()) {
if (getCategoryId(a) === categoryId && getTermId(a) === termId) {
this.searchSettings.annotations.splice(i, 1);
return;
}
}
console.warn(`${previewTerm} is not selected and thus cannot be unselected.`);
}
},
created() {
Expand Down