@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
77 lines • 4.52 kB
JavaScript
import { __awaiter } from "tslib";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { searchRequest } from "../RcsbGroupMembers/RcsbGroupMembersComponent";
import { SearchQueryContextManager as SQCM } from "../RcsbGroupSeacrhQuery/SearchQueryContextManager";
import resource from "../../../RcsbServerConfig/web.resources.json";
import { SearchQueryTools as SQT } from "../../../RcsbSeacrh/SearchQueryTools";
import { groupProvenanceToReturnType } from "../../../RcsbUtils/Groups/GroupProvenanceToAggregationType";
import { RelevanceScoreRankingOption, ScoringStrategy, Service, SortDirection } from "@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchEnums";
import { Operator } from "../../../RcsbUtils/Helpers/Operator";
export class RcsbGroupContentComponent extends React.Component {
constructor() {
super(...arguments);
this.state = {
subGroupMembers: 0,
fullGroupMembers: 0,
searchQuery: this.props.searchQuery
};
}
componentDidMount() {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
this.subscribe();
const fullGroupMembers = (_a = (yield searchRequest(this.props.groupProvenanceId, this.props.groupId))) === null || _a === void 0 ? void 0 : _a.total_count;
const subGroupMembers = (_b = (yield 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 (_jsxs("span", { children: [(_a = this.props.completeGroupText) !== null && _a !== void 0 ? _a : "", " ", _jsx("a", { href: this.href().fullGroup, children: this.displayNumber(this.state.fullGroupMembers) })] }));
else
return (_jsxs("span", { children: [this.props.subGroupText ? this.props.subGroupText + " " : "", _jsx("a", { href: this.href().subGroup, children: this.displayNumber(this.state.subGroupMembers) }), this.props.delimiterText ? " " + this.props.delimiterText + " " : " / ", _jsx("a", { href: this.href().fullGroup, children: this.displayNumber(this.state.fullGroupMembers) }), this.props.fullGroupText ? " " + this.props.fullGroupText : ""] }));
}
subscribe() {
SQCM.subscribe((o) => __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.digitGrouping)(x);
}
updateGroupContent(o) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const subGroupMembers = (_a = (yield 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) ? resource.rcsb_search.url + encodeURI(JSON.stringify(SQT.buildNodeSearchQuery(SQT.searchGroupQuery(this.props.groupProvenanceId, this.props.groupId, Service.Text), this.state.searchQuery.query, groupProvenanceToReturnType[this.props.groupProvenanceId], SQT.searchContentType(this.state.searchQuery)))) : "",
fullGroup: resource.rcsb_search.url + JSON.stringify({
query: SQT.searchGroupQuery(this.props.groupProvenanceId, this.props.groupId),
return_type: groupProvenanceToReturnType[this.props.groupProvenanceId],
request_options: {
pager: {
start: 0,
rows: 25
},
scoring_strategy: ScoringStrategy.Combined,
sort: [{
sort_by: RelevanceScoreRankingOption.Score,
direction: SortDirection.Desc
}],
results_content_type: ["computational", "experimental"]
}
})
};
}
}
//# sourceMappingURL=RcsbGroupContentComponent.js.map