UNPKG

@rcsb/rcsb-saguaro-app

Version:
81 lines (80 loc) 5.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RcsbGroupContentComponent = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = tslib_1.__importDefault(require("react")); const RcsbGroupMembersComponent_1 = require("../RcsbGroupMembers/RcsbGroupMembersComponent"); const SearchQueryContextManager_1 = require("../RcsbGroupSeacrhQuery/SearchQueryContextManager"); const web_resources_json_1 = tslib_1.__importDefault(require("../../../RcsbServerConfig/web.resources.json")); const SearchQueryTools_1 = require("../../../RcsbSeacrh/SearchQueryTools"); const GroupProvenanceToAggregationType_1 = require("../../../RcsbUtils/Groups/GroupProvenanceToAggregationType"); const SearchEnums_1 = require("@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchEnums"); const Operator_1 = require("../../../RcsbUtils/Helpers/Operator"); class RcsbGroupContentComponent extends react_1.default.Component { constructor() { super(...arguments); this.state = { subGroupMembers: 0, fullGroupMembers: 0, searchQuery: this.props.searchQuery }; } componentDidMount() { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b; this.subscribe(); const fullGroupMembers = (_a = (yield (0, RcsbGroupMembersComponent_1.searchRequest)(this.props.groupProvenanceId, this.props.groupId))) === null || _a === void 0 ? void 0 : _a.total_count; const subGroupMembers = (_b = (yield (0, RcsbGroupMembersComponent_1.searchRequest)(this.props.groupProvenanceId, this.props.groupId, this.props.searchQuery))) === null || _b === void 0 ? void 0 : _b.total_count; if (fullGroupMembers && subGroupMembers) this.setState({ subGroupMembers, fullGroupMembers }); }); } render() { var _a; if (this.state.subGroupMembers === this.state.fullGroupMembers) return ((0, jsx_runtime_1.jsxs)("span", { children: [(_a = this.props.completeGroupText) !== null && _a !== void 0 ? _a : "", " ", (0, jsx_runtime_1.jsx)("a", { href: this.href().fullGroup, children: this.displayNumber(this.state.fullGroupMembers) })] })); else return ((0, jsx_runtime_1.jsxs)("span", { children: [this.props.subGroupText ? this.props.subGroupText + " " : "", (0, jsx_runtime_1.jsx)("a", { href: this.href().subGroup, children: this.displayNumber(this.state.subGroupMembers) }), this.props.delimiterText ? " " + this.props.delimiterText + " " : " / ", (0, jsx_runtime_1.jsx)("a", { href: this.href().fullGroup, children: this.displayNumber(this.state.fullGroupMembers) }), this.props.fullGroupText ? " " + this.props.fullGroupText : ""] })); } subscribe() { SearchQueryContextManager_1.SearchQueryContextManager.subscribe((o) => tslib_1.__awaiter(this, void 0, void 0, function* () { yield this.updateGroupContent(o); })); } displayNumber(x) { var _a; return ((_a = this.props.displayNumber) !== null && _a !== void 0 ? _a : Operator_1.Operator.digitGrouping)(x); } updateGroupContent(o) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a; const subGroupMembers = (_a = (yield (0, RcsbGroupMembersComponent_1.searchRequest)(this.props.groupProvenanceId, this.props.groupId, o.searchQuery))) === null || _a === void 0 ? void 0 : _a.total_count; if (subGroupMembers) this.setState({ subGroupMembers, searchQuery: o.searchQuery }); }); } href() { var _a; return { subGroup: ((_a = this.state.searchQuery) === null || _a === void 0 ? void 0 : _a.query) ? web_resources_json_1.default.rcsb_search.url + encodeURI(JSON.stringify(SearchQueryTools_1.SearchQueryTools.buildNodeSearchQuery(SearchQueryTools_1.SearchQueryTools.searchGroupQuery(this.props.groupProvenanceId, this.props.groupId, SearchEnums_1.Service.Text), this.state.searchQuery.query, GroupProvenanceToAggregationType_1.groupProvenanceToReturnType[this.props.groupProvenanceId], SearchQueryTools_1.SearchQueryTools.searchContentType(this.state.searchQuery)))) : "", fullGroup: web_resources_json_1.default.rcsb_search.url + JSON.stringify({ query: SearchQueryTools_1.SearchQueryTools.searchGroupQuery(this.props.groupProvenanceId, this.props.groupId), return_type: GroupProvenanceToAggregationType_1.groupProvenanceToReturnType[this.props.groupProvenanceId], request_options: { pager: { start: 0, rows: 25 }, scoring_strategy: SearchEnums_1.ScoringStrategy.Combined, sort: [{ sort_by: SearchEnums_1.RelevanceScoreRankingOption.Score, direction: SearchEnums_1.SortDirection.Desc }], results_content_type: ["computational", "experimental"] } }) }; } } exports.RcsbGroupContentComponent = RcsbGroupContentComponent;