UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

74 lines 3.84 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/inherits"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } import { teamRequestAnalytics } from '../util/analytics'; import { getPageTime } from '../util/performance'; import CachingClient from './CachingClient'; import { getErrorAttributes } from './errorUtils'; import { getTeamFromAGG } from './getTeamFromAGG'; var TeamProfileCardClient = /*#__PURE__*/function (_CachingClient) { function TeamProfileCardClient(options) { var _this; _classCallCheck(this, TeamProfileCardClient); _this = _callSuper(this, TeamProfileCardClient, [options]); _this.options = options; return _this; } _inherits(TeamProfileCardClient, _CachingClient); return _createClass(TeamProfileCardClient, [{ key: "makeRequest", value: function makeRequest(teamId, _orgId) { if (!this.options.gatewayGraphqlUrl) { throw new Error('Trying to fetch via gateway with no specified config.gatewayGraphqlUrl'); } return getTeamFromAGG(this.options.gatewayGraphqlUrl, teamId, this.options.cloudId); } }, { key: "getProfile", value: function getProfile(teamId, orgId, analytics) { var _this2 = this; if (!teamId) { return Promise.reject(new Error('teamId is missing')); } var cache = this.getCachedProfile(teamId); if (cache) { return Promise.resolve(cache); } return new Promise(function (resolve, reject) { var startTime = getPageTime(); if (analytics) { analytics(teamRequestAnalytics('triggered')); } _this2.makeRequest(teamId, orgId).then(function (data) { if (_this2.cache) { _this2.setCachedProfile(teamId, data); } if (analytics) { analytics(teamRequestAnalytics('succeeded', { duration: getPageTime() - startTime, gateway: true })); } resolve(data); }).catch(function (error) { if (analytics) { analytics(teamRequestAnalytics('failed', _objectSpread(_objectSpread({ duration: getPageTime() - startTime }, getErrorAttributes(error)), {}, { gateway: true }))); } reject(error); }); }); } }]); }(CachingClient); export { TeamProfileCardClient as default };