@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,284 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { useIntl } from 'react-intl-next';
4
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
5
+ import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
6
+ import Popup from '@atlaskit/popup';
7
+ import { layers } from '@atlaskit/theme/constants';
8
+ import filterActionsInner from '../../internal/filterActions';
9
+ import getLabelMessage from '../../internal/getLabelMessage';
10
+ import { CardWrapper } from '../../styled/Card';
11
+ import { cardTriggered, fireEvent } from '../../util/analytics';
12
+ import { DELAY_MS_HIDE, DELAY_MS_SHOW } from '../../util/config';
13
+ import { ProfileCardLazy } from './lazyProfileCard';
14
+ import UserLoadingState from './UserLoadingState';
15
+ export default function ProfilecardTriggerNext({
16
+ trigger = 'hover',
17
+ userId,
18
+ cloudId,
19
+ resourceClient,
20
+ actions = [],
21
+ position = 'bottom-start',
22
+ children,
23
+ testId,
24
+ addFlag,
25
+ onReportingLinesClick,
26
+ ariaLabel,
27
+ ariaLabelledBy,
28
+ prepopulatedData,
29
+ disabledAriaAttributes,
30
+ onVisibilityChange
31
+ }) {
32
+ const {
33
+ createAnalyticsEvent
34
+ } = useAnalyticsEvents();
35
+ const {
36
+ formatMessage
37
+ } = useIntl();
38
+ const [isMounted, setIsMounted] = useState(false);
39
+ const showDelay = trigger === 'click' ? 0 : DELAY_MS_SHOW;
40
+ const hideDelay = trigger === 'click' ? 0 : DELAY_MS_HIDE;
41
+ const showTimer = useRef(0);
42
+ const hideTimer = useRef(0);
43
+ const [visible, setVisible] = useState(false);
44
+ const [isLoading, setIsLoading] = useState(undefined);
45
+ const [hasError, setHasError] = useState(false);
46
+ const [error, setError] = useState(null);
47
+ const [data, setData] = useState(null);
48
+ const [reportingLinesData, setReportingLinesData] = useState(undefined);
49
+ const [shouldShowGiveKudos, setShouldShowGiveKudos] = useState(false);
50
+ const [teamCentralBaseUrl, setTeamCentralBaseUrl] = useState(undefined);
51
+ const [kudosDrawerOpen, setKudosDrawerOpen] = useState(false);
52
+ const [isTriggeredUsingKeyboard, setTriggeredUsingKeyboard] = useState(false);
53
+ const triggerRef = useRef(null);
54
+ useEffect(() => {
55
+ setIsMounted(true);
56
+ return () => {
57
+ setIsMounted(false);
58
+ clearTimeout(showTimer.current);
59
+ clearTimeout(hideTimer.current);
60
+ };
61
+ // eslint-disable-next-line react-hooks/exhaustive-deps
62
+ }, []);
63
+ useEffect(() => {
64
+ // Reset state when the userId changes
65
+ setIsLoading(undefined);
66
+ setHasError(false);
67
+ setError(null);
68
+ setData(null);
69
+ setReportingLinesData(undefined);
70
+ setShouldShowGiveKudos(false);
71
+ setTeamCentralBaseUrl(undefined);
72
+ }, [userId]);
73
+ const fireAnalytics = useCallback(payload => {
74
+ // Don't fire any analytics if the component is unmounted
75
+ if (!isMounted) {
76
+ return;
77
+ }
78
+ fireEvent(createAnalyticsEvent, payload);
79
+ }, [createAnalyticsEvent, isMounted]);
80
+ const hideProfilecard = useCallback(() => {
81
+ clearTimeout(showTimer.current);
82
+ clearTimeout(hideTimer.current);
83
+ if (!isTriggeredUsingKeyboard) {
84
+ hideTimer.current = window.setTimeout(() => {
85
+ setVisible(false);
86
+ onVisibilityChange && onVisibilityChange(false);
87
+ }, hideDelay);
88
+ }
89
+ }, [hideDelay, isTriggeredUsingKeyboard, onVisibilityChange]);
90
+ const handleKeyboardClose = useCallback(event => {
91
+ if (event.key && event.key !== 'Escape') {
92
+ return;
93
+ }
94
+ if (triggerRef.current) {
95
+ triggerRef.current.focus();
96
+ }
97
+ setTriggeredUsingKeyboard(false);
98
+ setVisible(false);
99
+ onVisibilityChange && onVisibilityChange(false);
100
+ }, [setTriggeredUsingKeyboard, setVisible, onVisibilityChange]);
101
+ const handleClientSuccess = useCallback((profileData, reportingLinesData, shouldShowGiveKudos) => {
102
+ if (!isMounted) {
103
+ return;
104
+ }
105
+ setIsLoading(false);
106
+ setHasError(false);
107
+ setData(profileData);
108
+ setReportingLinesData(reportingLinesData);
109
+ setShouldShowGiveKudos(shouldShowGiveKudos);
110
+ }, [isMounted, setHasError, setIsLoading, setData, setReportingLinesData, setShouldShowGiveKudos]);
111
+ const handleClientError = useCallback(err => {
112
+ if (!isMounted) {
113
+ return;
114
+ }
115
+ setIsLoading(false);
116
+ setHasError(true);
117
+ setError(err);
118
+ }, [isMounted, setHasError, setIsLoading, setError]);
119
+ const clientFetchProfile = useCallback(async () => {
120
+ if (isLoading === true) {
121
+ // don't fetch data when fetching is in process
122
+ return;
123
+ }
124
+ setTeamCentralBaseUrl(resourceClient.getTeamCentralBaseUrl());
125
+ setIsLoading(true);
126
+ setHasError(false);
127
+ setError(null);
128
+ setData(null);
129
+ try {
130
+ const requests = Promise.all([resourceClient.getProfile(cloudId || '', userId, fireAnalytics), resourceClient.getReportingLines(userId), resourceClient.shouldShowGiveKudos()]);
131
+ const responses = await requests;
132
+ handleClientSuccess(...responses);
133
+ } catch (err) {
134
+ handleClientError(err);
135
+ }
136
+ }, [cloudId, fireAnalytics, isLoading, resourceClient, userId, handleClientSuccess, handleClientError]);
137
+ const showProfilecard = useCallback(() => {
138
+ clearTimeout(hideTimer.current);
139
+ clearTimeout(showTimer.current);
140
+ showTimer.current = window.setTimeout(() => {
141
+ if (!visible) {
142
+ void clientFetchProfile();
143
+ setVisible(true);
144
+ onVisibilityChange && onVisibilityChange(true);
145
+ }
146
+ }, showDelay);
147
+ }, [showDelay, visible, clientFetchProfile, onVisibilityChange]);
148
+ const onClick = useCallback(event => {
149
+ // If the user clicks on the trigger then we don't want that click event to
150
+ // propagate out to parent containers. For example when clicking a mention
151
+ // lozenge in an inline-edit.
152
+ event.stopPropagation();
153
+ showProfilecard();
154
+ if (!visible) {
155
+ fireAnalytics(cardTriggered('user', 'click'));
156
+ }
157
+ }, [fireAnalytics, showProfilecard, visible]);
158
+ const onMouseEnter = useCallback(() => {
159
+ showProfilecard();
160
+ if (!visible) {
161
+ fireAnalytics(cardTriggered('user', 'hover'));
162
+ }
163
+ }, [fireAnalytics, showProfilecard, visible]);
164
+ const onKeyPress = useCallback(event => {
165
+ if (event.key === 'Enter' || event.key === ' ') {
166
+ event.preventDefault();
167
+ setTriggeredUsingKeyboard(true);
168
+ showProfilecard();
169
+ if (!visible) {
170
+ fireAnalytics(cardTriggered('user', 'click'));
171
+ }
172
+ }
173
+ }, [fireAnalytics, showProfilecard, visible]);
174
+ const onFocus = useCallback(() => {
175
+ showProfilecard();
176
+ }, [showProfilecard]);
177
+ const containerListeners = useMemo(() => trigger === 'hover' ? {
178
+ onMouseEnter: onMouseEnter,
179
+ onMouseLeave: hideProfilecard,
180
+ onBlur: hideProfilecard,
181
+ onKeyPress: onKeyPress
182
+ } : {
183
+ onClick: onClick,
184
+ onKeyPress: onKeyPress
185
+ }, [hideProfilecard, onClick, onKeyPress, onMouseEnter, trigger]);
186
+ const filterActions = useCallback(() => {
187
+ return filterActionsInner(actions, data);
188
+ }, [actions, data]);
189
+ const openKudosDrawer = () => {
190
+ hideProfilecard();
191
+ setKudosDrawerOpen(true);
192
+ };
193
+ const closeKudosDrawer = () => {
194
+ setKudosDrawerOpen(false);
195
+ };
196
+ const showLoading = isLoading === true || isLoading === undefined;
197
+ const wrapperProps = useMemo(() => trigger === 'hover' ? {
198
+ onMouseEnter: onMouseEnter,
199
+ onMouseLeave: hideProfilecard,
200
+ onFocus: onFocus
201
+ } : {}, [hideProfilecard, onFocus, onMouseEnter, trigger]);
202
+ const profilecardProps = {
203
+ userId: userId,
204
+ fullName: prepopulatedData === null || prepopulatedData === void 0 ? void 0 : prepopulatedData.fullName,
205
+ isCurrentUser: data === null || data === void 0 ? void 0 : data.isCurrentUser,
206
+ clientFetchProfile: clientFetchProfile,
207
+ ...data,
208
+ reportingLines: reportingLinesData,
209
+ onReportingLinesClick: onReportingLinesClick,
210
+ isKudosEnabled: shouldShowGiveKudos,
211
+ teamCentralBaseUrl: teamCentralBaseUrl,
212
+ cloudId: cloudId,
213
+ openKudosDrawer: openKudosDrawer,
214
+ isTriggeredUsingKeyboard: isTriggeredUsingKeyboard,
215
+ disabledAriaAttributes: disabledAriaAttributes
216
+ };
217
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popup, {
218
+ isOpen: !!visible,
219
+ onClose: event => {
220
+ hideProfilecard();
221
+ handleKeyboardClose(event);
222
+ },
223
+ placement: position,
224
+ content: () => /*#__PURE__*/React.createElement("div", wrapperProps, showLoading ? /*#__PURE__*/React.createElement(LoadingView, {
225
+ fireAnalytics: fireAnalytics
226
+ }) : visible && /*#__PURE__*/React.createElement(Suspense, {
227
+ fallback: null
228
+ }, /*#__PURE__*/React.createElement(ProfileCardLazy, _extends({}, profilecardProps, {
229
+ actions: filterActions(),
230
+ hasError: hasError,
231
+ errorType: error,
232
+ withoutElevation: true
233
+ })))),
234
+ trigger: triggerProps => {
235
+ const {
236
+ ref: callbackRef,
237
+ ...innerProps
238
+ } = triggerProps;
239
+ const ref = element => {
240
+ triggerRef.current = element;
241
+ if (typeof callbackRef === 'function') {
242
+ callbackRef(element);
243
+ }
244
+ };
245
+ const {
246
+ 'aria-expanded': _,
247
+ 'aria-haspopup': __,
248
+ ...restInnerProps
249
+ } = innerProps;
250
+ return /*#__PURE__*/React.createElement("span", _extends({}, disabledAriaAttributes ? restInnerProps : triggerProps, containerListeners, {
251
+ ref: ref,
252
+ "data-testid": testId,
253
+ "aria-labelledby": ariaLabelledBy
254
+ }, disabledAriaAttributes ? {} : {
255
+ role: 'button',
256
+ tabIndex: 0,
257
+ 'aria-label': getLabelMessage(ariaLabel, profilecardProps.fullName, formatMessage)
258
+ }), children);
259
+ },
260
+ zIndex: layers.modal(),
261
+ shouldUseCaptureOnOutsideClick: true,
262
+ autoFocus: trigger === 'click'
263
+ }), shouldShowGiveKudos && /*#__PURE__*/React.createElement(Suspense, {
264
+ fallback: null
265
+ }, /*#__PURE__*/React.createElement(GiveKudosLauncherLazy, {
266
+ isOpen: kudosDrawerOpen,
267
+ recipient: {
268
+ type: KudosType.INDIVIDUAL,
269
+ recipientId: userId
270
+ },
271
+ analyticsSource: "profile-card",
272
+ teamCentralBaseUrl: teamCentralBaseUrl,
273
+ cloudId: cloudId,
274
+ addFlag: addFlag,
275
+ onClose: closeKudosDrawer
276
+ })));
277
+ }
278
+ const LoadingView = ({
279
+ fireAnalytics
280
+ }) => /*#__PURE__*/React.createElement(CardWrapper, {
281
+ "data-testId": "profilecard.profilecardtrigger.loading"
282
+ }, /*#__PURE__*/React.createElement(UserLoadingState, {
283
+ fireAnalytics: fireAnalytics
284
+ }));
@@ -31,7 +31,7 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
31
31
  actionSubjectId,
32
32
  attributes: {
33
33
  packageName: "@atlaskit/profilecard",
34
- packageVersion: "19.11.8",
34
+ packageVersion: "19.13.0",
35
35
  ...attributes,
36
36
  firedAt: Math.round(getPageTime())
37
37
  }
@@ -48,7 +48,7 @@ export var addHeaders = function addHeaders(headers) {
48
48
  headers.append('X-ExperimentalApi', 'teams-beta');
49
49
  headers.append('X-ExperimentalApi', 'team-members-beta');
50
50
  headers.append('atl-client-name', "@atlaskit/profilecard");
51
- headers.append('atl-client-version', "19.11.8");
51
+ headers.append('atl-client-version', "19.13.0");
52
52
  return headers;
53
53
  };
54
54
  export function getTeamFromAGG(_x, _x2, _x3) {