@atlaskit/profilecard 16.4.7 → 16.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/client/ProfileCardClient.js +16 -0
  3. package/dist/cjs/client/TeamCentralCardClient.js +91 -5
  4. package/dist/cjs/components/User/ProfileCard.js +62 -25
  5. package/dist/cjs/components/User/ProfileCardResourced.js +63 -13
  6. package/dist/cjs/components/User/ProfileCardTrigger.js +60 -12
  7. package/dist/cjs/messages.js +5 -0
  8. package/dist/cjs/mocks/mock-profile-client.js +5 -0
  9. package/dist/cjs/styled/Card.js +1 -1
  10. package/dist/cjs/util/analytics.js +1 -1
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/client/ProfileCardClient.js +14 -0
  13. package/dist/es2019/client/TeamCentralCardClient.js +57 -0
  14. package/dist/es2019/components/User/ProfileCard.js +53 -16
  15. package/dist/es2019/components/User/ProfileCardResourced.js +51 -11
  16. package/dist/es2019/components/User/ProfileCardTrigger.js +51 -8
  17. package/dist/es2019/messages.js +5 -0
  18. package/dist/es2019/mocks/mock-profile-client.js +4 -0
  19. package/dist/es2019/styled/Card.js +3 -1
  20. package/dist/es2019/util/analytics.js +1 -1
  21. package/dist/es2019/version.json +1 -1
  22. package/dist/esm/client/ProfileCardClient.js +16 -0
  23. package/dist/esm/client/TeamCentralCardClient.js +91 -5
  24. package/dist/esm/components/User/ProfileCard.js +65 -25
  25. package/dist/esm/components/User/ProfileCardResourced.js +57 -13
  26. package/dist/esm/components/User/ProfileCardTrigger.js +60 -12
  27. package/dist/esm/messages.js +5 -0
  28. package/dist/esm/mocks/mock-profile-client.js +5 -0
  29. package/dist/esm/styled/Card.js +1 -1
  30. package/dist/esm/util/analytics.js +1 -1
  31. package/dist/esm/version.json +1 -1
  32. package/dist/types/client/ProfileCardClient.d.ts +2 -0
  33. package/dist/types/client/TeamCentralCardClient.d.ts +7 -0
  34. package/dist/types/client/graphqlUtils.d.ts +1 -1
  35. package/dist/types/components/User/ProfileCard.d.ts +6 -2
  36. package/dist/types/components/User/ProfileCardResourced.d.ts +3 -1
  37. package/dist/types/components/User/ProfileCardTrigger.d.ts +3 -1
  38. package/dist/types/messages.d.ts +5 -0
  39. package/dist/types/types.d.ts +21 -1
  40. package/package.json +8 -6
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/profilecard",
3
- "version": "16.4.7"
3
+ "version": "16.6.0"
4
4
  }
@@ -34,6 +34,20 @@ class ProfileCardClient {
34
34
  });
35
35
  }
36
36
 
37
+ getTeamCentralBaseUrl() {
38
+ var _this$tcClient3;
39
+
40
+ return (_this$tcClient3 = this.tcClient) === null || _this$tcClient3 === void 0 ? void 0 : _this$tcClient3.options.teamCentralBaseUrl;
41
+ }
42
+
43
+ shouldShowGiveKudos() {
44
+ var _this$tcClient4, _this$tcClient5, _this$tcClient6;
45
+
46
+ // Check if the kudos feature enabled and if the user has TC
47
+ // if the user does not have TC the tc client will be undefined.
48
+ return ((_this$tcClient4 = this.tcClient) === null || _this$tcClient4 === void 0 ? void 0 : _this$tcClient4.options.teamCentralBaseUrl) && ((_this$tcClient5 = this.tcClient) === null || _this$tcClient5 === void 0 ? void 0 : _this$tcClient5.getFlagEnabled('team-central-kudos-enabled-m2', (_this$tcClient6 = this.tcClient) === null || _this$tcClient6 === void 0 ? void 0 : _this$tcClient6.options.productIdentifier)) || Promise.resolve(false);
49
+ }
50
+
37
51
  }
38
52
 
39
53
  function maybeCreateTeamCentralClient(config, clients) {
@@ -32,6 +32,20 @@ const buildReportingLinesQuery = aaid => ({
32
32
  }
33
33
  });
34
34
 
35
+ const buildCheckFeatureFlagQuery = (featureKey, context) => ({
36
+ query: `
37
+ query isFeatureKeyEnabled($featureKey: String!, $context: [IsFeatureEnabledContextInput]) {
38
+ isFeatureEnabled(featureKey: $featureKey, context: $context) {
39
+ enabled
40
+ }
41
+ }
42
+ `,
43
+ variables: {
44
+ featureKey,
45
+ context
46
+ }
47
+ });
48
+
35
49
  class TeamCentralCardClient extends CachingClient {
36
50
  /**
37
51
  * Simple circuit breaker to avoid making unnecessary calls to Team Central on auth failures
@@ -45,6 +59,17 @@ class TeamCentralCardClient extends CachingClient {
45
59
  super(options);
46
60
  this.options = options;
47
61
  this.bypassOnFailure = false;
62
+ this.featureFlagKeys = new Map();
63
+ }
64
+
65
+ async makeFeatureFlagCheckRequest(featureKey, context) {
66
+ if (!this.options.teamCentralUrl) {
67
+ throw new Error('options.teamCentralUrl is a required parameter for retrieving Team Central data');
68
+ }
69
+
70
+ const query = buildCheckFeatureFlagQuery(featureKey, context);
71
+ const response = await graphqlQuery(this.options.teamCentralUrl, query);
72
+ return response.isFeatureEnabled.enabled;
48
73
  }
49
74
 
50
75
  async makeRequest(userId) {
@@ -100,6 +125,38 @@ class TeamCentralCardClient extends CachingClient {
100
125
  });
101
126
  }
102
127
 
128
+ getFlagEnabled(featureKey, productIdentifier) {
129
+ if (!featureKey) {
130
+ return Promise.reject(new Error('featureKey missing'));
131
+ }
132
+
133
+ if (this.featureFlagKeys.has(featureKey)) {
134
+ return Promise.resolve(this.featureFlagKeys.get(featureKey));
135
+ }
136
+
137
+ if (this.bypassOnFailure) {
138
+ return Promise.resolve(false);
139
+ }
140
+
141
+ const context = [{
142
+ key: 'productIdentifier',
143
+ value: productIdentifier || 'unset'
144
+ }];
145
+ return new Promise(resolve => {
146
+ this.makeFeatureFlagCheckRequest(featureKey, context).then(enabled => {
147
+ this.featureFlagKeys.set(featureKey, enabled);
148
+ resolve(enabled);
149
+ }).catch(error => {
150
+ if ((error === null || error === void 0 ? void 0 : error.status) === 401 || (error === null || error === void 0 ? void 0 : error.status) === 403) {
151
+ // Trigger circuit breaker
152
+ this.bypassOnFailure = true;
153
+ }
154
+
155
+ resolve(false);
156
+ });
157
+ });
158
+ }
159
+
103
160
  filterReportingLinesUser(users = []) {
104
161
  return users.filter(user => user.identifierType === 'ATLASSIAN_ID');
105
162
  }
@@ -37,6 +37,39 @@ export default class Profilecard extends React.PureComponent {
37
37
  }
38
38
  });
39
39
 
40
+ _defineProperty(this, "kudosUrl", () => {
41
+ const recipientId = this.props.userId && `&recipientId=${this.props.userId}` || '';
42
+ const cloudId = this.props.cloudId && `&cloudId=${this.props.cloudId}` || '';
43
+ return `${this.props.teamCentralBaseUrl}/kudos/give?type=individual${recipientId}${cloudId}`;
44
+ });
45
+
46
+ _defineProperty(this, "kudosButtonCallback", () => {
47
+ if (this.props.openKudosDrawer) {
48
+ this.props.openKudosDrawer();
49
+ } else {
50
+ window.open(this.kudosUrl());
51
+ }
52
+ });
53
+
54
+ _defineProperty(this, "renderButton", (action, idx) => {
55
+ return /*#__PURE__*/React.createElement(Button, {
56
+ appearance: idx === 0 ? 'default' : 'subtle',
57
+ key: action.id || idx,
58
+ onClick: (event, ...args) => {
59
+ this.callAnalytics(AnalyticsName.PROFILE_CARD_CLICK, {
60
+ id: action.id || null,
61
+ duration: this.durationSince(this.timeOpen)
62
+ });
63
+
64
+ if (action.callback && isBasicClick(event)) {
65
+ event.preventDefault();
66
+ action.callback(event, ...args);
67
+ }
68
+ },
69
+ href: action.link
70
+ }, action.label);
71
+ });
72
+
40
73
  this.timeOpen = null;
41
74
 
42
75
  this.clientFetchProfile = (...args) => {
@@ -57,27 +90,31 @@ export default class Profilecard extends React.PureComponent {
57
90
  });
58
91
  }
59
92
 
93
+ getActions() {
94
+ const actions = this.props.actions || [];
95
+
96
+ if (!this.props.isCurrentUser && this.props.isKudosEnabled) {
97
+ const kudosAction = {
98
+ label: /*#__PURE__*/React.createElement(FormattedMessage, messages.giveKudosButton),
99
+ id: 'give-kudos',
100
+ callback: () => {
101
+ this.kudosButtonCallback();
102
+ },
103
+ link: this.kudosUrl()
104
+ };
105
+ return actions.concat([kudosAction]);
106
+ }
107
+
108
+ return actions;
109
+ }
110
+
60
111
  renderActionsButtons() {
61
112
  if (this.props.actions && this.props.actions.length === 0) {
62
113
  return null;
63
114
  }
64
115
 
65
- return /*#__PURE__*/React.createElement(ActionButtonGroup, null, this.props.actions && this.props.actions.map((action, idx) => /*#__PURE__*/React.createElement(Button, {
66
- appearance: idx === 0 ? 'default' : 'subtle',
67
- key: action.id || idx,
68
- onClick: (event, ...args) => {
69
- this.callAnalytics(AnalyticsName.PROFILE_CARD_CLICK, {
70
- id: action.id || null,
71
- duration: this.durationSince(this.timeOpen)
72
- });
73
-
74
- if (action.callback && isBasicClick(event)) {
75
- event.preventDefault();
76
- action.callback(event, ...args);
77
- }
78
- },
79
- href: action.link
80
- }, action.label)));
116
+ const actions = this.getActions();
117
+ return /*#__PURE__*/React.createElement(ActionButtonGroup, null, actions.map((action, idx) => this.renderButton(action, idx)));
81
118
  }
82
119
 
83
120
  renderCardDetailsDefault() {
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import React from 'react';
3
+ import React, { Suspense } from 'react';
4
+ import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
4
5
  import { AnalyticsName } from '../../internal/analytics';
5
6
  import filterActions from '../../internal/filterActions';
6
7
  import { CardWrapper } from '../../styled/Card';
@@ -19,7 +20,9 @@ export default class ProfileCardResourced extends React.PureComponent {
19
20
  hasError: false,
20
21
  error: null,
21
22
  data: null,
22
- reportingLinesData: undefined
23
+ reportingLinesData: undefined,
24
+ isKudosEnabled: false,
25
+ kudosDrawerOpen: false
23
26
  });
24
27
 
25
28
  _defineProperty(this, "callAnalytics", (id, options = {}) => {
@@ -51,12 +54,24 @@ export default class ProfileCardResourced extends React.PureComponent {
51
54
  hasError: false,
52
55
  data: null
53
56
  }, () => {
54
- const requests = Promise.all([this.props.resourceClient.getProfile(cloudId, userId), this.props.resourceClient.getReportingLines(userId)]);
55
- requests.then(res => this.handleClientSuccess(res[0], res[1]), err => this.handleClientError(err)).catch(err => this.handleClientError(err));
57
+ const requests = Promise.all([this.props.resourceClient.getProfile(cloudId, userId), this.props.resourceClient.getReportingLines(userId), this.props.resourceClient.shouldShowGiveKudos()]);
58
+ requests.then(res => this.handleClientSuccess(...res), err => this.handleClientError(err)).catch(err => this.handleClientError(err));
56
59
  });
57
60
  });
58
61
 
59
62
  _defineProperty(this, "filterActions", () => filterActions(this.props.actions, this.state.data));
63
+
64
+ _defineProperty(this, "openKudosDrawer", () => {
65
+ this.setState({
66
+ kudosDrawerOpen: true
67
+ });
68
+ });
69
+
70
+ _defineProperty(this, "closeKudosDrawer", () => {
71
+ this.setState({
72
+ kudosDrawerOpen: false
73
+ });
74
+ });
60
75
  }
61
76
 
62
77
  componentDidMount() {
@@ -89,7 +104,7 @@ export default class ProfileCardResourced extends React.PureComponent {
89
104
  this._isMounted = false;
90
105
  }
91
106
 
92
- handleClientSuccess(profileData, reportingLinesData) {
107
+ handleClientSuccess(profileData, reportingLinesData, shouldShowGiveKudos) {
93
108
  if (!this._isMounted) {
94
109
  return;
95
110
  }
@@ -98,7 +113,8 @@ export default class ProfileCardResourced extends React.PureComponent {
98
113
  isLoading: false,
99
114
  hasError: false,
100
115
  data: profileData,
101
- reportingLinesData
116
+ reportingLinesData,
117
+ isKudosEnabled: shouldShowGiveKudos
102
118
  });
103
119
  }
104
120
 
@@ -120,11 +136,15 @@ export default class ProfileCardResourced extends React.PureComponent {
120
136
  hasError,
121
137
  error,
122
138
  data,
123
- reportingLinesData
139
+ reportingLinesData,
140
+ isKudosEnabled
124
141
  } = this.state;
125
142
  const {
126
143
  analytics,
127
- onReportingLinesClick
144
+ onReportingLinesClick,
145
+ cloudId,
146
+ userId,
147
+ addFlag
128
148
  } = this.props;
129
149
  const isFetchingOrNotStartToFetchYet = isLoading === true || isLoading === undefined;
130
150
 
@@ -144,11 +164,31 @@ export default class ProfileCardResourced extends React.PureComponent {
144
164
  analytics,
145
165
  reportingLines: reportingLinesData,
146
166
  onReportingLinesClick: onReportingLinesClick,
147
- ...data
167
+ cloudId,
168
+ userId,
169
+ addFlag,
170
+ ...data,
171
+ isKudosEnabled,
172
+ teamCentralBaseUrl: this.props.resourceClient.getTeamCentralBaseUrl(),
173
+ openKudosDrawer: this.openKudosDrawer
148
174
  };
149
- return /*#__PURE__*/React.createElement(CardWrapper, null, /*#__PURE__*/React.createElement(ProfileCard, _extends({}, newProps, {
175
+ return /*#__PURE__*/React.createElement(CardWrapper, null, /*#__PURE__*/React.createElement(React.Fragment, null, isKudosEnabled && /*#__PURE__*/React.createElement(Suspense, {
176
+ fallback: null
177
+ }, /*#__PURE__*/React.createElement(GiveKudosLauncherLazy, {
178
+ isOpen: this.state.kudosDrawerOpen,
179
+ recipient: {
180
+ type: KudosType.INDIVIDUAL,
181
+ recipientId: this.props.userId
182
+ },
183
+ analytics: this.props.analytics,
184
+ analyticsSource: "profile-card",
185
+ teamCentralBaseUrl: newProps.teamCentralBaseUrl,
186
+ cloudId: this.props.cloudId,
187
+ addFlag: this.props.addFlag,
188
+ onClose: this.closeKudosDrawer
189
+ })), /*#__PURE__*/React.createElement(ProfileCard, _extends({}, newProps, {
150
190
  actions: this.filterActions()
151
- })));
191
+ }))));
152
192
  }
153
193
 
154
194
  }
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import React, { Suspense } from 'react';
4
+ import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
4
5
  import Popup from '@atlaskit/popup';
5
6
  import { layers } from '@atlaskit/theme/constants';
6
7
  import filterActions from '../../internal/filterActions';
@@ -72,7 +73,10 @@ class ProfilecardTrigger extends React.PureComponent {
72
73
  hasError: false,
73
74
  error: null,
74
75
  data: null,
75
- reportingLinesData: undefined
76
+ reportingLinesData: undefined,
77
+ shouldShowGiveKudos: false,
78
+ teamCentralBaseUrl: undefined,
79
+ kudosDrawerOpen: false
76
80
  });
77
81
 
78
82
  _defineProperty(this, "clientFetchProfile", () => {
@@ -89,13 +93,29 @@ class ProfilecardTrigger extends React.PureComponent {
89
93
  return;
90
94
  }
91
95
 
96
+ this.setState({
97
+ teamCentralBaseUrl: this.props.resourceClient.getTeamCentralBaseUrl()
98
+ });
92
99
  this.setState({
93
100
  isLoading: true,
94
101
  hasError: false,
95
102
  data: null
96
103
  }, () => {
97
- const requests = Promise.all([this.props.resourceClient.getProfile(cloudId || '', userId), this.props.resourceClient.getReportingLines(userId)]);
98
- requests.then(res => this.handleClientSuccess(res[0], res[1]), err => this.handleClientError(err)).catch(err => this.handleClientError(err));
104
+ const requests = Promise.all([this.props.resourceClient.getProfile(cloudId || '', userId), this.props.resourceClient.getReportingLines(userId), this.props.resourceClient.shouldShowGiveKudos()]);
105
+ requests.then(res => this.handleClientSuccess(...res), err => this.handleClientError(err)).catch(err => this.handleClientError(err));
106
+ });
107
+ });
108
+
109
+ _defineProperty(this, "openKudosDrawer", () => {
110
+ this.hideProfilecard();
111
+ this.setState({
112
+ kudosDrawerOpen: true
113
+ });
114
+ });
115
+
116
+ _defineProperty(this, "closeKudosDrawer", () => {
117
+ this.setState({
118
+ kudosDrawerOpen: false
99
119
  });
100
120
  });
101
121
 
@@ -139,7 +159,7 @@ class ProfilecardTrigger extends React.PureComponent {
139
159
  clearTimeout(this.hideTimer);
140
160
  }
141
161
 
142
- handleClientSuccess(profileData, reportingLinesData) {
162
+ handleClientSuccess(profileData, reportingLinesData, shouldShowGiveKudos) {
143
163
  if (!this._isMounted) {
144
164
  return;
145
165
  }
@@ -148,7 +168,8 @@ class ProfilecardTrigger extends React.PureComponent {
148
168
  isLoading: false,
149
169
  hasError: false,
150
170
  data: profileData,
151
- reportingLinesData
171
+ reportingLinesData,
172
+ shouldShowGiveKudos
152
173
  });
153
174
  }
154
175
 
@@ -169,12 +190,20 @@ class ProfilecardTrigger extends React.PureComponent {
169
190
  }
170
191
 
171
192
  renderProfileCard() {
193
+ var _this$state$data;
194
+
172
195
  const newProps = {
196
+ userId: this.props.userId,
197
+ isCurrentUser: (_this$state$data = this.state.data) === null || _this$state$data === void 0 ? void 0 : _this$state$data.isCurrentUser,
173
198
  clientFetchProfile: this.clientFetchProfile,
174
199
  analytics: this.props.analytics,
175
200
  ...this.state.data,
176
201
  reportingLines: this.state.reportingLinesData,
177
- onReportingLinesClick: this.props.onReportingLinesClick
202
+ onReportingLinesClick: this.props.onReportingLinesClick,
203
+ isKudosEnabled: this.state.shouldShowGiveKudos,
204
+ teamCentralBaseUrl: this.state.teamCentralBaseUrl,
205
+ cloudId: this.props.cloudId,
206
+ openKudosDrawer: this.openKudosDrawer
178
207
  };
179
208
  const wrapperProps = this.props.trigger === 'hover' ? {
180
209
  onMouseEnter: this.showProfilecard,
@@ -191,7 +220,7 @@ class ProfilecardTrigger extends React.PureComponent {
191
220
  }
192
221
 
193
222
  renderWithTrigger() {
194
- return /*#__PURE__*/React.createElement(Popup, {
223
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popup, {
195
224
  isOpen: !!this.state.visible,
196
225
  onClose: this.hideProfilecard,
197
226
  placement: this.props.position,
@@ -208,7 +237,21 @@ class ProfilecardTrigger extends React.PureComponent {
208
237
  },
209
238
  zIndex: layers.modal(),
210
239
  shouldUseCaptureOnOutsideClick: true
211
- });
240
+ }), this.state.shouldShowGiveKudos && /*#__PURE__*/React.createElement(Suspense, {
241
+ fallback: null
242
+ }, /*#__PURE__*/React.createElement(GiveKudosLauncherLazy, {
243
+ isOpen: this.state.kudosDrawerOpen,
244
+ recipient: {
245
+ type: KudosType.INDIVIDUAL,
246
+ recipientId: this.props.userId
247
+ },
248
+ analytics: this.props.analytics,
249
+ analyticsSource: "profile-card",
250
+ teamCentralBaseUrl: this.state.teamCentralBaseUrl,
251
+ cloudId: this.props.cloudId,
252
+ addFlag: this.props.addFlag,
253
+ onClose: this.closeKudosDrawer
254
+ })));
212
255
  }
213
256
 
214
257
  render() {
@@ -139,6 +139,11 @@ const messages = defineMessages({
139
139
  id: 'pt.team-profile-card.directReports.heading',
140
140
  defaultMessage: 'Direct reports',
141
141
  description: "Title for a section on the profile card that show the user's direct reports"
142
+ },
143
+ giveKudosButton: {
144
+ id: 'pt.profile-card.give-kudos',
145
+ defaultMessage: 'Give kudos',
146
+ description: 'Title for the button on the profile card for a user to give a kudos'
142
147
  }
143
148
  });
144
149
  export default messages;
@@ -57,6 +57,10 @@ export default function getMockProfileClient(BaseProfileClient, modifyResponse)
57
57
  });
58
58
  }
59
59
 
60
+ getFlagEnabled(featureKey) {
61
+ return Promise.resolve(true);
62
+ }
63
+
60
64
  }
61
65
 
62
66
  return class MockProfileClient extends BaseProfileClient {
@@ -23,7 +23,9 @@ export const ActionButtonGroup = styled.div`
23
23
  margin: ${2 * gridSize()}px 0 0 0;
24
24
  text-align: right;
25
25
 
26
- button {
26
+ button,
27
+ a,
28
+ span {
27
29
  margin-left: ${gridSize}px;
28
30
 
29
31
  &:first-child {
@@ -35,7 +35,7 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
35
35
  actionSubjectId,
36
36
  attributes: {
37
37
  packageName: "@atlaskit/profilecard",
38
- packageVersion: "16.4.7",
38
+ packageVersion: "16.6.0",
39
39
  ...attributes,
40
40
  firedAt: getPageTime()
41
41
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/profilecard",
3
- "version": "16.4.7"
3
+ "version": "16.6.0"
4
4
  }
@@ -48,6 +48,22 @@ var ProfileCardClient = /*#__PURE__*/function () {
48
48
  reports: []
49
49
  });
50
50
  }
51
+ }, {
52
+ key: "getTeamCentralBaseUrl",
53
+ value: function getTeamCentralBaseUrl() {
54
+ var _this$tcClient3;
55
+
56
+ return (_this$tcClient3 = this.tcClient) === null || _this$tcClient3 === void 0 ? void 0 : _this$tcClient3.options.teamCentralBaseUrl;
57
+ }
58
+ }, {
59
+ key: "shouldShowGiveKudos",
60
+ value: function shouldShowGiveKudos() {
61
+ var _this$tcClient4, _this$tcClient5, _this$tcClient6;
62
+
63
+ // Check if the kudos feature enabled and if the user has TC
64
+ // if the user does not have TC the tc client will be undefined.
65
+ return ((_this$tcClient4 = this.tcClient) === null || _this$tcClient4 === void 0 ? void 0 : _this$tcClient4.options.teamCentralBaseUrl) && ((_this$tcClient5 = this.tcClient) === null || _this$tcClient5 === void 0 ? void 0 : _this$tcClient5.getFlagEnabled('team-central-kudos-enabled-m2', (_this$tcClient6 = this.tcClient) === null || _this$tcClient6 === void 0 ? void 0 : _this$tcClient6.options.productIdentifier)) || Promise.resolve(false);
66
+ }
51
67
  }]);
52
68
 
53
69
  return ProfileCardClient;
@@ -22,6 +22,16 @@ var buildReportingLinesQuery = function buildReportingLinesQuery(aaid) {
22
22
  };
23
23
  };
24
24
 
25
+ var buildCheckFeatureFlagQuery = function buildCheckFeatureFlagQuery(featureKey, context) {
26
+ return {
27
+ query: "\n query isFeatureKeyEnabled($featureKey: String!, $context: [IsFeatureEnabledContextInput]) {\n isFeatureEnabled(featureKey: $featureKey, context: $context) {\n enabled\n }\n }\n ",
28
+ variables: {
29
+ featureKey: featureKey,
30
+ context: context
31
+ }
32
+ };
33
+ };
34
+
25
35
  var TeamCentralCardClient = /*#__PURE__*/function (_CachingClient) {
26
36
  _inherits(TeamCentralCardClient, _CachingClient);
27
37
 
@@ -43,13 +53,14 @@ var TeamCentralCardClient = /*#__PURE__*/function (_CachingClient) {
43
53
  _this = _super.call(this, options);
44
54
  _this.options = options;
45
55
  _this.bypassOnFailure = false;
56
+ _this.featureFlagKeys = new Map();
46
57
  return _this;
47
58
  }
48
59
 
49
60
  _createClass(TeamCentralCardClient, [{
50
- key: "makeRequest",
61
+ key: "makeFeatureFlagCheckRequest",
51
62
  value: function () {
52
- var _makeRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(userId) {
63
+ var _makeFeatureFlagCheckRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(featureKey, context) {
53
64
  var query, response;
54
65
  return _regeneratorRuntime.wrap(function _callee$(_context) {
55
66
  while (1) {
@@ -63,13 +74,13 @@ var TeamCentralCardClient = /*#__PURE__*/function (_CachingClient) {
63
74
  throw new Error('options.teamCentralUrl is a required parameter for retrieving Team Central data');
64
75
 
65
76
  case 2:
66
- query = buildReportingLinesQuery(userId);
77
+ query = buildCheckFeatureFlagQuery(featureKey, context);
67
78
  _context.next = 5;
68
79
  return graphqlQuery(this.options.teamCentralUrl, query);
69
80
 
70
81
  case 5:
71
82
  response = _context.sent;
72
- return _context.abrupt("return", response.reportingLines);
83
+ return _context.abrupt("return", response.isFeatureEnabled.enabled);
73
84
 
74
85
  case 7:
75
86
  case "end":
@@ -79,7 +90,46 @@ var TeamCentralCardClient = /*#__PURE__*/function (_CachingClient) {
79
90
  }, _callee, this);
80
91
  }));
81
92
 
82
- function makeRequest(_x) {
93
+ function makeFeatureFlagCheckRequest(_x, _x2) {
94
+ return _makeFeatureFlagCheckRequest.apply(this, arguments);
95
+ }
96
+
97
+ return makeFeatureFlagCheckRequest;
98
+ }()
99
+ }, {
100
+ key: "makeRequest",
101
+ value: function () {
102
+ var _makeRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(userId) {
103
+ var query, response;
104
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
105
+ while (1) {
106
+ switch (_context2.prev = _context2.next) {
107
+ case 0:
108
+ if (this.options.teamCentralUrl) {
109
+ _context2.next = 2;
110
+ break;
111
+ }
112
+
113
+ throw new Error('options.teamCentralUrl is a required parameter for retrieving Team Central data');
114
+
115
+ case 2:
116
+ query = buildReportingLinesQuery(userId);
117
+ _context2.next = 5;
118
+ return graphqlQuery(this.options.teamCentralUrl, query);
119
+
120
+ case 5:
121
+ response = _context2.sent;
122
+ return _context2.abrupt("return", response.reportingLines);
123
+
124
+ case 7:
125
+ case "end":
126
+ return _context2.stop();
127
+ }
128
+ }
129
+ }, _callee2, this);
130
+ }));
131
+
132
+ function makeRequest(_x3) {
83
133
  return _makeRequest.apply(this, arguments);
84
134
  }
85
135
 
@@ -131,6 +181,42 @@ var TeamCentralCardClient = /*#__PURE__*/function (_CachingClient) {
131
181
  });
132
182
  });
133
183
  }
184
+ }, {
185
+ key: "getFlagEnabled",
186
+ value: function getFlagEnabled(featureKey, productIdentifier) {
187
+ var _this3 = this;
188
+
189
+ if (!featureKey) {
190
+ return Promise.reject(new Error('featureKey missing'));
191
+ }
192
+
193
+ if (this.featureFlagKeys.has(featureKey)) {
194
+ return Promise.resolve(this.featureFlagKeys.get(featureKey));
195
+ }
196
+
197
+ if (this.bypassOnFailure) {
198
+ return Promise.resolve(false);
199
+ }
200
+
201
+ var context = [{
202
+ key: 'productIdentifier',
203
+ value: productIdentifier || 'unset'
204
+ }];
205
+ return new Promise(function (resolve) {
206
+ _this3.makeFeatureFlagCheckRequest(featureKey, context).then(function (enabled) {
207
+ _this3.featureFlagKeys.set(featureKey, enabled);
208
+
209
+ resolve(enabled);
210
+ }).catch(function (error) {
211
+ if ((error === null || error === void 0 ? void 0 : error.status) === 401 || (error === null || error === void 0 ? void 0 : error.status) === 403) {
212
+ // Trigger circuit breaker
213
+ _this3.bypassOnFailure = true;
214
+ }
215
+
216
+ resolve(false);
217
+ });
218
+ });
219
+ }
134
220
  }, {
135
221
  key: "filterReportingLinesUser",
136
222
  value: function filterReportingLinesUser() {