@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.
@@ -0,0 +1,347 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _extends from "@babel/runtime/helpers/extends";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ 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"];
9
+ 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
+ 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';
15
+ import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
16
+ import Popup from '@atlaskit/popup';
17
+ import { layers } from '@atlaskit/theme/constants';
18
+ import filterActionsInner from '../../internal/filterActions';
19
+ import getLabelMessage from '../../internal/getLabelMessage';
20
+ import { CardWrapper } from '../../styled/Card';
21
+ import { cardTriggered, fireEvent } from '../../util/analytics';
22
+ import { DELAY_MS_HIDE, DELAY_MS_SHOW } from '../../util/config';
23
+ import { ProfileCardLazy } from './lazyProfileCard';
24
+ import UserLoadingState from './UserLoadingState';
25
+ export default function ProfilecardTriggerNext(_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;
136
+ }
137
+ if (triggerRef.current) {
138
+ triggerRef.current.focus();
139
+ }
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;
147
+ }
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;
157
+ }
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
+ }, 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'));
216
+ }
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'));
231
+ }
232
+ }
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, {
292
+ fallback: null
293
+ }, /*#__PURE__*/React.createElement(ProfileCardLazy, _extends({}, profilecardProps, {
294
+ actions: filterActions(),
295
+ hasError: hasError,
296
+ errorType: error,
297
+ withoutElevation: true
298
+ }))));
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
+ };
@@ -38,7 +38,7 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
38
38
  actionSubjectId: actionSubjectId,
39
39
  attributes: _objectSpread(_objectSpread({
40
40
  packageName: "@atlaskit/profilecard",
41
- packageVersion: "19.11.8"
41
+ packageVersion: "19.13.0"
42
42
  }, attributes), {}, {
43
43
  firedAt: Math.round(getPageTime())
44
44
  })
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { ProfileCardTriggerProps } from '../../types';
3
- export default function ProfilecardTrigger({ trigger, userId, cloudId, resourceClient, actions, position, children, testId, addFlag, onReportingLinesClick, ariaLabel, ariaLabelledBy, prepopulatedData, disabledAriaAttributes, onVisibilityChange, }: ProfileCardTriggerProps): JSX.Element;
3
+ export default function ProfilecardTriggerSwitch(props: ProfileCardTriggerProps): JSX.Element;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { ProfileCardTriggerProps } from '../../types';
3
+ export default function ProfilecardTriggerNext({ trigger, userId, cloudId, resourceClient, actions, position, children, testId, addFlag, onReportingLinesClick, ariaLabel, ariaLabelledBy, prepopulatedData, disabledAriaAttributes, onVisibilityChange, }: ProfileCardTriggerProps): JSX.Element;
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { ProfileCardTriggerProps } from '../../types';
3
- export default function ProfilecardTrigger({ trigger, userId, cloudId, resourceClient, actions, position, children, testId, addFlag, onReportingLinesClick, ariaLabel, ariaLabelledBy, prepopulatedData, disabledAriaAttributes, onVisibilityChange, }: ProfileCardTriggerProps): JSX.Element;
3
+ export default function ProfilecardTriggerSwitch(props: ProfileCardTriggerProps): JSX.Element;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import { ProfileCardTriggerProps } from '../../types';
3
+ export default function ProfilecardTriggerNext({ trigger, userId, cloudId, resourceClient, actions, position, children, testId, addFlag, onReportingLinesClick, ariaLabel, ariaLabelledBy, prepopulatedData, disabledAriaAttributes, onVisibilityChange, }: ProfileCardTriggerProps): JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/profilecard",
3
- "version": "19.11.8",
3
+ "version": "19.13.0",
4
4
  "description": "A React component to display a card with user information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -53,8 +53,8 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@atlaskit/analytics-next": "^9.3.0",
56
- "@atlaskit/avatar": "^21.6.0",
57
- "@atlaskit/avatar-group": "^9.5.0",
56
+ "@atlaskit/avatar": "^21.8.0",
57
+ "@atlaskit/avatar-group": "^9.6.0",
58
58
  "@atlaskit/button": "^17.14.0",
59
59
  "@atlaskit/dropdown-menu": "^12.10.0",
60
60
  "@atlaskit/empty-state": "^7.8.0",
@@ -63,10 +63,11 @@
63
63
  "@atlaskit/icon": "^22.1.0",
64
64
  "@atlaskit/lozenge": "^11.7.0",
65
65
  "@atlaskit/menu": "^2.2.0",
66
- "@atlaskit/popup": "^1.15.0",
66
+ "@atlaskit/platform-feature-flags": "^0.2.4",
67
+ "@atlaskit/popup": "^1.17.0",
67
68
  "@atlaskit/spinner": "^16.1.0",
68
- "@atlaskit/theme": "^12.7.0",
69
- "@atlaskit/tokens": "^1.45.0",
69
+ "@atlaskit/theme": "^12.8.0",
70
+ "@atlaskit/tokens": "^1.48.0",
70
71
  "@atlaskit/tooltip": "^18.3.0",
71
72
  "@babel/runtime": "^7.0.0",
72
73
  "@emotion/react": "^11.7.1",
@@ -108,5 +109,10 @@
108
109
  ]
109
110
  }
110
111
  },
112
+ "platform-feature-flags": {
113
+ "platform.profile-card-trigger-next": {
114
+ "type": "boolean"
115
+ }
116
+ },
111
117
  "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
112
118
  }