@rcsb/rcsb-saguaro-app
Version:
RCSB 1D Saguaro Web App
99 lines • 6.07 kB
JavaScript
import { __awaiter } from "tslib";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import React from "react";
import { Col, Container, Row } from "react-bootstrap";
import { GroupMemberItem } from "./GroupMemberItem";
import { SearchQueryTools as SQT } from "../../../RcsbSeacrh/SearchQueryTools";
import { RcsbSearchMetadata } from "@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchMetadata";
import { ReturnType, SortDirection } from "@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchEnums";
import { GroupProvenanceId } from "@rcsb/rcsb-api-tools/lib/RcsbDw/Types/DwEnums";
import { rcsbRequestCtxManager } from "../../../RcsbRequest/RcsbRequestContextManager";
import uniqid from "uniqid";
import { TagDelimiter } from "@rcsb/rcsb-api-tools/lib/RcsbUtils/TagDelimiter";
export class GroupMembersGrid extends React.Component {
constructor() {
super(...arguments);
this.state = {
itemList: []
};
}
render() {
if (this.state.itemList.length > 0) {
return (_jsx(Container, { fluid: "md", children: Array(this.props.nRows).fill(null).map((none, i) => (_jsx(Row, { children: Array(this.props.nColumns).fill(null).map((none, j) => {
const ei = this.state.itemList[i * this.props.nColumns + j];
if (ei)
return (_jsx(Col, { className: "p-0", children: _jsx(GroupMemberItem, { item: ei, groupId: this.props.groupId, groupProvenanceId: this.props.groupProvenanceId, searchQuery: this.props.searchQuery, minHeight: this.props.minHeight, setMinHeight: this.props.setMinHeight }) }, `${uniqid("col_")}_${j}`));
else
return null;
}) }, `${uniqid("row_")}_${i}`))) }));
}
else
return _jsx(_Fragment, {});
}
componentDidMount() {
return __awaiter(this, void 0, void 0, function* () {
if (this.state.itemList.length == 0)
yield this.getMembersData();
});
}
componentDidUpdate(prevProps, prevState, snapshot) {
return __awaiter(this, void 0, void 0, function* () {
if (prevProps.index != this.props.index)
yield this.getMembersData();
});
}
getMembersData() {
return __awaiter(this, void 0, void 0, function* () {
const searchResult = yield this.searchRequest();
if (!(searchResult === null || searchResult === void 0 ? void 0 : searchResult.result_set))
return;
const itemList = parseItems(this.props.groupProvenanceId, this.props.groupProvenanceId === GroupProvenanceId.ProvenanceMatchingDepositGroupId ?
(yield rcsbRequestCtxManager.getEntryProperties(searchResult.result_set.map(m => typeof m === "string" ? m : m.identifier)))
:
(yield rcsbRequestCtxManager.getEntityProperties(searchResult.result_set.map(m => typeof m === "string" ? m : m.identifier))));
const visited = new Set();
this.setState({
itemList: itemList
.filter(ei => {
const entityId = ei.entryId.toLowerCase() + TagDelimiter.entity + ei.entityId;
if (visited.has(entityId))
return false;
visited.add(entityId);
return true;
}).sort((a, b) => ((a.entryId + TagDelimiter.entity + a.entityId)).localeCompare(b.entryId + TagDelimiter.entity + b.entityId))
});
});
}
searchRequest() {
return __awaiter(this, void 0, void 0, function* () {
return yield searchRequest(this.props.groupProvenanceId, this.props.groupId, this.props.nRows * this.props.nColumns * this.props.index, this.props.nRows * this.props.nColumns, this.props.searchQuery);
});
}
}
function searchRequest(groupProvenanceId, groupId, start, rows, searchQuery) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h;
return yield rcsbRequestCtxManager.getSearchQuery({
query: (searchQuery === null || searchQuery === void 0 ? void 0 : searchQuery.query) ? SQT.addGroupNodeToSearchQuery(groupProvenanceId, groupId, searchQuery.query) : SQT.searchGroupQuery(groupProvenanceId, groupId),
request_options: {
paginate: {
start: start,
rows: rows
},
sort: [{
sort_by: (_d = (_c = (_b = (_a = searchQuery === null || searchQuery === void 0 ? void 0 : searchQuery.request_options) === null || _a === void 0 ? void 0 : _a.group_by) === null || _b === void 0 ? void 0 : _b.ranking_criteria_type) === null || _c === void 0 ? void 0 : _c.sort_by) !== null && _d !== void 0 ? _d : RcsbSearchMetadata.RcsbEntryContainerIdentifiers.EntryId.path,
direction: (_h = (_g = (_f = (_e = searchQuery === null || searchQuery === void 0 ? void 0 : searchQuery.request_options) === null || _e === void 0 ? void 0 : _e.group_by) === null || _f === void 0 ? void 0 : _f.ranking_criteria_type) === null || _g === void 0 ? void 0 : _g.direction) !== null && _h !== void 0 ? _h : SortDirection.Asc
}],
results_content_type: SQT.searchContentType(searchQuery)
},
return_type: groupProvenanceId === GroupProvenanceId.ProvenanceMatchingDepositGroupId ? ReturnType.Entry : ReturnType.PolymerEntity
});
});
}
function parseItems(groupProvenanceId, propsList) {
return groupProvenanceId === GroupProvenanceId.ProvenanceMatchingDepositGroupId ?
propsList.map((o) => (Object.assign(Object.assign({}, o), { molecularWeight: o.entryMolecularWeight })))
:
propsList.map((o) => (o.instances)).flat().map((o) => (Object.assign(Object.assign({}, o), { molecularWeight: o.entityMolecularWeight })));
}
//# sourceMappingURL=GroupMembersGrid.js.map