@atlaskit/profilecard
Version:
A React component to display a card with user information.
184 lines • 8.71 kB
JavaScript
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _regeneratorRuntime from "@babel/runtime/regenerator";
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; }
import { getATLContextUrl, isFedRamp } from '@atlaskit/atlassian-context';
import RovoAgentCardClient from './RovoAgentCardClient';
import TeamCentralCardClient from './TeamCentralCardClient';
import TeamProfileCardClient from './TeamProfileCardClient';
import UserProfileCardClient from './UserProfileCardClient';
var defaultConfig = {
gatewayGraphqlUrl: '/gateway/api/graphql'
};
var ProfileCardClient = /*#__PURE__*/function () {
function ProfileCardClient(config, clients) {
var _config$gatewayGraphq;
_classCallCheck(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(withDefaultConfig);
this.teamClient = (clients === null || clients === void 0 ? void 0 : clients.teamClient) || new TeamProfileCardClient(withDefaultConfig);
this.rovoAgentClient = (clients === null || clients === void 0 ? void 0 : clients.rovoAgentClient) || new RovoAgentCardClient(withDefaultConfig);
this.tcClient = maybeCreateTeamCentralClient(withDefaultConfig, clients);
}
return _createClass(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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(teamCentralScopes) {
var isGlobalExperienceWorkspace, suffix, orgId;
return _regeneratorRuntime.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(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(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 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
return _regeneratorRuntime.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 (isFedRamp()) {
return undefined;
}
if (clients !== null && clients !== void 0 && clients.teamCentralClient) {
return clients.teamCentralClient;
}
var teamCentralEnabled = config.teamCentralDisabled !== true;
return teamCentralEnabled ? new TeamCentralCardClient(_objectSpread({}, config)) : undefined;
}
export default ProfileCardClient;