@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
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useDeleteAgent = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _react = require("react");
12
+ var _rovoAgentUtils = require("../../../util/rovoAgentUtils");
13
+ var useDeleteAgent = exports.useDeleteAgent = function useDeleteAgent(_ref) {
14
+ var cloudId = _ref.cloudId,
15
+ product = _ref.product;
16
+ var _useState = (0, _react.useState)(false),
17
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
18
+ isLoading = _useState2[0],
19
+ setIsLoading = _useState2[1];
20
+ var _useState3 = (0, _react.useState)(),
21
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
22
+ error = _useState4[0],
23
+ setError = _useState4[1];
24
+ var deleteAgent = /*#__PURE__*/function () {
25
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(agentId) {
26
+ var headers;
27
+ return _regenerator.default.wrap(function _callee$(_context) {
28
+ while (1) switch (_context.prev = _context.next) {
29
+ case 0:
30
+ if (!(!agentId || !cloudId)) {
31
+ _context.next = 2;
32
+ break;
33
+ }
34
+ return _context.abrupt("return");
35
+ case 2:
36
+ setIsLoading(true);
37
+ _context.prev = 3;
38
+ headers = (0, _rovoAgentUtils.createHeaders)(product, cloudId);
39
+ _context.next = 7;
40
+ return fetch(new Request("/gateway/api/assist/agents/v1/".concat(agentId), {
41
+ method: 'DELETE',
42
+ credentials: 'include',
43
+ mode: 'cors',
44
+ headers: headers
45
+ }));
46
+ case 7:
47
+ setIsLoading(false);
48
+ _context.next = 14;
49
+ break;
50
+ case 10:
51
+ _context.prev = 10;
52
+ _context.t0 = _context["catch"](3);
53
+ setIsLoading(false);
54
+ setError(_context.t0);
55
+ case 14:
56
+ case "end":
57
+ return _context.stop();
58
+ }
59
+ }, _callee, null, [[3, 10]]);
60
+ }));
61
+ return function deleteAgent(_x) {
62
+ return _ref2.apply(this, arguments);
63
+ };
64
+ }();
65
+ return {
66
+ isLoading: isLoading,
67
+ error: error,
68
+ deleteAgent: deleteAgent
69
+ };
70
+ };
@@ -9,7 +9,7 @@ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"))
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
  var _react = require("react");
12
- var _rovoAgentUtils = require("../../util/rovoAgentUtils");
12
+ var _rovoAgentUtils = require("../../../util/rovoAgentUtils");
13
13
  var useSetFavouriteAgent = exports.useSetFavouriteAgent = function useSetFavouriteAgent(_ref) {
14
14
  var agentId = _ref.agentId,
15
15
  cloudId = _ref.cloudId,
@@ -17,6 +17,7 @@ var _react = _interopRequireWildcard(require("react"));
17
17
  var _reactIntlNext = require("react-intl-next");
18
18
  var _analyticsNext = require("@atlaskit/analytics-next");
19
19
  var _giveKudos = require("@atlaskit/give-kudos");
20
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
21
  var _popup = _interopRequireDefault(require("@atlaskit/popup"));
21
22
  var _constants = require("@atlaskit/theme/constants");
22
23
  var _filterActions = _interopRequireDefault(require("../../internal/filterActions"));
@@ -52,7 +53,8 @@ function ProfilecardTriggerNext(_ref) {
52
53
  prepopulatedData = _ref.prepopulatedData,
53
54
  disabledAriaAttributes = _ref.disabledAriaAttributes,
54
55
  onVisibilityChange = _ref.onVisibilityChange,
55
- offset = _ref.offset;
56
+ offset = _ref.offset,
57
+ viewingUserId = _ref.viewingUserId;
56
58
  var _useAnalyticsEvents = (0, _analyticsNext.useAnalyticsEvents)(),
57
59
  createAnalyticsEvent = _useAnalyticsEvents.createAnalyticsEvent;
58
60
  var _useIntl = (0, _reactIntlNext.useIntl)(),
@@ -274,7 +276,7 @@ function ProfilecardTriggerNext(_ref) {
274
276
  var profilecardProps = _objectSpread(_objectSpread({
275
277
  userId: userId,
276
278
  fullName: prepopulatedData === null || prepopulatedData === void 0 ? void 0 : prepopulatedData.fullName,
277
- isCurrentUser: data === null || data === void 0 ? void 0 : data.isCurrentUser,
279
+ isCurrentUser: (0, _platformFeatureFlags.fg)('migrate_cloud_user_to_agg_user_query') ? userId === viewingUserId : data === null || data === void 0 ? void 0 : data.isCurrentUser,
278
280
  clientFetchProfile: clientFetchProfile
279
281
  }, data), {}, {
280
282
  reportingLines: reportingLinesData,
@@ -45,25 +45,25 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
45
45
  actionSubjectId: actionSubjectId,
46
46
  attributes: _objectSpread(_objectSpread({
47
47
  packageName: "@atlaskit/profilecard",
48
- packageVersion: "19.19.0"
48
+ packageVersion: "19.20.0"
49
49
  }, attributes), {}, {
50
50
  firedAt: Math.round((0, _performance.getPageTime)())
51
51
  })
52
52
  };
53
53
  };
54
+ var getActionSubject = function getActionSubject(type) {
55
+ switch (type) {
56
+ case 'user':
57
+ return USER_SUBJECT;
58
+ case 'team':
59
+ return TEAM_SUBJECT;
60
+ case 'agent':
61
+ return AGENT_SUBJECT;
62
+ default:
63
+ return 'user';
64
+ }
65
+ };
54
66
  var cardTriggered = exports.cardTriggered = function cardTriggered(type, method) {
55
- var getActionSubject = function getActionSubject(type) {
56
- switch (type) {
57
- case 'user':
58
- return USER_SUBJECT;
59
- case 'team':
60
- return TEAM_SUBJECT;
61
- case 'agent':
62
- return AGENT_SUBJECT;
63
- default:
64
- return 'user';
65
- }
66
- };
67
67
  return createEvent('ui', 'triggered', getActionSubject(type), undefined, {
68
68
  method: method
69
69
  });
@@ -75,16 +75,16 @@ var userRequestAnalytics = exports.userRequestAnalytics = function userRequestAn
75
75
  return createEvent('operational', action, USER_SUBJECT, 'request', attributes);
76
76
  };
77
77
  var profileCardRendered = exports.profileCardRendered = function profileCardRendered(type, actionSubjectId, attributes) {
78
- return createEvent('ui', 'rendered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, actionSubjectId, attributes);
78
+ return createEvent('ui', 'rendered', getActionSubject(type), actionSubjectId, attributes);
79
79
  };
80
80
  var actionClicked = exports.actionClicked = function actionClicked(type, attributes) {
81
- return createEvent('ui', 'clicked', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, 'action', attributes);
81
+ return createEvent('ui', 'clicked', getActionSubject(type), 'action', attributes);
82
82
  };
83
83
  var reportingLinesClicked = exports.reportingLinesClicked = function reportingLinesClicked(attributes) {
84
84
  return createEvent('ui', 'clicked', USER_SUBJECT, 'reportingLines', attributes);
85
85
  };
86
86
  var moreActionsClicked = exports.moreActionsClicked = function moreActionsClicked(type, attributes) {
87
- return createEvent('ui', 'clicked', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, 'moreActions', attributes);
87
+ return createEvent('ui', 'clicked', getActionSubject(type), 'moreActions', attributes);
88
88
  };
89
89
  var teamAvatarClicked = exports.teamAvatarClicked = function teamAvatarClicked(attributes) {
90
90
  return createEvent('ui', 'clicked', TEAM_SUBJECT, 'avatar', attributes);
@@ -9,13 +9,10 @@ export default class RovoAgentCardClient extends CachingClient {
9
9
  this.options = options;
10
10
  }
11
11
  makeRequest(id, cloudId) {
12
- if (!this.options.productIdentifier) {
13
- throw new Error('Trying to fetch agents data with no specified config.productIdentifier');
14
- }
15
12
  if (id.type === 'identity') {
16
- return getAgentDetailsByUserId(id.value, this.options.productIdentifier, cloudId);
13
+ return getAgentDetailsByUserId(id.value, this.options.productIdentifier || 'rovo', cloudId);
17
14
  }
18
- return getAgentDetailsByAgentId(id.value, this.options.productIdentifier, cloudId);
15
+ return getAgentDetailsByAgentId(id.value, this.options.productIdentifier || 'rovo', cloudId);
19
16
  }
20
17
  getProfile(id, analytics) {
21
18
  if (!id.value) {
@@ -1,8 +1,10 @@
1
+ import { fg } from '@atlaskit/platform-feature-flags';
1
2
  import { userRequestAnalytics } from '../util/analytics';
3
+ import { localTime } from '../util/date';
2
4
  import { getPageTime } from '../util/performance';
3
5
  import CachingClient from './CachingClient';
4
6
  import { getErrorAttributes } from './errorUtils';
5
- import { directoryGraphqlQuery } from './graphqlUtils';
7
+ import { AGGQuery, directoryGraphqlQuery } from './graphqlUtils';
6
8
 
7
9
  /**
8
10
  * Transform response from GraphQL
@@ -68,18 +70,104 @@ export const buildUserQuery = (cloudId, userId) => ({
68
70
  userId
69
71
  }
70
72
  });
73
+ export const buildAggUserQuery = userId => ({
74
+ query: `query TeamsUserQuery($userId: ID!) {
75
+ user(accountId: $userId) {
76
+ id
77
+ name
78
+ picture
79
+ accountStatus
80
+ __typename
81
+ ... on AtlassianAccountUser {
82
+ email
83
+ nickname
84
+ zoneinfo
85
+ extendedProfile {
86
+ jobTitle
87
+ organization
88
+ location
89
+ closedDate
90
+ inactiveDate
91
+ }
92
+ }
93
+ ... on CustomerUser {
94
+ email
95
+ zoneinfo
96
+ }
97
+ }
98
+ }`,
99
+ variables: {
100
+ userId
101
+ }
102
+ });
103
+ const getUserInSiteUserBase = (cloudId, userId) => {
104
+ return fetch(new Request(`/gateway/api/teams/site/${cloudId}/users/${userId}/exists`, {
105
+ method: 'GET',
106
+ credentials: 'include',
107
+ mode: 'cors',
108
+ headers: {
109
+ Accept: 'application/json',
110
+ 'X-header-client-id': 'ptc-fe'
111
+ }
112
+ })).then(response => response.json());
113
+ };
114
+ const queryAGGUser = async (url, userId) => {
115
+ const query = buildAggUserQuery(userId);
116
+ const {
117
+ user
118
+ } = await AGGQuery(url, query);
119
+ return user;
120
+ };
71
121
  export default class UserProfileCardClient extends CachingClient {
72
122
  constructor(options) {
73
123
  super(options);
74
124
  this.options = options;
75
125
  }
76
126
  async makeRequest(cloudId, userId) {
77
- if (!this.options.url) {
78
- throw new Error('options.url is a required parameter');
127
+ if (fg('migrate_cloud_user_to_agg_user_query')) {
128
+ var _user$extendedProfile, _user$extendedProfile2, _user$extendedProfile3, _user$extendedProfile4, _user$extendedProfile5;
129
+ if (!this.options.gatewayGraphqlUrl) {
130
+ throw new Error('options.gatewayGraphqlUrl is a required parameter');
131
+ }
132
+ const userCheckPromise = getUserInSiteUserBase(cloudId, userId);
133
+ const userQueryPromise = queryAGGUser(this.options.gatewayGraphqlUrl, userId);
134
+ const checkUserPresentInSiteRes = await userCheckPromise;
135
+ if (!checkUserPresentInSiteRes.isPresent) {
136
+ // Use this error message to not trouble SLO, check out getErrorAttributes for reference
137
+ throw new Error('Unable to fetch user: User does not exist in this site');
138
+ }
139
+ const user = await userQueryPromise;
140
+ let timestring;
141
+ const localWeekdayIndex = new Date().getDay().toString();
142
+ if (user.zoneinfo) {
143
+ if (localTime(user.zoneinfo, 'i') === localWeekdayIndex) {
144
+ timestring = localTime(user.zoneinfo, 'h:mmbbb') || undefined;
145
+ } else {
146
+ timestring = localTime(user.zoneinfo, 'eee h:mmbbb') || undefined;
147
+ }
148
+ }
149
+ return {
150
+ ...user,
151
+ isBot: user.__typename === 'AppUser',
152
+ status: user.accountStatus,
153
+ 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),
154
+ avatarUrl: user.picture,
155
+ email: user.email,
156
+ fullName: user.name,
157
+ location: (_user$extendedProfile3 = user.extendedProfile) === null || _user$extendedProfile3 === void 0 ? void 0 : _user$extendedProfile3.location,
158
+ meta: (_user$extendedProfile4 = user.extendedProfile) === null || _user$extendedProfile4 === void 0 ? void 0 : _user$extendedProfile4.jobTitle,
159
+ nickname: user.nickname,
160
+ companyName: (_user$extendedProfile5 = user.extendedProfile) === null || _user$extendedProfile5 === void 0 ? void 0 : _user$extendedProfile5.organization,
161
+ timestring: timestring
162
+ };
163
+ } else {
164
+ if (!this.options.url) {
165
+ throw new Error('options.url is a required parameter');
166
+ }
167
+ const query = buildUserQuery(cloudId, userId);
168
+ const response = await directoryGraphqlQuery(this.options.url, query);
169
+ return modifyResponse(response);
79
170
  }
80
- const query = buildUserQuery(cloudId, userId);
81
- const response = await directoryGraphqlQuery(this.options.url, query);
82
- return modifyResponse(response);
83
171
  }
84
172
  getProfile(cloudId, userId, analytics) {
85
173
  if (!userId) {
@@ -67,7 +67,7 @@ export const addHeaders = headers => {
67
67
  headers.append('X-ExperimentalApi', 'teams-beta');
68
68
  headers.append('X-ExperimentalApi', 'team-members-beta');
69
69
  headers.append('atl-client-name', "@atlaskit/profilecard");
70
- headers.append('atl-client-version', "19.19.0");
70
+ headers.append('atl-client-version', "19.20.0");
71
71
  return headers;
72
72
  };
73
73
  export async function getTeamFromAGG(url, teamId, siteId) {
@@ -1,11 +1,12 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React from 'react';
2
+ import React, { useState } from 'react';
3
3
  import { defineMessages, FormattedMessage, useIntl } from 'react-intl-next';
4
4
  import Button, { IconButton } from '@atlaskit/button/new';
5
5
  import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
6
6
  import MoreIcon from '@atlaskit/icon/core/migration/show-more-horizontal--more';
7
7
  import { Box, Inline, xcss } from '@atlaskit/primitives';
8
8
  import { ChatPillIcon } from '@atlaskit/rovo-agent-components';
9
+ import { AgentDeleteConfirmationModal } from './AgentDeleteConfirmationModal';
9
10
  const chatToAgentButtonContainer = xcss({
10
11
  width: '100%'
11
12
  });
@@ -82,15 +83,18 @@ export const AgentActions = ({
82
83
  const {
83
84
  formatMessage
84
85
  } = useIntl();
86
+ const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
85
87
  const agentActions = buildAgentActions({
86
88
  onDuplicateAgent,
87
89
  onCopyAgent
88
90
  });
89
91
  const agentSetting = buildAgentSettings({
90
92
  onEditAgent,
91
- onDeleteAgent
93
+ onDeleteAgent: () => {
94
+ setIsDeleteModalOpen(true);
95
+ }
92
96
  });
93
- return /*#__PURE__*/React.createElement(Inline, {
97
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Inline, {
94
98
  space: "space.100",
95
99
  xcss: actopnsWrapperStyles
96
100
  }, /*#__PURE__*/React.createElement(Box, {
@@ -137,7 +141,15 @@ export const AgentActions = ({
137
141
  key: idx,
138
142
  onClick: onClick
139
143
  }, text);
140
- }))));
144
+ })))), /*#__PURE__*/React.createElement(AgentDeleteConfirmationModal, {
145
+ isOpen: isDeleteModalOpen,
146
+ onClose: () => {
147
+ setIsDeleteModalOpen(false);
148
+ },
149
+ onSubmit: onDeleteAgent,
150
+ agentId: 'some Id',
151
+ agentName: "agentName"
152
+ }));
141
153
  };
142
154
  const messages = defineMessages({
143
155
  actionChatToAgent: {
@@ -0,0 +1,82 @@
1
+ import React, { useCallback } from 'react';
2
+ import { defineMessages, useIntl } from 'react-intl-next';
3
+ import Button from '@atlaskit/button/new';
4
+ import Modal, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
5
+ import { Text } from '@atlaskit/primitives';
6
+ export const AgentDeleteConfirmationModal = ({
7
+ onClose,
8
+ agentName,
9
+ isOpen,
10
+ onSubmit,
11
+ agentId
12
+ }) => {
13
+ const {
14
+ formatMessage
15
+ } = useIntl();
16
+ const handleDeleteAgent = useCallback(async () => {
17
+ if (agentId) {
18
+ await onSubmit();
19
+ onClose();
20
+ }
21
+ }, [agentId, onClose, onSubmit]);
22
+ return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen && /*#__PURE__*/React.createElement(Modal, {
23
+ width: "small"
24
+ }, /*#__PURE__*/React.createElement(ModalHeader, null, /*#__PURE__*/React.createElement(ModalTitle, null, formatMessage(messages.title, {
25
+ agentName
26
+ }))), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Text, {
27
+ as: "p"
28
+ }, formatMessage(messages.body)), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
29
+ appearance: "subtle",
30
+ onClick: onClose
31
+ }, formatMessage(messages.cancelText)), /*#__PURE__*/React.createElement(Button, {
32
+ appearance: "danger",
33
+ onClick: (_e, event) => {
34
+ handleDeleteAgent();
35
+ }
36
+ }, formatMessage(messages.confirmText))))));
37
+ };
38
+ const messages = defineMessages({
39
+ cancelText: {
40
+ id: 'ai-mate.agent-modal.agent-delete-confirm.cancel-text',
41
+ defaultMessage: 'Cancel'
42
+ },
43
+ confirmText: {
44
+ id: 'ai-mate.agent-modal.agent-delete-confirm.confirm-text',
45
+ defaultMessage: 'Delete'
46
+ },
47
+ title: {
48
+ id: 'ai-mate.agent-list.delete-agent-confirm-title',
49
+ defaultMessage: 'Delete "{agentName}"?',
50
+ description: 'Title text for the delete agent confirmation modal'
51
+ },
52
+ body: {
53
+ id: 'ai-mate.agent-list.delete-agent-confirm-body',
54
+ defaultMessage: `Are you sure you want to delete this agent? This action cannot be undone.`,
55
+ description: 'Body text for the delete agent confirmation modal'
56
+ },
57
+ error: {
58
+ id: 'ai-mate.agent-list.delete-agent-error',
59
+ defaultMessage: 'Could not delete agent',
60
+ description: 'Error message displayed when an agent cannot be deleted'
61
+ },
62
+ errorAgentNotFound: {
63
+ id: 'ai-mate.agent-list.delete-agent-error.agent-not-found',
64
+ defaultMessage: 'That agent could not be found.',
65
+ description: 'Error message displayed when an agent cannot be found'
66
+ },
67
+ errorAgentInUse: {
68
+ id: 'ai-mate.agent-list.delete-agent-error.agent-in-use',
69
+ defaultMessage: 'Agent is currently in use. Try again later.',
70
+ description: 'Error message displayed when an agent is in use'
71
+ },
72
+ errorIncorrectOwner: {
73
+ id: 'ai-mate.agent-list.delete-agent-error.incorrect-owner',
74
+ defaultMessage: 'You cannot delete agents you have not created yourself. Please contact the agent owner.',
75
+ description: 'Error message displayed when the agent owner is incorrect'
76
+ },
77
+ agentDeletedSuccess: {
78
+ id: 'ai-mate.agent-list.delete-agent-success',
79
+ defaultMessage: 'Agent has been deleted!',
80
+ description: 'Success message displayed when an agent is deleted'
81
+ }
82
+ });
@@ -8,8 +8,9 @@ import { ErrorMessage } from '../Error';
8
8
  import { AgentActions } from './Actions';
9
9
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
10
10
  import { ConversationStarters } from './ConversationStarters';
11
- import { useAgentUrlActions } from './useAgentActions';
12
- import { useSetFavouriteAgent } from './useSetFavouriteAgent';
11
+ import { useAgentUrlActions } from './hooks/useAgentActions';
12
+ import { useDeleteAgent } from './hooks/useDeleteAgent';
13
+ import { useSetFavouriteAgent } from './hooks/useSetFavouriteAgent';
13
14
  const styles = xcss({
14
15
  paddingBlockStart: 'space.400',
15
16
  paddingInline: 'space.200'
@@ -38,7 +39,9 @@ const AgentProfileCard = ({
38
39
  const {
39
40
  onEditAgent,
40
41
  onCopyAgent,
41
- onDuplicateAgent
42
+ onDuplicateAgent,
43
+ onOpenChat: onOpenChatFullScreecn,
44
+ onConversationStarter
42
45
  } = useAgentUrlActions({
43
46
  cloudId: cloudId || ''
44
47
  });
@@ -51,6 +54,12 @@ const AgentProfileCard = ({
51
54
  isStarred: !!(agent !== null && agent !== void 0 && agent.favourite),
52
55
  product
53
56
  });
57
+ const {
58
+ deleteAgent
59
+ } = useDeleteAgent({
60
+ cloudId,
61
+ product
62
+ });
54
63
  const {
55
64
  createAnalyticsEvent
56
65
  } = useAnalyticsEvents();
@@ -59,6 +68,11 @@ const AgentProfileCard = ({
59
68
  fireEvent(createAnalyticsEvent, payload);
60
69
  }
61
70
  }, [createAnalyticsEvent]);
71
+ const handleOnDelete = async () => {
72
+ if (agent) {
73
+ await deleteAgent(agent.id);
74
+ }
75
+ };
62
76
  useEffect(() => {
63
77
  if (!isLoading && agent) {
64
78
  fireAnalytics(profileCardRendered('agent', 'content'));
@@ -109,18 +123,19 @@ const AgentProfileCard = ({
109
123
  }), /*#__PURE__*/React.createElement(ConversationStarters, {
110
124
  isAgentDefault: agent.is_default,
111
125
  userDefinedConversationStarters: agent.user_defined_conversation_starters,
112
- onConversationStarterClick: function (conversationStarter) {
113
- throw new Error('Function not implemented.');
126
+ onConversationStarterClick: conversationStarter => {
127
+ onConversationStarter({
128
+ agentId: agent.id,
129
+ prompt: 'conversationStarter'
130
+ });
114
131
  }
115
132
  })), /*#__PURE__*/React.createElement(AgentActions, {
116
133
  isAgentCreatedByCurrentUser: isCreatedByViewingUser,
117
134
  onEditAgent: () => onEditAgent(agent.id),
118
135
  onCopyAgent: () => onCopyAgent(agent.id),
119
136
  onDuplicateAgent: () => onDuplicateAgent(agent.id),
120
- onDeleteAgent: function () {
121
- throw new Error('Function not implemented.');
122
- },
123
- onChatClick: () => onOpenChat === null || onOpenChat === void 0 ? void 0 : onOpenChat(agent.id)
137
+ onDeleteAgent: handleOnDelete,
138
+ onChatClick: () => onOpenChat ? onOpenChat(agent.id) : onOpenChatFullScreecn()
124
139
  })));
125
140
  };
126
141
  export default AgentProfileCard;
@@ -84,7 +84,8 @@ export const AgentProfileCardTrigger = ({
84
84
  isCreatedByViewingUser: (profileData === null || profileData === void 0 ? void 0 : (_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
85
85
  cloudId: props.cloudId,
86
86
  product: product,
87
- errorType: error
87
+ errorType: error,
88
+ onOpenChat: props.onOpenChat
88
89
  }));
89
90
  };
90
91
  return /*#__PURE__*/React.createElement(ProfileCardTrigger, _extends({}, props, {
@@ -0,0 +1,83 @@
1
+ import { useCallback } from 'react';
2
+ import { getATLContextUrl } from '@atlaskit/atlassian-context';
3
+ import { encodeParamsToUrl } from '../../../util/url';
4
+ export const firstCharUpper = str => str.charAt(0).toUpperCase() + str.slice(1);
5
+ const ROVO_PARAM_PREFIX = 'rovoChat';
6
+ const createRovoParams = params => {
7
+ const rovoParams = {};
8
+ Object.entries(params).forEach(([key, value]) => {
9
+ rovoParams[`${ROVO_PARAM_PREFIX}.${key}`] = encodeURIComponent(value);
10
+ rovoParams[`${ROVO_PARAM_PREFIX}${firstCharUpper(key)}`] = encodeURIComponent(value);
11
+ });
12
+ return rovoParams;
13
+ };
14
+ export const useAgentUrlActions = ({
15
+ cloudId
16
+ }) => {
17
+ const onEditAgent = useCallback(agentId => {
18
+ const url = `${getATLContextUrl('home')}/agents/${agentId}/edit`;
19
+ const urlWithParams = encodeParamsToUrl(url, {
20
+ cloudId,
21
+ ...createRovoParams({
22
+ cloudId
23
+ })
24
+ });
25
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
26
+ }, [cloudId]);
27
+ const onCopyAgent = useCallback(agentId => {
28
+ const baseUrl = `${getATLContextUrl('home')}/chat`;
29
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
30
+ cloudId,
31
+ ...createRovoParams({
32
+ cloudId,
33
+ agentId,
34
+ pathway: 'chat'
35
+ })
36
+ });
37
+ navigator.clipboard.writeText(urlWithParams);
38
+ }, [cloudId]);
39
+ const onDuplicateAgent = useCallback(agentId => {
40
+ const baseUrl = `${getATLContextUrl('home')}/chat/agents/new`;
41
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
42
+ cloudId,
43
+ ...createRovoParams({
44
+ cloudId,
45
+ agentId,
46
+ pathway: 'agents-create'
47
+ })
48
+ });
49
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
50
+ }, [cloudId]);
51
+ const onConversationStarter = ({
52
+ agentId,
53
+ prompt
54
+ }) => {
55
+ const baseUrl = `${getATLContextUrl('home')}/chat`;
56
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
57
+ cloudId,
58
+ ...createRovoParams({
59
+ cloudId,
60
+ agentId,
61
+ prompt
62
+ })
63
+ });
64
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
65
+ };
66
+ const onOpenChat = () => {
67
+ const baseUrl = `${getATLContextUrl('home')}/chat`;
68
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
69
+ cloudId,
70
+ ...createRovoParams({
71
+ cloudId
72
+ })
73
+ });
74
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
75
+ };
76
+ return {
77
+ onEditAgent,
78
+ onCopyAgent,
79
+ onDuplicateAgent,
80
+ onOpenChat,
81
+ onConversationStarter
82
+ };
83
+ };
@@ -0,0 +1,33 @@
1
+ import { useState } from 'react';
2
+ import { createHeaders } from '../../../util/rovoAgentUtils';
3
+ export const useDeleteAgent = ({
4
+ cloudId,
5
+ product
6
+ }) => {
7
+ const [isLoading, setIsLoading] = useState(false);
8
+ const [error, setError] = useState();
9
+ const deleteAgent = async agentId => {
10
+ if (!agentId || !cloudId) {
11
+ return;
12
+ }
13
+ setIsLoading(true);
14
+ try {
15
+ const headers = createHeaders(product, cloudId);
16
+ await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}`, {
17
+ method: 'DELETE',
18
+ credentials: 'include',
19
+ mode: 'cors',
20
+ headers
21
+ }));
22
+ setIsLoading(false);
23
+ } catch (error) {
24
+ setIsLoading(false);
25
+ setError(error);
26
+ }
27
+ };
28
+ return {
29
+ isLoading,
30
+ error,
31
+ deleteAgent
32
+ };
33
+ };
@@ -1,5 +1,5 @@
1
1
  import { useState } from 'react';
2
- import { createHeaders } from '../../util/rovoAgentUtils';
2
+ import { createHeaders } from '../../../util/rovoAgentUtils';
3
3
  export const useSetFavouriteAgent = ({
4
4
  agentId,
5
5
  cloudId,