diff --git a/src/webcomponents/variant/variant-browser-horizontal-filter.js b/src/webcomponents/variant/variant-browser-horizontal-filter.js index 20d83d250..bf0be06e1 100644 --- a/src/webcomponents/variant/variant-browser-horizontal-filter.js +++ b/src/webcomponents/variant/variant-browser-horizontal-filter.js @@ -69,9 +69,21 @@ export default class VariantBrowserHorizontalFilter extends LitElement { cellbaseClient: { type: Object }, + resource: { + type: String, + }, + toolId: { + type: String, + }, + filters: { + type: Array, + }, + defaultFilter: { + type: Object, + }, config: { - type: Object - } + type: Object, + }, }; } @@ -83,13 +95,14 @@ export default class VariantBrowserHorizontalFilter extends LitElement { this.queryList = []; this.preparedQuery = {}; - // history filters - this.history = []; - // quick and advanced filters this.quickFiltersList = []; this.advancedFilters = []; + this.applicationFilters = []; + this.userFilters = []; + this.history = []; + // map filter id to filter field // TO_REMOVE this.mapFilterIdToField = { @@ -196,9 +209,13 @@ export default class VariantBrowserHorizontalFilter extends LitElement { } update(changedProperties) { - // if (changedProperties.has("opencgaSession")) { - // this.opencgaSessionObserver(); - // } + if (changedProperties.has("opencgaSession")) { + this.updateUserFilters(); + } + + if (changedProperties.has("filters") || changedProperties.has("defaultFilter")) { + this.updateApplicationFilters(); + } if (changedProperties.has("query")) { this.queryObserver(); @@ -211,10 +228,6 @@ export default class VariantBrowserHorizontalFilter extends LitElement { super.update(changedProperties); } - updated() { - console.log(this.queryList); - } - // opencgaSessionObserver() { // if (this.opencgaSession.study) { // // Render filter menu and add event and tooltips @@ -273,6 +286,31 @@ export default class VariantBrowserHorizontalFilter extends LitElement { LitUtils.dispatchCustomEvent(this, "querySearch", null, {query}); } + updateApplicationFilters() { + this.applicationFilters = []; + + // 1. Add default filter + if (!!this.defaultFilter) { + const isDisabled = UtilsNew.isEmpty(this.defaultFilter); + this.applicationFilters.push({ + id: "Default Filter", + query: UtilsNew.objectClone(this.defaultFilter), + disabled: isDisabled, + description: isDisabled ? "Filter not configured." : "", + active: false, + }); + } + + // 2. Add example filters + if (this.filters?.length > 0) { + this.applicationFilters.push(...this.filters); + } + } + + updateUserFilters() { + this.userFilters = this.opencgaSession.user.filters.filter(f => f.resource === this.resource); + } + updateHistory() { // 1. remove all identical filters const _history = this.history.filter(historyItem => { @@ -286,7 +324,8 @@ export default class VariantBrowserHorizontalFilter extends LitElement { // 3. prepare new latest filter and add at the beginning _history.unshift({ - date: UtilsNew.getDatetime(), + id: UtilsNew.dateFormatter(UtilsNew.getDatetime(), "HH:mm:ss"), + // date: UtilsNew.getDatetime(), query: UtilsNew.objectClone(this.preparedQuery), latest: true, }); @@ -946,9 +985,8 @@ export default class VariantBrowserHorizontalFilter extends LitElement { `; } - renderHistoryItems() { - return this.history.map(item => { - const filterTitle = UtilsNew.dateFormatter(item.date, "HH:mm:ss"); + renderFilterItems(items) { + return items.map(item => { const filterParams = Object.keys(item.query) .filter(key => key !== "study" && !!item.query[key]); const filterTooltip = filterParams @@ -960,7 +998,7 @@ export default class VariantBrowserHorizontalFilter extends LitElement {
- ${filterTitle} ${item.latest ? html` (latest)` : nothing} + ${item.id} ${item.latest ? html` (latest)` : nothing}
${filterParams?.length > 0 ? html` @@ -973,7 +1011,7 @@ export default class VariantBrowserHorizontalFilter extends LitElement {
- +
@@ -1011,6 +1049,24 @@ export default class VariantBrowserHorizontalFilter extends LitElement { Search
+ +