UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

191 lines (190 loc) 9.33 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var _atlassianContext = require("@atlaskit/atlassian-context"); var _RovoAgentCardClient = _interopRequireDefault(require("./RovoAgentCardClient")); var _TeamCentralCardClient = _interopRequireDefault(require("./TeamCentralCardClient")); var _TeamProfileCardClient = _interopRequireDefault(require("./TeamProfileCardClient")); var _UserProfileCardClient = _interopRequireDefault(require("./UserProfileCardClient")); 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) { (0, _defineProperty2.default)(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; } var defaultConfig = { gatewayGraphqlUrl: '/gateway/api/graphql' }; var ProfileCardClient = /*#__PURE__*/function () { function ProfileCardClient(config, clients) { var _config$gatewayGraphq; (0, _classCallCheck2.default)(this, ProfileCardClient); //This default can be removed once all the clients are updated to pass the gatewayGraphqlUrl var withDefaultConfig = _objectSpread(_objectSpread(_objectSpread({}, defaultConfig), config), { gatewayGraphqlUrl: (_config$gatewayGraphq = config.gatewayGraphqlUrl) !== null && _config$gatewayGraphq !== void 0 ? _config$gatewayGraphq : defaultConfig.gatewayGraphqlUrl }); this.userClient = (clients === null || clients === void 0 ? void 0 : clients.userClient) || new _UserProfileCardClient.default(withDefaultConfig); this.teamClient = (clients === null || clients === void 0 ? void 0 : clients.teamClient) || new _TeamProfileCardClient.default(withDefaultConfig); this.rovoAgentClient = (clients === null || clients === void 0 ? void 0 : clients.rovoAgentClient) || new _RovoAgentCardClient.default(withDefaultConfig); this.tcClient = maybeCreateTeamCentralClient(withDefaultConfig, clients); } return (0, _createClass2.default)(ProfileCardClient, [{ key: "flushCache", value: function flushCache() { var _this$tcClient, _this$rovoAgentClient; this.userClient.flushCache(); this.teamClient.flushCache(); (_this$tcClient = this.tcClient) === null || _this$tcClient === void 0 || _this$tcClient.flushCache(); (_this$rovoAgentClient = this.rovoAgentClient) === null || _this$rovoAgentClient === void 0 || _this$rovoAgentClient.flushCache(); } }, { key: "getProfile", value: function getProfile(cloudId, userId, analytics) { return this.userClient.getProfile(cloudId, userId, analytics); } }, { key: "getTeamProfile", value: function getTeamProfile(teamId, orgId, analytics) { return this.teamClient.getProfile(teamId, orgId, analytics); } }, { key: "getReportingLines", value: function getReportingLines(userId) { var _this$tcClient2; return ((_this$tcClient2 = this.tcClient) === null || _this$tcClient2 === void 0 ? void 0 : _this$tcClient2.getReportingLines(userId)) || Promise.resolve({ managers: [], reports: [] }); } }, { key: "getTeamCentralBaseUrl", value: function () { var _getTeamCentralBaseUrl = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(teamCentralScopes) { var isGlobalExperienceWorkspace, suffix, orgId; return _regenerator.default.wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: if (!(this.tcClient === undefined)) { _context.next = 2; break; } return _context.abrupt("return", Promise.resolve(undefined)); case 2: _context.next = 4; return this.tcClient.getIsGlobalExperienceWorkspace(); case 4: isGlobalExperienceWorkspace = _context.sent; if (isGlobalExperienceWorkspace) { _context.next = 7; break; } return _context.abrupt("return", Promise.resolve((0, _atlassianContext.getATLContextUrl)('team'))); case 7: suffix = ''; if (!(teamCentralScopes !== undefined)) { _context.next = 16; break; } _context.next = 11; return this.tcClient.getOrgId(); case 11: orgId = _context.sent; if (!(orgId === null)) { _context.next = 14; break; } return _context.abrupt("return", Promise.resolve(undefined)); case 14: suffix += "/o/".concat(orgId); if (teamCentralScopes.withSiteContext) { suffix += "/s/".concat(this.tcClient.options.cloudId); } case 16: return _context.abrupt("return", Promise.resolve("".concat((0, _atlassianContext.getATLContextUrl)('home')).concat(suffix))); case 17: case "end": return _context.stop(); } }, _callee, this); })); function getTeamCentralBaseUrl(_x) { return _getTeamCentralBaseUrl.apply(this, arguments); } return getTeamCentralBaseUrl; }() }, { key: "shouldShowGiveKudos", value: function () { var _shouldShowGiveKudos = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() { return _regenerator.default.wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: _context2.t0 = !this.tcClient; if (_context2.t0) { _context2.next = 5; break; } _context2.next = 4; return this.getTeamCentralBaseUrl(); case 4: _context2.t0 = !_context2.sent; case 5: if (!_context2.t0) { _context2.next = 7; break; } return _context2.abrupt("return", Promise.resolve(false)); case 7: return _context2.abrupt("return", this.tcClient.checkWorkspaceExists()); case 8: case "end": return _context2.stop(); } }, _callee2, this); })); function shouldShowGiveKudos() { return _shouldShowGiveKudos.apply(this, arguments); } return shouldShowGiveKudos; }() }, { key: "getRovoAgentProfile", value: function getRovoAgentProfile(id, analytics) { var _this$rovoAgentClient2; return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(id, analytics); } }, { key: "getRovoAgentPermissions", value: function getRovoAgentPermissions(id, fireAnalytics) { var _this$rovoAgentClient3; return (_this$rovoAgentClient3 = this.rovoAgentClient) === null || _this$rovoAgentClient3 === void 0 ? void 0 : _this$rovoAgentClient3.getPermissions(id, fireAnalytics); } }, { key: "deleteAgent", value: function deleteAgent(id, analytics) { var _this$rovoAgentClient4; return (_this$rovoAgentClient4 = this.rovoAgentClient) === null || _this$rovoAgentClient4 === void 0 ? void 0 : _this$rovoAgentClient4.deleteAgent(id, analytics); } }, { key: "setFavouriteAgent", value: function setFavouriteAgent(id, isFavourite, analytics) { var _this$rovoAgentClient5; return (_this$rovoAgentClient5 = this.rovoAgentClient) === null || _this$rovoAgentClient5 === void 0 ? void 0 : _this$rovoAgentClient5.setFavouriteAgent(id, isFavourite, analytics); } }]); }(); function maybeCreateTeamCentralClient(config, clients) { if ((0, _atlassianContext.isFedRamp)()) { return undefined; } if (clients !== null && clients !== void 0 && clients.teamCentralClient) { return clients.teamCentralClient; } var teamCentralEnabled = config.teamCentralDisabled !== true; return teamCentralEnabled ? new _TeamCentralCardClient.default(_objectSpread({}, config)) : undefined; } var _default = exports.default = ProfileCardClient;