UNPKG

@rcsb/rcsb-saguaro-app

Version:
103 lines (102 loc) 6.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupMembersGrid = void 0; const tslib_1 = require("tslib"); const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = tslib_1.__importDefault(require("react")); const react_bootstrap_1 = require("react-bootstrap"); const GroupMemberItem_1 = require("./GroupMemberItem"); const SearchQueryTools_1 = require("../../../RcsbSeacrh/SearchQueryTools"); const SearchMetadata_1 = require("@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchMetadata"); const SearchEnums_1 = require("@rcsb/rcsb-api-tools/lib/RcsbSearch/Types/SearchEnums"); const DwEnums_1 = require("@rcsb/rcsb-api-tools/lib/RcsbDw/Types/DwEnums"); const RcsbRequestContextManager_1 = require("../../../RcsbRequest/RcsbRequestContextManager"); const uniqid_1 = tslib_1.__importDefault(require("uniqid")); const TagDelimiter_1 = require("@rcsb/rcsb-api-tools/lib/RcsbUtils/TagDelimiter"); class GroupMembersGrid extends react_1.default.Component { constructor() { super(...arguments); this.state = { itemList: [] }; } render() { if (this.state.itemList.length > 0) { return ((0, jsx_runtime_1.jsx)(react_bootstrap_1.Container, { fluid: "md", children: Array(this.props.nRows).fill(null).map((none, i) => ((0, jsx_runtime_1.jsx)(react_bootstrap_1.Row, { children: Array(this.props.nColumns).fill(null).map((none, j) => { const ei = this.state.itemList[i * this.props.nColumns + j]; if (ei) return ((0, jsx_runtime_1.jsx)(react_bootstrap_1.Col, { className: "p-0", children: (0, jsx_runtime_1.jsx)(GroupMemberItem_1.GroupMemberItem, { item: ei, groupId: this.props.groupId, groupProvenanceId: this.props.groupProvenanceId, searchQuery: this.props.searchQuery, minHeight: this.props.minHeight, setMinHeight: this.props.setMinHeight }) }, `${(0, uniqid_1.default)("col_")}_${j}`)); else return null; }) }, `${(0, uniqid_1.default)("row_")}_${i}`))) })); } else return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}); } componentDidMount() { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (this.state.itemList.length == 0) yield this.getMembersData(); }); } componentDidUpdate(prevProps, prevState, snapshot) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (prevProps.index != this.props.index) yield this.getMembersData(); }); } getMembersData() { return tslib_1.__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 === DwEnums_1.GroupProvenanceId.ProvenanceMatchingDepositGroupId ? (yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntryProperties(searchResult.result_set.map(m => typeof m === "string" ? m : m.identifier))) : (yield RcsbRequestContextManager_1.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_1.TagDelimiter.entity + ei.entityId; if (visited.has(entityId)) return false; visited.add(entityId); return true; }).sort((a, b) => ((a.entryId + TagDelimiter_1.TagDelimiter.entity + a.entityId)).localeCompare(b.entryId + TagDelimiter_1.TagDelimiter.entity + b.entityId)) }); }); } searchRequest() { return tslib_1.__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); }); } } exports.GroupMembersGrid = GroupMembersGrid; function searchRequest(groupProvenanceId, groupId, start, rows, searchQuery) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f, _g, _h; return yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getSearchQuery({ query: (searchQuery === null || searchQuery === void 0 ? void 0 : searchQuery.query) ? SearchQueryTools_1.SearchQueryTools.addGroupNodeToSearchQuery(groupProvenanceId, groupId, searchQuery.query) : SearchQueryTools_1.SearchQueryTools.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 : SearchMetadata_1.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 : SearchEnums_1.SortDirection.Asc }], results_content_type: SearchQueryTools_1.SearchQueryTools.searchContentType(searchQuery) }, return_type: groupProvenanceId === DwEnums_1.GroupProvenanceId.ProvenanceMatchingDepositGroupId ? SearchEnums_1.ReturnType.Entry : SearchEnums_1.ReturnType.PolymerEntity }); }); } function parseItems(groupProvenanceId, propsList) { return groupProvenanceId === DwEnums_1.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 }))); }