diff --git a/src/webcomponents/commons/filters/study-filter.js b/src/webcomponents/commons/filters/study-filter.js
index 6e13b51ff..3f57de3a3 100644
--- a/src/webcomponents/commons/filters/study-filter.js
+++ b/src/webcomponents/commons/filters/study-filter.js
@@ -16,6 +16,7 @@
import {LitElement, html} from "lit";
import UtilsNew from "../../../core/utils-new.js";
+import LitUtils from "../utils/lit-utils.js";
import "../forms/select-field-filter.js";
@@ -35,7 +36,10 @@ export default class StudyFilter extends LitElement {
return {
opencgaSession: {
type: Object
- }
+ },
+ value: {
+ type: String,
+ },
};
}
@@ -47,17 +51,25 @@ export default class StudyFilter extends LitElement {
this.differentStudies = [];
}
- updated(changedProperties) {
+ update(changedProperties) {
if (changedProperties.has("opencgaSession")) {
- this.selectedStudies = [this.opencgaSession.study.fqn];
if (this.opencgaSession.project.studies.length) {
this.differentStudies = this.opencgaSession.project.studies.filter(study => this.opencgaSession.study.id !== study.id);
}
- this.requestUpdate();
- this.updateComplete.then(() => {
- $(".selectpicker", this).selectpicker("refresh");
- });
}
+
+ if (changedProperties.has("opencgaSession") || changedProperties.has("value")) {
+ this.selectedStudies = Array.from(new Set([
+ this.opencgaSession.study.fqn,
+ ...(this.value || "").split(this.operator).filter(v => !!v),
+ ]));
+ }
+
+ super.update(changedProperties);
+ }
+
+ updated() {
+ $(".selectpicker", this).selectpicker("val", this.selectedStudies);
}
filterChange() {
@@ -69,12 +81,7 @@ export default class StudyFilter extends LitElement {
// NOT operator (not visible/not implemented)
querystring = [...this.selectedStudies.map(study => `${this.operator}${study}`)].join(";");
}
- const event = new CustomEvent("filterChange", {
- detail: {
- value: querystring
- }
- });
- this.dispatchEvent(event);
+ LitUtils.dispatchCustomEvent(this, "filterChange", querystring);
}
onChangeOperator(e) {
@@ -82,21 +89,6 @@ export default class StudyFilter extends LitElement {
this.filterChange();
}
- // onChangeStudy(e) {
- // const study = e.target.dataset.id;
- // if (e.target.checked) {
- // this.selectedStudies.push(study);
- // } else {
- // const indx = this.selectedStudies.indexOf(study);
- // if (!~indx) {
- // console.error("Trying to remove non active study");
- // } else {
- // this.selectedStudies.splice(indx);
- // }
- // }
- // this.filterChange();
- // }
-
onChangeSelectedStudy() {
const selected = $(".selectpicker", this).selectpicker("val");
// Active study is always the first element
@@ -117,15 +109,6 @@ export default class StudyFilter extends LitElement {
}
return html`
-
-
`;
}
+
}
customElements.define("study-filter", StudyFilter);
diff --git a/src/webcomponents/variant/variant-browser.js b/src/webcomponents/variant/variant-browser.js
index fa02132cf..f49f42a38 100644
--- a/src/webcomponents/variant/variant-browser.js
+++ b/src/webcomponents/variant/variant-browser.js
@@ -85,9 +85,6 @@ export default class VariantBrowser extends LitElement {
this.COMPONENT_ID = "variant-browser";
this._prefix = UtilsNew.randomString(8);
- // this.results = [];
- // this._showInitMessage = true;
-
this.searchActive = true;
this.facetActive = true;
this.query = {};
@@ -147,8 +144,8 @@ export default class VariantBrowser extends LitElement {
opencgaSessionObserver() {
if (this?.opencgaSession?.study?.fqn) {
- this._query = {study: this.opencgaSession.study.fqn};
- this.preparedQuery = {study: this.opencgaSession.study.fqn};
+ this.preparedQuery = {};
+ this.executedQuery = {};
// TODO FIXME
/** temp fix this.onRun(): when you switch study this.facetQuery contains the old study when you perform a new Aggregation query.
@@ -162,13 +159,11 @@ export default class VariantBrowser extends LitElement {
queryObserver() {
if (this.opencgaSession?.study?.fqn) {
// NOTE UtilsNew.objectCompare avoid repeating remote requests.
- if (!UtilsNew.objectCompare(this.query, this._query)) {
- this._query = {study: this.opencgaSession.study.fqn, ...this.query};
+ if (!UtilsNew.objectCompare(this.query, this.executedQuery)) {
this.preparedQuery = {...this.query};
this.executedQuery = {...this.query};
LitUtils.dispatchCustomEvent(this, "queryChange", undefined, this.preparedQuery);
- // this.detail = {};
this.searchActive = false; // Disable search button
}
}
@@ -198,10 +193,8 @@ export default class VariantBrowser extends LitElement {
}
async onRun() {
- // NOTE notifySearch() triggers this chain: notifySearch -> onQueryFilterSearch() on iva-app.js -> this.queries updated -> queryObserver() in variant-browser
- // queryObserver() here stops the repetition of the remote request by checking if it has changed
- this.query = {...this.preparedQuery};
- // updates this.queries in iva-app
+ this.executedQuery = {...this.preparedQuery};
+ this.searchActive = false;
this.notifySearch(this.preparedQuery);
this.facetQueryBuilder();
@@ -216,6 +209,7 @@ export default class VariantBrowser extends LitElement {
} else {
this.facetQuery = null;
}*/
+ this.requestUpdate();
}
changeView(id) {
@@ -226,6 +220,7 @@ export default class VariantBrowser extends LitElement {
onVariantFilterSearch(e) {
this.preparedQuery = e.detail.query;
this.executedQuery = e.detail.query;
+ this.searchActive = false;
this.requestUpdate();
}
@@ -236,16 +231,21 @@ export default class VariantBrowser extends LitElement {
onActiveFilterChange(e) {
VariantUtils.validateQuery(e.detail);
- this.query = {study: this.opencgaSession.study.fqn, ...e.detail};
- this.notifySearch(this.query);
+ this.preparedQuery = {...e.detail};
+ this.executedQuery = {...e.detail};
+ this.searchActive = false;
+ this.notifySearch(this.preparedQuery);
this.facetQueryBuilder();
+ this.requestUpdate();
}
onActiveFilterClear() {
- this.query = {study: this.opencgaSession.study.fqn};
- this.preparedQuery = {...this.query};
- this.notifySearch(this.query);
+ this.preparedQuery = {};
+ this.executedQuery = {};
+ this.searchActive = false;
+ this.notifySearch(this.preparedQuery);
this.facetQueryBuilder();
+ this.requestUpdate();
}
onFacetQueryChange(e) {
@@ -260,7 +260,7 @@ export default class VariantBrowser extends LitElement {
this.requestUpdate();
}
- onActiveFacetClear(e) {
+ onActiveFacetClear() {
this.selectedFacet = {};
this.onRun();
this.requestUpdate();
@@ -325,7 +325,7 @@ export default class VariantBrowser extends LitElement {