UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

101 lines 4.62 kB
import { getATLContextUrl, isFedRamp } from '@atlaskit/atlassian-context'; import RovoAgentCardClient from './RovoAgentCardClient'; import TeamCentralCardClient from './TeamCentralCardClient'; import TeamProfileCardClient from './TeamProfileCardClient'; import UserProfileCardClient from './UserProfileCardClient'; const defaultConfig = { gatewayGraphqlUrl: '/gateway/api/graphql' }; class ProfileCardClient { constructor(config, clients) { var _config$gatewayGraphq; //This default can be removed once all the clients are updated to pass the gatewayGraphqlUrl const withDefaultConfig = { ...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); } flushCache() { var _this$tcClient, _this$rovoAgentClient; this.userClient.flushCache(); this.teamClient.flushCache(); (_this$tcClient = this.tcClient) === null || _this$tcClient === void 0 ? void 0 : _this$tcClient.flushCache(); (_this$rovoAgentClient = this.rovoAgentClient) === null || _this$rovoAgentClient === void 0 ? void 0 : _this$rovoAgentClient.flushCache(); } getProfile(cloudId, userId, analytics) { return this.userClient.getProfile(cloudId, userId, analytics); } getTeamProfile(teamId, orgId, analytics) { return this.teamClient.getProfile(teamId, orgId, analytics); } 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: [] }); } async getTeamCentralBaseUrl(teamCentralScopes) { if (this.tcClient === undefined) { return Promise.resolve(undefined); } const isGlobalExperienceWorkspace = await this.tcClient.getIsGlobalExperienceWorkspace(); if (!isGlobalExperienceWorkspace) { return Promise.resolve(getATLContextUrl('team')); } let suffix = ''; if (teamCentralScopes !== undefined) { const orgId = await this.tcClient.getOrgId(); if (orgId === null) { return Promise.resolve(undefined); } suffix += `/o/${orgId}`; if (teamCentralScopes.withSiteContext) { suffix += `/s/${this.tcClient.options.cloudId}`; } } return Promise.resolve(`${getATLContextUrl('home')}${suffix}`); } async shouldShowGiveKudos() { if (!this.tcClient || !(await this.getTeamCentralBaseUrl())) { return Promise.resolve(false); } return this.tcClient.checkWorkspaceExists(); } getRovoAgentProfile(id, analytics) { var _this$rovoAgentClient2; return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(id, analytics); } getRovoAgentPermissions(id, fireAnalytics) { var _this$rovoAgentClient3; return (_this$rovoAgentClient3 = this.rovoAgentClient) === null || _this$rovoAgentClient3 === void 0 ? void 0 : _this$rovoAgentClient3.getPermissions(id, fireAnalytics); } deleteAgent(id, analytics) { var _this$rovoAgentClient4; return (_this$rovoAgentClient4 = this.rovoAgentClient) === null || _this$rovoAgentClient4 === void 0 ? void 0 : _this$rovoAgentClient4.deleteAgent(id, analytics); } 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; } const teamCentralEnabled = config.teamCentralDisabled !== true; return teamCentralEnabled ? new TeamCentralCardClient({ ...config }) : undefined; } export default ProfileCardClient;