@atlaskit/profilecard 19.19.0 → 19.20.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 (58) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-jira/tsconfig.json +6 -0
  4. package/afm-post-office/tsconfig.json +3 -0
  5. package/dist/cjs/client/RovoAgentCardClient.js +2 -5
  6. package/dist/cjs/client/UserProfileCardClient.js +110 -16
  7. package/dist/cjs/client/getTeamFromAGG.js +1 -1
  8. package/dist/cjs/components/Agent/Actions.js +20 -4
  9. package/dist/cjs/components/Agent/AgentDeleteConfirmationModal.js +104 -0
  10. package/dist/cjs/components/Agent/AgentProfileCard.js +40 -8
  11. package/dist/cjs/components/Agent/AgentProfileCardTrigger.js +2 -1
  12. package/dist/cjs/components/Agent/hooks/useAgentActions.js +92 -0
  13. package/dist/cjs/components/Agent/hooks/useDeleteAgent.js +70 -0
  14. package/dist/cjs/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +1 -1
  15. package/dist/cjs/components/User/ProfileCardTrigger.js +4 -2
  16. package/dist/cjs/util/analytics.js +16 -16
  17. package/dist/es2019/client/RovoAgentCardClient.js +2 -5
  18. package/dist/es2019/client/UserProfileCardClient.js +94 -6
  19. package/dist/es2019/client/getTeamFromAGG.js +1 -1
  20. package/dist/es2019/components/Agent/Actions.js +16 -4
  21. package/dist/es2019/components/Agent/AgentDeleteConfirmationModal.js +82 -0
  22. package/dist/es2019/components/Agent/AgentProfileCard.js +24 -9
  23. package/dist/es2019/components/Agent/AgentProfileCardTrigger.js +2 -1
  24. package/dist/es2019/components/Agent/hooks/useAgentActions.js +83 -0
  25. package/dist/es2019/components/Agent/hooks/useDeleteAgent.js +33 -0
  26. package/dist/es2019/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +1 -1
  27. package/dist/es2019/components/User/ProfileCardTrigger.js +4 -2
  28. package/dist/es2019/util/analytics.js +16 -16
  29. package/dist/esm/client/RovoAgentCardClient.js +2 -5
  30. package/dist/esm/client/UserProfileCardClient.js +111 -17
  31. package/dist/esm/client/getTeamFromAGG.js +1 -1
  32. package/dist/esm/components/Agent/Actions.js +20 -4
  33. package/dist/esm/components/Agent/AgentDeleteConfirmationModal.js +94 -0
  34. package/dist/esm/components/Agent/AgentProfileCard.js +40 -8
  35. package/dist/esm/components/Agent/AgentProfileCardTrigger.js +2 -1
  36. package/dist/esm/components/Agent/hooks/useAgentActions.js +85 -0
  37. package/dist/esm/components/Agent/hooks/useDeleteAgent.js +63 -0
  38. package/dist/esm/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +1 -1
  39. package/dist/esm/components/User/ProfileCardTrigger.js +4 -2
  40. package/dist/esm/util/analytics.js +16 -16
  41. package/dist/types/client/UserProfileCardClient.d.ts +7 -1
  42. package/dist/types/components/Agent/AgentDeleteConfirmationModal.d.ts +10 -0
  43. package/dist/types/components/Agent/{useAgentActions.d.ts → hooks/useAgentActions.d.ts} +6 -0
  44. package/dist/types/components/Agent/hooks/useDeleteAgent.d.ts +8 -0
  45. package/dist/types/components/User/ProfileCardTrigger.d.ts +1 -1
  46. package/dist/types/types.d.ts +35 -2
  47. package/dist/types-ts4.5/client/UserProfileCardClient.d.ts +7 -1
  48. package/dist/types-ts4.5/components/Agent/AgentDeleteConfirmationModal.d.ts +10 -0
  49. package/dist/types-ts4.5/components/Agent/{useAgentActions.d.ts → hooks/useAgentActions.d.ts} +6 -0
  50. package/dist/types-ts4.5/components/Agent/hooks/useDeleteAgent.d.ts +8 -0
  51. package/dist/types-ts4.5/components/User/ProfileCardTrigger.d.ts +1 -1
  52. package/dist/types-ts4.5/types.d.ts +35 -2
  53. package/package.json +6 -1
  54. package/dist/cjs/components/Agent/useAgentActions.js +0 -39
  55. package/dist/es2019/components/Agent/useAgentActions.js +0 -34
  56. package/dist/esm/components/Agent/useAgentActions.js +0 -33
  57. /package/dist/types/components/Agent/{useSetFavouriteAgent.d.ts → hooks/useSetFavouriteAgent.d.ts} +0 -0
  58. /package/dist/types-ts4.5/components/Agent/{useSetFavouriteAgent.d.ts → hooks/useSetFavouriteAgent.d.ts} +0 -0
@@ -3,6 +3,7 @@ import React, { Suspense, useCallback, useEffect, useMemo, useRef, useState } fr
3
3
  import { useIntl } from 'react-intl-next';
4
4
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
5
5
  import { GiveKudosLauncherLazy, KudosType } from '@atlaskit/give-kudos';
6
+ import { fg } from '@atlaskit/platform-feature-flags';
6
7
  import Popup from '@atlaskit/popup';
7
8
  import { layers } from '@atlaskit/theme/constants';
8
9
  import filterActionsInner from '../../internal/filterActions';
@@ -29,7 +30,8 @@ export default function ProfilecardTriggerNext({
29
30
  prepopulatedData,
30
31
  disabledAriaAttributes,
31
32
  onVisibilityChange,
32
- offset
33
+ offset,
34
+ viewingUserId
33
35
  }) {
34
36
  const {
35
37
  createAnalyticsEvent
@@ -203,7 +205,7 @@ export default function ProfilecardTriggerNext({
203
205
  const profilecardProps = {
204
206
  userId: userId,
205
207
  fullName: prepopulatedData === null || prepopulatedData === void 0 ? void 0 : prepopulatedData.fullName,
206
- isCurrentUser: data === null || data === void 0 ? void 0 : data.isCurrentUser,
208
+ isCurrentUser: fg('migrate_cloud_user_to_agg_user_query') ? userId === viewingUserId : data === null || data === void 0 ? void 0 : data.isCurrentUser,
207
209
  clientFetchProfile: clientFetchProfile,
208
210
  ...data,
209
211
  reportingLines: reportingLinesData,
@@ -32,34 +32,34 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
32
32
  actionSubjectId,
33
33
  attributes: {
34
34
  packageName: "@atlaskit/profilecard",
35
- packageVersion: "19.19.0",
35
+ packageVersion: "19.20.0",
36
36
  ...attributes,
37
37
  firedAt: Math.round(getPageTime())
38
38
  }
39
39
  });
40
+ const getActionSubject = type => {
41
+ switch (type) {
42
+ case 'user':
43
+ return USER_SUBJECT;
44
+ case 'team':
45
+ return TEAM_SUBJECT;
46
+ case 'agent':
47
+ return AGENT_SUBJECT;
48
+ default:
49
+ return 'user';
50
+ }
51
+ };
40
52
  export const cardTriggered = (type, method) => {
41
- const getActionSubject = type => {
42
- switch (type) {
43
- case 'user':
44
- return USER_SUBJECT;
45
- case 'team':
46
- return TEAM_SUBJECT;
47
- case 'agent':
48
- return AGENT_SUBJECT;
49
- default:
50
- return 'user';
51
- }
52
- };
53
53
  return createEvent('ui', 'triggered', getActionSubject(type), undefined, {
54
54
  method
55
55
  });
56
56
  };
57
57
  export const teamRequestAnalytics = (action, attributes) => createEvent('operational', action, TEAM_SUBJECT, 'request', attributes);
58
58
  export const userRequestAnalytics = (action, attributes) => createEvent('operational', action, USER_SUBJECT, 'request', attributes);
59
- export const profileCardRendered = (type, actionSubjectId, attributes) => createEvent('ui', 'rendered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, actionSubjectId, attributes);
60
- export const actionClicked = (type, attributes) => createEvent('ui', 'clicked', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, 'action', attributes);
59
+ export const profileCardRendered = (type, actionSubjectId, attributes) => createEvent('ui', 'rendered', getActionSubject(type), actionSubjectId, attributes);
60
+ export const actionClicked = (type, attributes) => createEvent('ui', 'clicked', getActionSubject(type), 'action', attributes);
61
61
  export const reportingLinesClicked = attributes => createEvent('ui', 'clicked', USER_SUBJECT, 'reportingLines', attributes);
62
- export const moreActionsClicked = (type, attributes) => createEvent('ui', 'clicked', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, 'moreActions', attributes);
62
+ export const moreActionsClicked = (type, attributes) => createEvent('ui', 'clicked', getActionSubject(type), 'moreActions', attributes);
63
63
  export const teamAvatarClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'avatar', attributes);
64
64
  export const moreMembersClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'moreMembers', attributes);
65
65
  export const errorRetryClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'errorRetry', attributes);
@@ -26,13 +26,10 @@ var RovoAgentCardClient = /*#__PURE__*/function (_CachingClient) {
26
26
  _createClass(RovoAgentCardClient, [{
27
27
  key: "makeRequest",
28
28
  value: function makeRequest(id, cloudId) {
29
- if (!this.options.productIdentifier) {
30
- throw new Error('Trying to fetch agents data with no specified config.productIdentifier');
31
- }
32
29
  if (id.type === 'identity') {
33
- return getAgentDetailsByUserId(id.value, this.options.productIdentifier, cloudId);
30
+ return getAgentDetailsByUserId(id.value, this.options.productIdentifier || 'rovo', cloudId);
34
31
  }
35
- return getAgentDetailsByAgentId(id.value, this.options.productIdentifier, cloudId);
32
+ return getAgentDetailsByAgentId(id.value, this.options.productIdentifier || 'rovo', cloudId);
36
33
  }
37
34
  }, {
38
35
  key: "getProfile",
@@ -1,20 +1,22 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
2
  import _createClass from "@babel/runtime/helpers/createClass";
4
3
  import _inherits from "@babel/runtime/helpers/inherits";
5
4
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
5
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
7
7
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
8
  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); }; }
10
9
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
10
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
11
11
  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; }
12
12
  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; }
13
+ import { fg } from '@atlaskit/platform-feature-flags';
13
14
  import { userRequestAnalytics } from '../util/analytics';
15
+ import { localTime } from '../util/date';
14
16
  import { getPageTime } from '../util/performance';
15
17
  import CachingClient from './CachingClient';
16
18
  import { getErrorAttributes } from './errorUtils';
17
- import { directoryGraphqlQuery } from './graphqlUtils';
19
+ import { AGGQuery, directoryGraphqlQuery } from './graphqlUtils';
18
20
 
19
21
  /**
20
22
  * Transform response from GraphQL
@@ -61,6 +63,50 @@ export var buildUserQuery = function buildUserQuery(cloudId, userId) {
61
63
  }
62
64
  };
63
65
  };
66
+ export var buildAggUserQuery = function buildAggUserQuery(userId) {
67
+ return {
68
+ query: "query TeamsUserQuery($userId: ID!) {\n\t\tuser(accountId: $userId) {\n\t\t\tid\n\t\t\tname\n\t\t\tpicture\n\t\t\taccountStatus\n\t\t\t__typename\n\t\t\t... on AtlassianAccountUser {\n\t\t\t\temail\n\t\t\t\tnickname\n\t\t\t\tzoneinfo\n\t\t\t\textendedProfile {\n\t\t\t\t\tjobTitle\n\t\t\t\t\torganization\n\t\t\t\t\tlocation\n\t\t\t\t\tclosedDate\n\t\t\t\t\tinactiveDate\n\t\t\t\t}\n\t\t\t}\n\t\t\t... on CustomerUser {\n\t\t\t\temail\n\t\t\t\tzoneinfo\n\t\t\t}\n\t\t}\n\t}",
69
+ variables: {
70
+ userId: userId
71
+ }
72
+ };
73
+ };
74
+ var getUserInSiteUserBase = function getUserInSiteUserBase(cloudId, userId) {
75
+ return fetch(new Request("/gateway/api/teams/site/".concat(cloudId, "/users/").concat(userId, "/exists"), {
76
+ method: 'GET',
77
+ credentials: 'include',
78
+ mode: 'cors',
79
+ headers: {
80
+ Accept: 'application/json',
81
+ 'X-header-client-id': 'ptc-fe'
82
+ }
83
+ })).then(function (response) {
84
+ return response.json();
85
+ });
86
+ };
87
+ var queryAGGUser = /*#__PURE__*/function () {
88
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url, userId) {
89
+ var query, _yield$AGGQuery, user;
90
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
91
+ while (1) switch (_context.prev = _context.next) {
92
+ case 0:
93
+ query = buildAggUserQuery(userId);
94
+ _context.next = 3;
95
+ return AGGQuery(url, query);
96
+ case 3:
97
+ _yield$AGGQuery = _context.sent;
98
+ user = _yield$AGGQuery.user;
99
+ return _context.abrupt("return", user);
100
+ case 6:
101
+ case "end":
102
+ return _context.stop();
103
+ }
104
+ }, _callee);
105
+ }));
106
+ return function queryAGGUser(_x, _x2) {
107
+ return _ref.apply(this, arguments);
108
+ };
109
+ }();
64
110
  var UserProfileCardClient = /*#__PURE__*/function (_CachingClient) {
65
111
  _inherits(UserProfileCardClient, _CachingClient);
66
112
  var _super = _createSuper(UserProfileCardClient);
@@ -74,30 +120,78 @@ var UserProfileCardClient = /*#__PURE__*/function (_CachingClient) {
74
120
  _createClass(UserProfileCardClient, [{
75
121
  key: "makeRequest",
76
122
  value: function () {
77
- var _makeRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(cloudId, userId) {
78
- var query, response;
79
- return _regeneratorRuntime.wrap(function _callee$(_context) {
80
- while (1) switch (_context.prev = _context.next) {
123
+ var _makeRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(cloudId, userId) {
124
+ var _user$extendedProfile, _user$extendedProfile2, _user$extendedProfile3, _user$extendedProfile4, _user$extendedProfile5, userCheckPromise, userQueryPromise, checkUserPresentInSiteRes, user, timestring, localWeekdayIndex, query, response;
125
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
126
+ while (1) switch (_context2.prev = _context2.next) {
81
127
  case 0:
128
+ if (!fg('migrate_cloud_user_to_agg_user_query')) {
129
+ _context2.next = 18;
130
+ break;
131
+ }
132
+ if (this.options.gatewayGraphqlUrl) {
133
+ _context2.next = 3;
134
+ break;
135
+ }
136
+ throw new Error('options.gatewayGraphqlUrl is a required parameter');
137
+ case 3:
138
+ userCheckPromise = getUserInSiteUserBase(cloudId, userId);
139
+ userQueryPromise = queryAGGUser(this.options.gatewayGraphqlUrl, userId);
140
+ _context2.next = 7;
141
+ return userCheckPromise;
142
+ case 7:
143
+ checkUserPresentInSiteRes = _context2.sent;
144
+ if (checkUserPresentInSiteRes.isPresent) {
145
+ _context2.next = 10;
146
+ break;
147
+ }
148
+ throw new Error('Unable to fetch user: User does not exist in this site');
149
+ case 10:
150
+ _context2.next = 12;
151
+ return userQueryPromise;
152
+ case 12:
153
+ user = _context2.sent;
154
+ localWeekdayIndex = new Date().getDay().toString();
155
+ if (user.zoneinfo) {
156
+ if (localTime(user.zoneinfo, 'i') === localWeekdayIndex) {
157
+ timestring = localTime(user.zoneinfo, 'h:mmbbb') || undefined;
158
+ } else {
159
+ timestring = localTime(user.zoneinfo, 'eee h:mmbbb') || undefined;
160
+ }
161
+ }
162
+ return _context2.abrupt("return", _objectSpread(_objectSpread({}, user), {}, {
163
+ isBot: user.__typename === 'AppUser',
164
+ status: user.accountStatus,
165
+ statusModifiedDate: ((_user$extendedProfile = user.extendedProfile) === null || _user$extendedProfile === void 0 ? void 0 : _user$extendedProfile.closedDate) || ((_user$extendedProfile2 = user.extendedProfile) === null || _user$extendedProfile2 === void 0 ? void 0 : _user$extendedProfile2.inactiveDate),
166
+ avatarUrl: user.picture,
167
+ email: user.email,
168
+ fullName: user.name,
169
+ location: (_user$extendedProfile3 = user.extendedProfile) === null || _user$extendedProfile3 === void 0 ? void 0 : _user$extendedProfile3.location,
170
+ meta: (_user$extendedProfile4 = user.extendedProfile) === null || _user$extendedProfile4 === void 0 ? void 0 : _user$extendedProfile4.jobTitle,
171
+ nickname: user.nickname,
172
+ companyName: (_user$extendedProfile5 = user.extendedProfile) === null || _user$extendedProfile5 === void 0 ? void 0 : _user$extendedProfile5.organization,
173
+ timestring: timestring
174
+ }));
175
+ case 18:
82
176
  if (this.options.url) {
83
- _context.next = 2;
177
+ _context2.next = 20;
84
178
  break;
85
179
  }
86
180
  throw new Error('options.url is a required parameter');
87
- case 2:
181
+ case 20:
88
182
  query = buildUserQuery(cloudId, userId);
89
- _context.next = 5;
183
+ _context2.next = 23;
90
184
  return directoryGraphqlQuery(this.options.url, query);
91
- case 5:
92
- response = _context.sent;
93
- return _context.abrupt("return", modifyResponse(response));
94
- case 7:
185
+ case 23:
186
+ response = _context2.sent;
187
+ return _context2.abrupt("return", modifyResponse(response));
188
+ case 25:
95
189
  case "end":
96
- return _context.stop();
190
+ return _context2.stop();
97
191
  }
98
- }, _callee, this);
192
+ }, _callee2, this);
99
193
  }));
100
- function makeRequest(_x, _x2) {
194
+ function makeRequest(_x3, _x4) {
101
195
  return _makeRequest.apply(this, arguments);
102
196
  }
103
197
  return makeRequest;
@@ -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.19.0");
51
+ headers.append('atl-client-version', "19.20.0");
52
52
  return headers;
53
53
  };
54
54
  export function getTeamFromAGG(_x, _x2, _x3) {
@@ -1,13 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
4
  var _excluded = ["triggerRef"];
4
- import React from 'react';
5
+ import React, { useState } from 'react';
5
6
  import { defineMessages, FormattedMessage, useIntl } from 'react-intl-next';
6
7
  import Button, { IconButton } from '@atlaskit/button/new';
7
8
  import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
8
9
  import MoreIcon from '@atlaskit/icon/core/migration/show-more-horizontal--more';
9
10
  import { Box, Inline, xcss } from '@atlaskit/primitives';
10
11
  import { ChatPillIcon } from '@atlaskit/rovo-agent-components';
12
+ import { AgentDeleteConfirmationModal } from './AgentDeleteConfirmationModal';
11
13
  var chatToAgentButtonContainer = xcss({
12
14
  width: '100%'
13
15
  });
@@ -80,15 +82,21 @@ export var AgentActions = function AgentActions(_ref3) {
80
82
  onChatClick = _ref3.onChatClick;
81
83
  var _useIntl = useIntl(),
82
84
  formatMessage = _useIntl.formatMessage;
85
+ var _useState = useState(false),
86
+ _useState2 = _slicedToArray(_useState, 2),
87
+ isDeleteModalOpen = _useState2[0],
88
+ setIsDeleteModalOpen = _useState2[1];
83
89
  var agentActions = buildAgentActions({
84
90
  onDuplicateAgent: onDuplicateAgent,
85
91
  onCopyAgent: onCopyAgent
86
92
  });
87
93
  var agentSetting = buildAgentSettings({
88
94
  onEditAgent: onEditAgent,
89
- onDeleteAgent: onDeleteAgent
95
+ onDeleteAgent: function onDeleteAgent() {
96
+ setIsDeleteModalOpen(true);
97
+ }
90
98
  });
91
- return /*#__PURE__*/React.createElement(Inline, {
99
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Inline, {
92
100
  space: "space.100",
93
101
  xcss: actopnsWrapperStyles
94
102
  }, /*#__PURE__*/React.createElement(Box, {
@@ -134,7 +142,15 @@ export var AgentActions = function AgentActions(_ref3) {
134
142
  key: idx,
135
143
  onClick: onClick
136
144
  }, text);
137
- }))));
145
+ })))), /*#__PURE__*/React.createElement(AgentDeleteConfirmationModal, {
146
+ isOpen: isDeleteModalOpen,
147
+ onClose: function onClose() {
148
+ setIsDeleteModalOpen(false);
149
+ },
150
+ onSubmit: onDeleteAgent,
151
+ agentId: 'some Id',
152
+ agentName: "agentName"
153
+ }));
138
154
  };
139
155
  var messages = defineMessages({
140
156
  actionChatToAgent: {
@@ -0,0 +1,94 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import React, { useCallback } from 'react';
4
+ import { defineMessages, useIntl } from 'react-intl-next';
5
+ import Button from '@atlaskit/button/new';
6
+ import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
7
+ import { Text } from '@atlaskit/primitives';
8
+ export var AgentDeleteConfirmationModal = function AgentDeleteConfirmationModal(_ref) {
9
+ var onClose = _ref.onClose,
10
+ agentName = _ref.agentName,
11
+ isOpen = _ref.isOpen,
12
+ onSubmit = _ref.onSubmit,
13
+ agentId = _ref.agentId;
14
+ var _useIntl = useIntl(),
15
+ formatMessage = _useIntl.formatMessage;
16
+ var handleDeleteAgent = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
17
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
18
+ while (1) switch (_context.prev = _context.next) {
19
+ case 0:
20
+ if (!agentId) {
21
+ _context.next = 4;
22
+ break;
23
+ }
24
+ _context.next = 3;
25
+ return onSubmit();
26
+ case 3:
27
+ onClose();
28
+ case 4:
29
+ case "end":
30
+ return _context.stop();
31
+ }
32
+ }, _callee);
33
+ })), [agentId, onClose, onSubmit]);
34
+ return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen && /*#__PURE__*/React.createElement(Modal, {
35
+ width: "small"
36
+ }, /*#__PURE__*/React.createElement(ModalHeader, null, /*#__PURE__*/React.createElement(ModalTitle, null, formatMessage(messages.title, {
37
+ agentName: agentName
38
+ }))), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Text, {
39
+ as: "p"
40
+ }, formatMessage(messages.body)), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
41
+ appearance: "subtle",
42
+ onClick: onClose
43
+ }, formatMessage(messages.cancelText)), /*#__PURE__*/React.createElement(Button, {
44
+ appearance: "danger",
45
+ onClick: function onClick(_e, event) {
46
+ handleDeleteAgent();
47
+ }
48
+ }, formatMessage(messages.confirmText))))));
49
+ };
50
+ var messages = defineMessages({
51
+ cancelText: {
52
+ id: 'ai-mate.agent-modal.agent-delete-confirm.cancel-text',
53
+ defaultMessage: 'Cancel'
54
+ },
55
+ confirmText: {
56
+ id: 'ai-mate.agent-modal.agent-delete-confirm.confirm-text',
57
+ defaultMessage: 'Delete'
58
+ },
59
+ title: {
60
+ id: 'ai-mate.agent-list.delete-agent-confirm-title',
61
+ defaultMessage: 'Delete "{agentName}"?',
62
+ description: 'Title text for the delete agent confirmation modal'
63
+ },
64
+ body: {
65
+ id: 'ai-mate.agent-list.delete-agent-confirm-body',
66
+ defaultMessage: "Are you sure you want to delete this agent? This action cannot be undone.",
67
+ description: 'Body text for the delete agent confirmation modal'
68
+ },
69
+ error: {
70
+ id: 'ai-mate.agent-list.delete-agent-error',
71
+ defaultMessage: 'Could not delete agent',
72
+ description: 'Error message displayed when an agent cannot be deleted'
73
+ },
74
+ errorAgentNotFound: {
75
+ id: 'ai-mate.agent-list.delete-agent-error.agent-not-found',
76
+ defaultMessage: 'That agent could not be found.',
77
+ description: 'Error message displayed when an agent cannot be found'
78
+ },
79
+ errorAgentInUse: {
80
+ id: 'ai-mate.agent-list.delete-agent-error.agent-in-use',
81
+ defaultMessage: 'Agent is currently in use. Try again later.',
82
+ description: 'Error message displayed when an agent is in use'
83
+ },
84
+ errorIncorrectOwner: {
85
+ id: 'ai-mate.agent-list.delete-agent-error.incorrect-owner',
86
+ defaultMessage: 'You cannot delete agents you have not created yourself. Please contact the agent owner.',
87
+ description: 'Error message displayed when the agent owner is incorrect'
88
+ },
89
+ agentDeletedSuccess: {
90
+ id: 'ai-mate.agent-list.delete-agent-success',
91
+ defaultMessage: 'Agent has been deleted!',
92
+ description: 'Success message displayed when an agent is deleted'
93
+ }
94
+ });
@@ -1,3 +1,5 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
1
3
  import React, { useCallback, useEffect } from 'react';
2
4
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
5
  import { Box, Stack, xcss } from '@atlaskit/primitives';
@@ -8,8 +10,9 @@ import { ErrorMessage } from '../Error';
8
10
  import { AgentActions } from './Actions';
9
11
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
10
12
  import { ConversationStarters } from './ConversationStarters';
11
- import { useAgentUrlActions } from './useAgentActions';
12
- import { useSetFavouriteAgent } from './useSetFavouriteAgent';
13
+ import { useAgentUrlActions } from './hooks/useAgentActions';
14
+ import { useDeleteAgent } from './hooks/useDeleteAgent';
15
+ import { useSetFavouriteAgent } from './hooks/useSetFavouriteAgent';
13
16
  var styles = xcss({
14
17
  paddingBlockStart: 'space.400',
15
18
  paddingInline: 'space.200'
@@ -40,7 +43,9 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
40
43
  }),
41
44
  _onEditAgent = _useAgentUrlActions.onEditAgent,
42
45
  _onCopyAgent = _useAgentUrlActions.onCopyAgent,
43
- _onDuplicateAgent = _useAgentUrlActions.onDuplicateAgent;
46
+ _onDuplicateAgent = _useAgentUrlActions.onDuplicateAgent,
47
+ onOpenChatFullScreecn = _useAgentUrlActions.onOpenChat,
48
+ onConversationStarter = _useAgentUrlActions.onConversationStarter;
44
49
  var _useSetFavouriteAgent = useSetFavouriteAgent({
45
50
  agentId: agent === null || agent === void 0 ? void 0 : agent.id,
46
51
  cloudId: cloudId,
@@ -49,6 +54,11 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
49
54
  }),
50
55
  isStarred = _useSetFavouriteAgent.isStarred,
51
56
  setFavourite = _useSetFavouriteAgent.setFavourite;
57
+ var _useDeleteAgent = useDeleteAgent({
58
+ cloudId: cloudId,
59
+ product: product
60
+ }),
61
+ deleteAgent = _useDeleteAgent.deleteAgent;
52
62
  var _useAnalyticsEvents = useAnalyticsEvents(),
53
63
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
54
64
  var fireAnalytics = useCallback(function (payload) {
@@ -56,6 +66,27 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
56
66
  fireEvent(createAnalyticsEvent, payload);
57
67
  }
58
68
  }, [createAnalyticsEvent]);
69
+ var handleOnDelete = /*#__PURE__*/function () {
70
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
71
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
72
+ while (1) switch (_context.prev = _context.next) {
73
+ case 0:
74
+ if (!agent) {
75
+ _context.next = 3;
76
+ break;
77
+ }
78
+ _context.next = 3;
79
+ return deleteAgent(agent.id);
80
+ case 3:
81
+ case "end":
82
+ return _context.stop();
83
+ }
84
+ }, _callee);
85
+ }));
86
+ return function handleOnDelete() {
87
+ return _ref2.apply(this, arguments);
88
+ };
89
+ }();
59
90
  useEffect(function () {
60
91
  if (!isLoading && agent) {
61
92
  fireAnalytics(profileCardRendered('agent', 'content'));
@@ -107,7 +138,10 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
107
138
  isAgentDefault: agent.is_default,
108
139
  userDefinedConversationStarters: agent.user_defined_conversation_starters,
109
140
  onConversationStarterClick: function onConversationStarterClick(conversationStarter) {
110
- throw new Error('Function not implemented.');
141
+ onConversationStarter({
142
+ agentId: agent.id,
143
+ prompt: 'conversationStarter'
144
+ });
111
145
  }
112
146
  })), /*#__PURE__*/React.createElement(AgentActions, {
113
147
  isAgentCreatedByCurrentUser: isCreatedByViewingUser,
@@ -120,11 +154,9 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
120
154
  onDuplicateAgent: function onDuplicateAgent() {
121
155
  return _onDuplicateAgent(agent.id);
122
156
  },
123
- onDeleteAgent: function onDeleteAgent() {
124
- throw new Error('Function not implemented.');
125
- },
157
+ onDeleteAgent: handleOnDelete,
126
158
  onChatClick: function onChatClick() {
127
- return onOpenChat === null || onOpenChat === void 0 ? void 0 : onOpenChat(agent.id);
159
+ return onOpenChat ? onOpenChat(agent.id) : onOpenChatFullScreecn();
128
160
  }
129
161
  })));
130
162
  };
@@ -131,7 +131,8 @@ export var AgentProfileCardTrigger = function AgentProfileCardTrigger(_ref) {
131
131
  isCreatedByViewingUser: (profileData === null || profileData === void 0 || (_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
132
132
  cloudId: props.cloudId,
133
133
  product: product,
134
- errorType: error
134
+ errorType: error,
135
+ onOpenChat: props.onOpenChat
135
136
  }));
136
137
  };
137
138
  return /*#__PURE__*/React.createElement(ProfileCardTrigger, _extends({}, props, {
@@ -0,0 +1,85 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ 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; }
4
+ 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; }
5
+ import { useCallback } from 'react';
6
+ import { getATLContextUrl } from '@atlaskit/atlassian-context';
7
+ import { encodeParamsToUrl } from '../../../util/url';
8
+ export var firstCharUpper = function firstCharUpper(str) {
9
+ return str.charAt(0).toUpperCase() + str.slice(1);
10
+ };
11
+ var ROVO_PARAM_PREFIX = 'rovoChat';
12
+ var createRovoParams = function createRovoParams(params) {
13
+ var rovoParams = {};
14
+ Object.entries(params).forEach(function (_ref) {
15
+ var _ref2 = _slicedToArray(_ref, 2),
16
+ key = _ref2[0],
17
+ value = _ref2[1];
18
+ rovoParams["".concat(ROVO_PARAM_PREFIX, ".").concat(key)] = encodeURIComponent(value);
19
+ rovoParams["".concat(ROVO_PARAM_PREFIX).concat(firstCharUpper(key))] = encodeURIComponent(value);
20
+ });
21
+ return rovoParams;
22
+ };
23
+ export var useAgentUrlActions = function useAgentUrlActions(_ref3) {
24
+ var cloudId = _ref3.cloudId;
25
+ var onEditAgent = useCallback(function (agentId) {
26
+ var url = "".concat(getATLContextUrl('home'), "/agents/").concat(agentId, "/edit");
27
+ var urlWithParams = encodeParamsToUrl(url, _objectSpread({
28
+ cloudId: cloudId
29
+ }, createRovoParams({
30
+ cloudId: cloudId
31
+ })));
32
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
33
+ }, [cloudId]);
34
+ var onCopyAgent = useCallback(function (agentId) {
35
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
36
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
37
+ cloudId: cloudId
38
+ }, createRovoParams({
39
+ cloudId: cloudId,
40
+ agentId: agentId,
41
+ pathway: 'chat'
42
+ })));
43
+ navigator.clipboard.writeText(urlWithParams);
44
+ }, [cloudId]);
45
+ var onDuplicateAgent = useCallback(function (agentId) {
46
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat/agents/new");
47
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
48
+ cloudId: cloudId
49
+ }, createRovoParams({
50
+ cloudId: cloudId,
51
+ agentId: agentId,
52
+ pathway: 'agents-create'
53
+ })));
54
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
55
+ }, [cloudId]);
56
+ var onConversationStarter = function onConversationStarter(_ref4) {
57
+ var agentId = _ref4.agentId,
58
+ prompt = _ref4.prompt;
59
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
60
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
61
+ cloudId: cloudId
62
+ }, createRovoParams({
63
+ cloudId: cloudId,
64
+ agentId: agentId,
65
+ prompt: prompt
66
+ })));
67
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
68
+ };
69
+ var onOpenChat = function onOpenChat() {
70
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
71
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
72
+ cloudId: cloudId
73
+ }, createRovoParams({
74
+ cloudId: cloudId
75
+ })));
76
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
77
+ };
78
+ return {
79
+ onEditAgent: onEditAgent,
80
+ onCopyAgent: onCopyAgent,
81
+ onDuplicateAgent: onDuplicateAgent,
82
+ onOpenChat: onOpenChat,
83
+ onConversationStarter: onConversationStarter
84
+ };
85
+ };