UNPKG

synapse-react-client

Version:

[![Build Status](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client.svg?branch=main)](https://travis-ci.com/Sage-Bionetworks/Synapse-React-Client) [![npm version](https://badge.fury.io/js/synapse-react-client.svg)](https://badge.fury.io/js/synaps

99 lines 5.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var React = (0, tslib_1.__importStar)(require("react")); var getUserData_1 = require("../utils/functions/getUserData"); var SynapseConstants_1 = require("../utils/SynapseConstants"); var UserCard_1 = (0, tslib_1.__importDefault)(require("./UserCard")); var lodash_es_1 = require("lodash-es"); var UserCardList = /** @class */ (function (_super) { (0, tslib_1.__extends)(UserCardList, _super); function UserCardList(props) { var _this = _super.call(this, props) || this; _this.state = { userProfileMap: {}, }; _this.update = _this.update.bind(_this); return _this; } UserCardList.prototype.componentDidMount = function () { var list = this.props.list; this.update(list); }; UserCardList.prototype.componentDidUpdate = function (prevProps) { var priorListOfIds = prevProps.list; var newValues = lodash_es_1.without.apply(void 0, (0, tslib_1.__spreadArray)([this.props.list.filter(function (el) { return el; })], priorListOfIds, false)); // check that the props have changed by seeing that at least one element is different if (newValues.length > 0) { this.update(newValues); } }; UserCardList.prototype.update = function (list) { var _this = this; (0, getUserData_1.getUserProfileWithProfilePicAttached)(list.filter(function (el) { return el; })) .then(function (data) { var newEntries = {}; data.list.forEach(function (el) { var ownerId = el.ownerId; newEntries[ownerId] = el; }); _this.setState({ userProfileMap: (0, tslib_1.__assign)((0, tslib_1.__assign)({}, _this.state.userProfileMap), newEntries), }); }) .catch(function (err) { console.log('Error on batch call =', err); }); }; /** * Given data this will find rows where there is no userId columnType and create faux user profiles * using firstName, lastName, and instituion (company in UserProfile object). * @param {QueryResultBundle} data * @returns list of UserProfiles with firstName, lastName, company, userName (first letter of firstName) filled out. * @memberof UserCardList */ UserCardList.prototype.manuallyExtractData = function (data) { var firstNameIndex = data.queryResult.queryResults.headers.findIndex(function (el) { return el.name === 'firstName'; }); var lastNameIndex = data.queryResult.queryResults.headers.findIndex(function (el) { return el.name === 'lastName'; }); var institutionIndex = data.queryResult.queryResults.headers.findIndex(function (el) { return el.name === 'institution'; }); var ownerId = data.queryResult.queryResults.headers.findIndex(function (el) { return el.columnType === 'USERID'; }); var nullOwnerIdsRows = data.queryResult.queryResults.rows.filter(function (el) { return !el.values[ownerId]; }); return nullOwnerIdsRows.map(function (el) { var values = el.values; return { firstName: values[firstNameIndex], lastName: values[lastNameIndex], company: values[institutionIndex], ownerId: '', userName: values[firstNameIndex][0], }; }); }; UserCardList.prototype.render = function () { var _a = this.props, _b = _a.size, size = _b === void 0 ? SynapseConstants_1.MEDIUM_USER_CARD : _b, data = _a.data, list = _a.list; var _c = this.state.userProfileMap, userProfileMap = _c === void 0 ? {} : _c; var fauxUserProfilesList = data && this.manuallyExtractData(data); var fauxUserProfileIndex = 0; return (React.createElement("div", { className: "SRC-card-grid-row" }, // we loop through the list from the props because thats the 'active set of data' whereas the data stored in state could be stale list.map(function (ownerId) { var userProfile = userProfileMap[ownerId]; if (userProfile) { return (React.createElement("div", { key: JSON.stringify(userProfile), className: "SRC-grid-item SRC-narrow-grid-item" }, React.createElement(UserCard_1.default, { size: size, preSignedURL: userProfile.clientPreSignedURL, userProfile: userProfile }))); } var fauxUserProfile = fauxUserProfilesList && fauxUserProfilesList[fauxUserProfileIndex]; if (!fauxUserProfile) { // This could happen in one of two cases: // - The props just updated with a new userlist where the data is being gathered for this particular user // OR there is no mapping for this user return false; } fauxUserProfileIndex += 1; return (React.createElement("div", { key: JSON.stringify(fauxUserProfile), className: "SRC-grid-item SRC-narrow-grid-item" }, React.createElement(UserCard_1.default, { disableLink: true, hideEmail: true, size: size, userProfile: fauxUserProfile }))); }))); }; return UserCardList; }(React.Component)); exports.default = UserCardList; //# sourceMappingURL=UserCardList.js.map