@atlaskit/profilecard 19.11.8 → 19.13.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.
@@ -1,347 +1,329 @@
1
1
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
3
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
6
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
7
- var _excluded = ["ref"],
8
- _excluded2 = ["aria-expanded", "aria-haspopup"];
4
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/createClass";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
7
+ import _inherits from "@babel/runtime/helpers/inherits";
8
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
9
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
10
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
+ var _excluded = ["ref"];
9
12
  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; }
10
13
  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; }
11
- import _regeneratorRuntime from "@babel/runtime/regenerator";
12
- import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
- import { useIntl } from 'react-intl-next';
14
- import { useAnalyticsEvents } from '@atlaskit/analytics-next';
14
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
16
+ import React, { Suspense } from 'react';
17
+ import { withAnalyticsEvents } from '@atlaskit/analytics-next';
15
18
  import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
19
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
16
20
  import Popup from '@atlaskit/popup';
17
21
  import { layers } from '@atlaskit/theme/constants';
18
- import filterActionsInner from '../../internal/filterActions';
19
- import getLabelMessage from '../../internal/getLabelMessage';
22
+ import _filterActions from '../../internal/filterActions';
20
23
  import { CardWrapper } from '../../styled/Card';
21
24
  import { cardTriggered, fireEvent } from '../../util/analytics';
22
25
  import { DELAY_MS_HIDE, DELAY_MS_SHOW } from '../../util/config';
23
26
  import { ProfileCardLazy } from './lazyProfileCard';
27
+ import ProfilecardTriggerNext from './ProfileCardTriggerNext';
24
28
  import UserLoadingState from './UserLoadingState';
25
- export default function ProfilecardTrigger(_ref) {
26
- var _ref$trigger = _ref.trigger,
27
- trigger = _ref$trigger === void 0 ? 'hover' : _ref$trigger,
28
- userId = _ref.userId,
29
- cloudId = _ref.cloudId,
30
- resourceClient = _ref.resourceClient,
31
- _ref$actions = _ref.actions,
32
- actions = _ref$actions === void 0 ? [] : _ref$actions,
33
- _ref$position = _ref.position,
34
- position = _ref$position === void 0 ? 'bottom-start' : _ref$position,
35
- children = _ref.children,
36
- testId = _ref.testId,
37
- addFlag = _ref.addFlag,
38
- onReportingLinesClick = _ref.onReportingLinesClick,
39
- ariaLabel = _ref.ariaLabel,
40
- ariaLabelledBy = _ref.ariaLabelledBy,
41
- prepopulatedData = _ref.prepopulatedData,
42
- disabledAriaAttributes = _ref.disabledAriaAttributes,
43
- onVisibilityChange = _ref.onVisibilityChange;
44
- var _useAnalyticsEvents = useAnalyticsEvents(),
45
- createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
46
- var _useIntl = useIntl(),
47
- formatMessage = _useIntl.formatMessage;
48
- var _useState = useState(false),
49
- _useState2 = _slicedToArray(_useState, 2),
50
- isMounted = _useState2[0],
51
- setIsMounted = _useState2[1];
52
- var showDelay = trigger === 'click' ? 0 : DELAY_MS_SHOW;
53
- var hideDelay = trigger === 'click' ? 0 : DELAY_MS_HIDE;
54
- var showTimer = useRef(0);
55
- var hideTimer = useRef(0);
56
- var _useState3 = useState(false),
57
- _useState4 = _slicedToArray(_useState3, 2),
58
- visible = _useState4[0],
59
- setVisible = _useState4[1];
60
- var _useState5 = useState(undefined),
61
- _useState6 = _slicedToArray(_useState5, 2),
62
- isLoading = _useState6[0],
63
- setIsLoading = _useState6[1];
64
- var _useState7 = useState(false),
65
- _useState8 = _slicedToArray(_useState7, 2),
66
- hasError = _useState8[0],
67
- setHasError = _useState8[1];
68
- var _useState9 = useState(null),
69
- _useState10 = _slicedToArray(_useState9, 2),
70
- error = _useState10[0],
71
- setError = _useState10[1];
72
- var _useState11 = useState(null),
73
- _useState12 = _slicedToArray(_useState11, 2),
74
- data = _useState12[0],
75
- setData = _useState12[1];
76
- var _useState13 = useState(undefined),
77
- _useState14 = _slicedToArray(_useState13, 2),
78
- reportingLinesData = _useState14[0],
79
- setReportingLinesData = _useState14[1];
80
- var _useState15 = useState(false),
81
- _useState16 = _slicedToArray(_useState15, 2),
82
- shouldShowGiveKudos = _useState16[0],
83
- setShouldShowGiveKudos = _useState16[1];
84
- var _useState17 = useState(undefined),
85
- _useState18 = _slicedToArray(_useState17, 2),
86
- teamCentralBaseUrl = _useState18[0],
87
- setTeamCentralBaseUrl = _useState18[1];
88
- var _useState19 = useState(false),
89
- _useState20 = _slicedToArray(_useState19, 2),
90
- kudosDrawerOpen = _useState20[0],
91
- setKudosDrawerOpen = _useState20[1];
92
- var _useState21 = useState(false),
93
- _useState22 = _slicedToArray(_useState21, 2),
94
- isTriggeredUsingKeyboard = _useState22[0],
95
- setTriggeredUsingKeyboard = _useState22[1];
96
- var triggerRef = useRef(null);
97
- useEffect(function () {
98
- setIsMounted(true);
99
- return function () {
100
- setIsMounted(false);
101
- clearTimeout(showTimer.current);
102
- clearTimeout(hideTimer.current);
103
- };
104
- // eslint-disable-next-line react-hooks/exhaustive-deps
105
- }, []);
106
- useEffect(function () {
107
- // Reset state when the userId changes
108
- setIsLoading(undefined);
109
- setHasError(false);
110
- setError(null);
111
- setData(null);
112
- setReportingLinesData(undefined);
113
- setShouldShowGiveKudos(false);
114
- setTeamCentralBaseUrl(undefined);
115
- }, [userId]);
116
- var fireAnalytics = useCallback(function (payload) {
117
- // Don't fire any analytics if the component is unmounted
118
- if (!isMounted) {
119
- return;
120
- }
121
- fireEvent(createAnalyticsEvent, payload);
122
- }, [createAnalyticsEvent, isMounted]);
123
- var hideProfilecard = useCallback(function () {
124
- clearTimeout(showTimer.current);
125
- clearTimeout(hideTimer.current);
126
- if (!isTriggeredUsingKeyboard) {
127
- hideTimer.current = window.setTimeout(function () {
128
- setVisible(false);
129
- onVisibilityChange && onVisibilityChange(false);
130
- }, hideDelay);
131
- }
132
- }, [hideDelay, isTriggeredUsingKeyboard, onVisibilityChange]);
133
- var handleKeyboardClose = useCallback(function (event) {
134
- if (event.key && event.key !== 'Escape') {
135
- return;
29
+ var ProfilecardTrigger = /*#__PURE__*/function (_React$PureComponent) {
30
+ _inherits(ProfilecardTrigger, _React$PureComponent);
31
+ var _super = _createSuper(ProfilecardTrigger);
32
+ function ProfilecardTrigger() {
33
+ var _this;
34
+ _classCallCheck(this, ProfilecardTrigger);
35
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
36
+ args[_key] = arguments[_key];
136
37
  }
137
- if (triggerRef.current) {
138
- triggerRef.current.focus();
38
+ _this = _super.call.apply(_super, [this].concat(args));
39
+ _defineProperty(_assertThisInitialized(_this), "_isMounted", false);
40
+ _defineProperty(_assertThisInitialized(_this), "showDelay", _this.props.trigger === 'click' ? 0 : DELAY_MS_SHOW);
41
+ _defineProperty(_assertThisInitialized(_this), "hideDelay", _this.props.trigger === 'click' ? 0 : DELAY_MS_HIDE);
42
+ _defineProperty(_assertThisInitialized(_this), "showTimer", 0);
43
+ _defineProperty(_assertThisInitialized(_this), "hideTimer", 0);
44
+ _defineProperty(_assertThisInitialized(_this), "fireAnalytics", function (payload) {
45
+ // Don't fire any analytics if the component is unmounted
46
+ if (!_this._isMounted) {
47
+ return;
48
+ }
49
+ if (_this.props.createAnalyticsEvent) {
50
+ fireEvent(_this.props.createAnalyticsEvent, payload);
51
+ }
52
+ });
53
+ _defineProperty(_assertThisInitialized(_this), "hideProfilecard", function () {
54
+ clearTimeout(_this.showTimer);
55
+ clearTimeout(_this.hideTimer);
56
+ _this.hideTimer = window.setTimeout(function () {
57
+ _this.setState({
58
+ visible: false
59
+ });
60
+ }, _this.hideDelay);
61
+ });
62
+ _defineProperty(_assertThisInitialized(_this), "showProfilecard", function () {
63
+ clearTimeout(_this.hideTimer);
64
+ clearTimeout(_this.showTimer);
65
+ _this.showTimer = window.setTimeout(function () {
66
+ if (!_this.state.visible) {
67
+ _this.clientFetchProfile();
68
+ _this.setState({
69
+ visible: true
70
+ });
71
+ }
72
+ }, _this.showDelay);
73
+ });
74
+ _defineProperty(_assertThisInitialized(_this), "onClick", function (event) {
75
+ // If the user clicks on the trigger then we don't want that click event to
76
+ // propagate out to parent containers. For example when clicking a mention
77
+ // lozenge in an inline-edit.
78
+ event.stopPropagation();
79
+ _this.showProfilecard();
80
+ if (!_this.state.visible) {
81
+ _this.fireAnalytics(cardTriggered('user', 'click'));
82
+ }
83
+ });
84
+ _defineProperty(_assertThisInitialized(_this), "onMouseEnter", function () {
85
+ _this.showProfilecard();
86
+ if (!_this.state.visible) {
87
+ _this.fireAnalytics(cardTriggered('user', 'hover'));
88
+ }
89
+ });
90
+ _defineProperty(_assertThisInitialized(_this), "onKeyPress", function (event) {
91
+ if (event.key === 'Enter' || event.key === ' ') {
92
+ event.preventDefault();
93
+ _this.showProfilecard();
94
+ if (!_this.state.visible) {
95
+ _this.fireAnalytics(cardTriggered('user', 'click'));
96
+ }
97
+ }
98
+ });
99
+ _defineProperty(_assertThisInitialized(_this), "onFocus", function () {
100
+ _this.showProfilecard();
101
+ });
102
+ _defineProperty(_assertThisInitialized(_this), "containerListeners", _this.props.trigger === 'hover' ? {
103
+ onMouseEnter: _this.onMouseEnter,
104
+ onMouseLeave: _this.hideProfilecard,
105
+ onBlur: _this.hideProfilecard,
106
+ onKeyPress: _this.onKeyPress
107
+ } : {
108
+ onClick: _this.onClick,
109
+ onKeyPress: _this.onKeyPress
110
+ });
111
+ _defineProperty(_assertThisInitialized(_this), "layerListeners", {
112
+ handleClickOutside: _this.hideProfilecard,
113
+ handleEscapeKeydown: _this.hideProfilecard
114
+ });
115
+ _defineProperty(_assertThisInitialized(_this), "state", {
116
+ visible: false,
117
+ isLoading: undefined,
118
+ hasError: false,
119
+ error: null,
120
+ data: null,
121
+ reportingLinesData: undefined,
122
+ shouldShowGiveKudos: false,
123
+ teamCentralBaseUrl: undefined,
124
+ kudosDrawerOpen: false
125
+ });
126
+ _defineProperty(_assertThisInitialized(_this), "clientFetchProfile", function () {
127
+ var _this$props = _this.props,
128
+ cloudId = _this$props.cloudId,
129
+ userId = _this$props.userId;
130
+ var isLoading = _this.state.isLoading;
131
+ if (isLoading === true) {
132
+ // don't fetch data when fetching is in process
133
+ return;
134
+ }
135
+ _this.setState({
136
+ teamCentralBaseUrl: _this.props.resourceClient.getTeamCentralBaseUrl()
137
+ });
138
+ _this.setState({
139
+ isLoading: true,
140
+ hasError: false,
141
+ data: null
142
+ }, function () {
143
+ var requests = Promise.all([_this.props.resourceClient.getProfile(cloudId || '', userId, _this.fireAnalytics), _this.props.resourceClient.getReportingLines(userId), _this.props.resourceClient.shouldShowGiveKudos()]);
144
+ requests.then(function (res) {
145
+ var _this2;
146
+ return (_this2 = _this).handleClientSuccess.apply(_this2, _toConsumableArray(res));
147
+ }, function (err) {
148
+ return _this.handleClientError(err);
149
+ }).catch(function (err) {
150
+ return _this.handleClientError(err);
151
+ });
152
+ });
153
+ });
154
+ _defineProperty(_assertThisInitialized(_this), "openKudosDrawer", function () {
155
+ _this.hideProfilecard();
156
+ _this.setState({
157
+ kudosDrawerOpen: true
158
+ });
159
+ });
160
+ _defineProperty(_assertThisInitialized(_this), "closeKudosDrawer", function () {
161
+ _this.setState({
162
+ kudosDrawerOpen: false
163
+ });
164
+ });
165
+ _defineProperty(_assertThisInitialized(_this), "renderCard", function () {
166
+ var isLoading = _this.state.isLoading;
167
+ if (isLoading === true || isLoading === undefined) {
168
+ return /*#__PURE__*/React.createElement(CardWrapper, null, /*#__PURE__*/React.createElement(UserLoadingState, {
169
+ fireAnalytics: _this.fireAnalytics
170
+ }));
171
+ } else {
172
+ return _this.renderProfileCard();
173
+ }
174
+ });
175
+ return _this;
176
+ }
177
+ _createClass(ProfilecardTrigger, [{
178
+ key: "componentDidMount",
179
+ value: function componentDidMount() {
180
+ this._isMounted = true;
139
181
  }
140
- setTriggeredUsingKeyboard(false);
141
- setVisible(false);
142
- onVisibilityChange && onVisibilityChange(false);
143
- }, [setTriggeredUsingKeyboard, setVisible, onVisibilityChange]);
144
- var handleClientSuccess = useCallback(function (profileData, reportingLinesData, shouldShowGiveKudos) {
145
- if (!isMounted) {
146
- return;
182
+ }, {
183
+ key: "componentDidUpdate",
184
+ value: function componentDidUpdate(prevProps) {
185
+ var _this$props2 = this.props,
186
+ userId = _this$props2.userId,
187
+ cloudId = _this$props2.cloudId,
188
+ resourceClient = _this$props2.resourceClient;
189
+ var visible = this.state.visible;
190
+
191
+ // just re-fetching data when the card opens
192
+ if (visible && (userId !== prevProps.userId || cloudId !== prevProps.cloudId || resourceClient !== prevProps.resourceClient)) {
193
+ this.setState({
194
+ isLoading: undefined
195
+ }, this.clientFetchProfile);
196
+ }
147
197
  }
148
- setIsLoading(false);
149
- setHasError(false);
150
- setData(profileData);
151
- setReportingLinesData(reportingLinesData);
152
- setShouldShowGiveKudos(shouldShowGiveKudos);
153
- }, [isMounted, setHasError, setIsLoading, setData, setReportingLinesData, setShouldShowGiveKudos]);
154
- var handleClientError = useCallback(function (err) {
155
- if (!isMounted) {
156
- return;
198
+ }, {
199
+ key: "componentWillUnmount",
200
+ value: function componentWillUnmount() {
201
+ this._isMounted = false;
202
+ clearTimeout(this.showTimer);
203
+ clearTimeout(this.hideTimer);
157
204
  }
158
- setIsLoading(false);
159
- setHasError(true);
160
- setError(err);
161
- }, [isMounted, setHasError, setIsLoading, setError]);
162
- var clientFetchProfile = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
163
- var requests, responses;
164
- return _regeneratorRuntime.wrap(function _callee$(_context) {
165
- while (1) switch (_context.prev = _context.next) {
166
- case 0:
167
- if (!(isLoading === true)) {
168
- _context.next = 2;
169
- break;
170
- }
171
- return _context.abrupt("return");
172
- case 2:
173
- setTeamCentralBaseUrl(resourceClient.getTeamCentralBaseUrl());
174
- setIsLoading(true);
175
- setHasError(false);
176
- setError(null);
177
- setData(null);
178
- _context.prev = 7;
179
- requests = Promise.all([resourceClient.getProfile(cloudId || '', userId, fireAnalytics), resourceClient.getReportingLines(userId), resourceClient.shouldShowGiveKudos()]);
180
- _context.next = 11;
181
- return requests;
182
- case 11:
183
- responses = _context.sent;
184
- handleClientSuccess.apply(void 0, _toConsumableArray(responses));
185
- _context.next = 18;
186
- break;
187
- case 15:
188
- _context.prev = 15;
189
- _context.t0 = _context["catch"](7);
190
- handleClientError(_context.t0);
191
- case 18:
192
- case "end":
193
- return _context.stop();
194
- }
195
- }, _callee, null, [[7, 15]]);
196
- })), [cloudId, fireAnalytics, isLoading, resourceClient, userId, handleClientSuccess, handleClientError]);
197
- var showProfilecard = useCallback(function () {
198
- clearTimeout(hideTimer.current);
199
- clearTimeout(showTimer.current);
200
- showTimer.current = window.setTimeout(function () {
201
- if (!visible) {
202
- void clientFetchProfile();
203
- setVisible(true);
204
- onVisibilityChange && onVisibilityChange(true);
205
+ }, {
206
+ key: "handleClientSuccess",
207
+ value: function handleClientSuccess(profileData, reportingLinesData, shouldShowGiveKudos) {
208
+ if (!this._isMounted) {
209
+ return;
205
210
  }
206
- }, showDelay);
207
- }, [showDelay, visible, clientFetchProfile, onVisibilityChange]);
208
- var onClick = useCallback(function (event) {
209
- // If the user clicks on the trigger then we don't want that click event to
210
- // propagate out to parent containers. For example when clicking a mention
211
- // lozenge in an inline-edit.
212
- event.stopPropagation();
213
- showProfilecard();
214
- if (!visible) {
215
- fireAnalytics(cardTriggered('user', 'click'));
211
+ this.setState({
212
+ isLoading: false,
213
+ hasError: false,
214
+ data: profileData,
215
+ reportingLinesData: reportingLinesData,
216
+ shouldShowGiveKudos: shouldShowGiveKudos
217
+ });
216
218
  }
217
- }, [fireAnalytics, showProfilecard, visible]);
218
- var onMouseEnter = useCallback(function () {
219
- showProfilecard();
220
- if (!visible) {
221
- fireAnalytics(cardTriggered('user', 'hover'));
222
- }
223
- }, [fireAnalytics, showProfilecard, visible]);
224
- var onKeyPress = useCallback(function (event) {
225
- if (event.key === 'Enter' || event.key === ' ') {
226
- event.preventDefault();
227
- setTriggeredUsingKeyboard(true);
228
- showProfilecard();
229
- if (!visible) {
230
- fireAnalytics(cardTriggered('user', 'click'));
219
+ }, {
220
+ key: "handleClientError",
221
+ value: function handleClientError(err) {
222
+ if (!this._isMounted) {
223
+ return;
231
224
  }
225
+ this.setState({
226
+ isLoading: false,
227
+ hasError: true,
228
+ error: err
229
+ });
232
230
  }
233
- }, [fireAnalytics, showProfilecard, visible]);
234
- var onFocus = useCallback(function () {
235
- showProfilecard();
236
- }, [showProfilecard]);
237
- var containerListeners = useMemo(function () {
238
- return trigger === 'hover' ? {
239
- onMouseEnter: onMouseEnter,
240
- onMouseLeave: hideProfilecard,
241
- onBlur: hideProfilecard,
242
- onKeyPress: onKeyPress
243
- } : {
244
- onClick: onClick,
245
- onKeyPress: onKeyPress
246
- };
247
- }, [hideProfilecard, onClick, onKeyPress, onMouseEnter, trigger]);
248
- var filterActions = useCallback(function () {
249
- return filterActionsInner(actions, data);
250
- }, [actions, data]);
251
- var openKudosDrawer = function openKudosDrawer() {
252
- hideProfilecard();
253
- setKudosDrawerOpen(true);
254
- };
255
- var closeKudosDrawer = function closeKudosDrawer() {
256
- setKudosDrawerOpen(false);
257
- };
258
- var showLoading = isLoading === true || isLoading === undefined;
259
- var wrapperProps = useMemo(function () {
260
- return trigger === 'hover' ? {
261
- onMouseEnter: onMouseEnter,
262
- onMouseLeave: hideProfilecard,
263
- onFocus: onFocus
264
- } : {};
265
- }, [hideProfilecard, onFocus, onMouseEnter, trigger]);
266
- var profilecardProps = _objectSpread(_objectSpread({
267
- userId: userId,
268
- fullName: prepopulatedData === null || prepopulatedData === void 0 ? void 0 : prepopulatedData.fullName,
269
- isCurrentUser: data === null || data === void 0 ? void 0 : data.isCurrentUser,
270
- clientFetchProfile: clientFetchProfile
271
- }, data), {}, {
272
- reportingLines: reportingLinesData,
273
- onReportingLinesClick: onReportingLinesClick,
274
- isKudosEnabled: shouldShowGiveKudos,
275
- teamCentralBaseUrl: teamCentralBaseUrl,
276
- cloudId: cloudId,
277
- openKudosDrawer: openKudosDrawer,
278
- isTriggeredUsingKeyboard: isTriggeredUsingKeyboard,
279
- disabledAriaAttributes: disabledAriaAttributes
280
- });
281
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popup, {
282
- isOpen: !!visible,
283
- onClose: function onClose(event) {
284
- hideProfilecard();
285
- handleKeyboardClose(event);
286
- },
287
- placement: position,
288
- content: function content() {
289
- return /*#__PURE__*/React.createElement("div", wrapperProps, showLoading ? /*#__PURE__*/React.createElement(LoadingView, {
290
- fireAnalytics: fireAnalytics
291
- }) : visible && /*#__PURE__*/React.createElement(Suspense, {
231
+ }, {
232
+ key: "filterActions",
233
+ value: function filterActions() {
234
+ return _filterActions(this.props.actions, this.state.data);
235
+ }
236
+ }, {
237
+ key: "renderProfileCard",
238
+ value: function renderProfileCard() {
239
+ var _this$state$data;
240
+ var newProps = _objectSpread(_objectSpread({
241
+ userId: this.props.userId,
242
+ isCurrentUser: (_this$state$data = this.state.data) === null || _this$state$data === void 0 ? void 0 : _this$state$data.isCurrentUser,
243
+ clientFetchProfile: this.clientFetchProfile
244
+ }, this.state.data), {}, {
245
+ reportingLines: this.state.reportingLinesData,
246
+ onReportingLinesClick: this.props.onReportingLinesClick,
247
+ isKudosEnabled: this.state.shouldShowGiveKudos,
248
+ teamCentralBaseUrl: this.state.teamCentralBaseUrl,
249
+ cloudId: this.props.cloudId,
250
+ openKudosDrawer: this.openKudosDrawer
251
+ });
252
+ var wrapperProps = this.props.trigger === 'hover' ? {
253
+ onMouseEnter: this.onMouseEnter,
254
+ onMouseLeave: this.hideProfilecard,
255
+ onFocus: this.onFocus
256
+ } : {};
257
+ return /*#__PURE__*/React.createElement("div", wrapperProps, this.state.visible && /*#__PURE__*/React.createElement(Suspense, {
292
258
  fallback: null
293
- }, /*#__PURE__*/React.createElement(ProfileCardLazy, _extends({}, profilecardProps, {
294
- actions: filterActions(),
295
- hasError: hasError,
296
- errorType: error,
259
+ }, /*#__PURE__*/React.createElement(ProfileCardLazy, _extends({}, newProps, {
260
+ actions: this.filterActions(),
261
+ hasError: this.state.hasError,
262
+ errorType: this.state.error,
297
263
  withoutElevation: true
298
264
  }))));
299
- },
300
- trigger: function trigger(triggerProps) {
301
- var callbackRef = triggerProps.ref,
302
- innerProps = _objectWithoutProperties(triggerProps, _excluded);
303
- var ref = function ref(element) {
304
- triggerRef.current = element;
305
- if (typeof callbackRef === 'function') {
306
- callbackRef(element);
307
- }
308
- };
309
- var _ = innerProps['aria-expanded'],
310
- __ = innerProps['aria-haspopup'],
311
- restInnerProps = _objectWithoutProperties(innerProps, _excluded2);
312
- return /*#__PURE__*/React.createElement("span", _extends({}, disabledAriaAttributes ? restInnerProps : triggerProps, containerListeners, {
313
- ref: ref,
314
- "data-testid": testId,
315
- "aria-labelledby": ariaLabelledBy
316
- }, disabledAriaAttributes ? {} : {
317
- role: 'button',
318
- tabIndex: 0,
319
- 'aria-label': getLabelMessage(ariaLabel, profilecardProps.fullName, formatMessage)
320
- }), children);
321
- },
322
- zIndex: layers.modal(),
323
- shouldUseCaptureOnOutsideClick: true,
324
- autoFocus: trigger === 'click'
325
- }), shouldShowGiveKudos && /*#__PURE__*/React.createElement(Suspense, {
326
- fallback: null
327
- }, /*#__PURE__*/React.createElement(GiveKudosLauncherLazy, {
328
- isOpen: kudosDrawerOpen,
329
- recipient: {
330
- type: KudosType.INDIVIDUAL,
331
- recipientId: userId
332
- },
333
- analyticsSource: "profile-card",
334
- teamCentralBaseUrl: teamCentralBaseUrl,
335
- cloudId: cloudId,
336
- addFlag: addFlag,
337
- onClose: closeKudosDrawer
338
- })));
339
- }
340
- var LoadingView = function LoadingView(_ref3) {
341
- var fireAnalytics = _ref3.fireAnalytics;
342
- return /*#__PURE__*/React.createElement(CardWrapper, {
343
- "data-testId": "profilecard.profilecardtrigger.loading"
344
- }, /*#__PURE__*/React.createElement(UserLoadingState, {
345
- fireAnalytics: fireAnalytics
346
- }));
347
- };
265
+ }
266
+ }, {
267
+ key: "renderWithTrigger",
268
+ value: function renderWithTrigger() {
269
+ var _this3 = this;
270
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popup, {
271
+ isOpen: !!this.state.visible,
272
+ onClose: this.hideProfilecard,
273
+ placement: this.props.position,
274
+ content: this.renderCard,
275
+ trigger: function trigger(triggerProps) {
276
+ var ref = triggerProps.ref,
277
+ innerProps = _objectWithoutProperties(triggerProps, _excluded);
278
+ return /*#__PURE__*/React.createElement("span", _extends({}, innerProps, _this3.containerListeners, {
279
+ ref: ref,
280
+ "data-testid": _this3.props.testId,
281
+ role: "button",
282
+ tabIndex: 0
283
+ }), _this3.props.children);
284
+ },
285
+ zIndex: layers.modal(),
286
+ shouldUseCaptureOnOutsideClick: true,
287
+ autoFocus: this.props.trigger === 'click'
288
+ }), this.state.shouldShowGiveKudos && /*#__PURE__*/React.createElement(Suspense, {
289
+ fallback: null
290
+ }, /*#__PURE__*/React.createElement(GiveKudosLauncherLazy, {
291
+ isOpen: this.state.kudosDrawerOpen,
292
+ recipient: {
293
+ type: KudosType.INDIVIDUAL,
294
+ recipientId: this.props.userId
295
+ },
296
+ analyticsSource: "profile-card",
297
+ teamCentralBaseUrl: this.state.teamCentralBaseUrl,
298
+ cloudId: this.props.cloudId,
299
+ addFlag: this.props.addFlag,
300
+ onClose: this.closeKudosDrawer
301
+ })));
302
+ }
303
+ }, {
304
+ key: "render",
305
+ value: function render() {
306
+ if (this.props.children) {
307
+ return this.renderWithTrigger();
308
+ } else {
309
+ throw new Error('Component "ProfileCardTrigger" must have "children" property');
310
+ }
311
+ }
312
+ }]);
313
+ return ProfilecardTrigger;
314
+ }(React.PureComponent);
315
+ _defineProperty(ProfilecardTrigger, "defaultProps", {
316
+ actions: [],
317
+ trigger: 'hover',
318
+ position: 'bottom-start'
319
+ });
320
+ var ProfilecardTriggerLegacy = withAnalyticsEvents()(ProfilecardTrigger);
321
+ export default function ProfilecardTriggerSwitch(props) {
322
+ return getBooleanFF('platform.profile-card-trigger-next') ? /*#__PURE__*/React.createElement(ProfilecardTriggerNext, _extends({}, props, {
323
+ onVisibilityChange: function onVisibilityChange(isVisible) {
324
+ if (props.onVisibilityChange) {
325
+ props.onVisibilityChange(isVisible);
326
+ }
327
+ }
328
+ })) : /*#__PURE__*/React.createElement(ProfilecardTriggerLegacy, props);
329
+ }