UNPKG

@rcsb/rcsb-saguaro-app

Version:
92 lines 4.14 kB
import { __awaiter } from "tslib"; import { Subject } from "rxjs"; import { cloneDeep } from "lodash"; import { DataContainer } from "../../../RcsbUtils/Helpers/DataContainer"; import { SearchQueryTools as SQT } from "../../../RcsbSeacrh/SearchQueryTools"; import { GroupChartMap as GDCM } from "../RcsbGroupChart/GroupChartTools"; export class SearchQueryContextManager { static setConfig(config) { if (config.searchQuery) SearchQueryContextManager.currentSearchQuery.set(config.searchQuery); if (config.groupId) SearchQueryContextManager.groupId.set(config.groupId); if (config.groupProvenanceId) SearchQueryContextManager.groupProvenanceId.set(config.groupProvenanceId); } static updateSearchQuery(attributeName, query, returnType) { return __awaiter(this, void 0, void 0, function* () { const searchQuery = SearchQueryContextManager.currentSearchQuery.get(); const groupProvenanceId = SearchQueryContextManager.groupProvenanceId.get(); const groupId = SearchQueryContextManager.groupId.get(); if (!groupProvenanceId || !groupId) throw new Error("Undefined group config"); const newQuery = searchQuery && searchQuery.query ? SQT.buildNodeSearchQuery(searchQuery.query, query, returnType, SQT.searchContentType(searchQuery)) : SQT.buildSearchQuery(query, returnType); const chartMap = yield GDCM.getChartMap(groupProvenanceId, groupId, newQuery); SearchQueryContextManager.next({ chartMap: chartMap, attributeName: attributeName, searchQuery: newQuery, groupId: groupId, groupProvenanceId: groupProvenanceId }); if (!newQuery.query) throw new Error("Search query error"); return SQT.buildSearchQuery(SQT.addGroupNodeToSearchQuery(groupProvenanceId, groupId, newQuery.query), returnType); }); } static replaceSearchQuery(attributeName, searchQuery) { return __awaiter(this, void 0, void 0, function* () { const groupProvenanceId = SearchQueryContextManager.groupProvenanceId.get(); const groupId = SearchQueryContextManager.groupId.get(); if (!groupProvenanceId || !groupId) return; const chartMap = yield GDCM.getChartMap(groupProvenanceId, groupId, searchQuery); SearchQueryContextManager.next({ chartMap, attributeName, searchQuery, groupId, groupProvenanceId }); }); } static subscribe(f, attr) { if (typeof attr === "string") SearchQueryContextManager.attributeList.push(attr); return SearchQueryContextManager.searchQueryObservable.subscribe({ next: (o) => { f(o); } }); } static dataSubscription(f, attr) { return SearchQueryContextManager.dataObservable.subscribe({ next: (o) => { f(o); } }); } static next(o) { this.currentSearchQuery.set(o.searchQuery); SearchQueryContextManager.searchQueryObservable.next(o); SearchQueryContextManager.dataObservable.next({ attributeName: o.attributeName, chartMap: Array.from(o.chartMap.entries()).reduce((prev, [k, v]) => { return prev.set(k, v.map(v => v.data)); }, new Map()) }); } static getAttributeList() { return cloneDeep(this.attributeList); } } SearchQueryContextManager.searchQueryObservable = new Subject(); SearchQueryContextManager.dataObservable = new Subject(); SearchQueryContextManager.attributeList = []; SearchQueryContextManager.currentSearchQuery = new DataContainer(); SearchQueryContextManager.groupProvenanceId = new DataContainer(); SearchQueryContextManager.groupId = new DataContainer(); //# sourceMappingURL=SearchQueryContextManager.js.map