@atlaskit/profilecard 19.18.1 → 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 (107) hide show
  1. package/CHANGELOG.md +25 -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/agent/package.json +14 -0
  6. package/dist/cjs/client/ProfileCardClient.js +2 -2
  7. package/dist/cjs/client/RovoAgentCardClient.js +10 -10
  8. package/dist/cjs/client/UserProfileCardClient.js +110 -16
  9. package/dist/cjs/client/getAgentInfo.js +4 -7
  10. package/dist/cjs/client/getTeamFromAGG.js +1 -1
  11. package/dist/cjs/components/Agent/Actions.js +20 -4
  12. package/dist/cjs/components/Agent/AgentDeleteConfirmationModal.js +104 -0
  13. package/dist/cjs/components/Agent/AgentProfileCard.js +74 -14
  14. package/dist/cjs/components/Agent/AgentProfileCardResourced.js +36 -12
  15. package/dist/cjs/components/Agent/AgentProfileCardTrigger.js +42 -16
  16. package/dist/cjs/components/Agent/hooks/useAgentActions.js +92 -0
  17. package/dist/cjs/components/Agent/hooks/useDeleteAgent.js +70 -0
  18. package/dist/cjs/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +23 -17
  19. package/dist/cjs/components/Agent/index.js +8 -0
  20. package/dist/cjs/components/User/ProfileCardTrigger.js +4 -2
  21. package/dist/cjs/components/common/ProfileCardTrigger.js +13 -5
  22. package/dist/cjs/mocks/simple-mock-clients.js +1 -1
  23. package/dist/cjs/util/analytics.js +19 -7
  24. package/dist/cjs/util/rovoAgentUtils.js +3 -3
  25. package/dist/cjs/util/useProfileInfo.js +11 -6
  26. package/dist/es2019/client/ProfileCardClient.js +2 -2
  27. package/dist/es2019/client/RovoAgentCardClient.js +11 -11
  28. package/dist/es2019/client/UserProfileCardClient.js +94 -6
  29. package/dist/es2019/client/getAgentInfo.js +5 -3
  30. package/dist/es2019/client/getTeamFromAGG.js +1 -1
  31. package/dist/es2019/components/Agent/Actions.js +16 -4
  32. package/dist/es2019/components/Agent/AgentDeleteConfirmationModal.js +82 -0
  33. package/dist/es2019/components/Agent/AgentProfileCard.js +56 -15
  34. package/dist/es2019/components/Agent/AgentProfileCardResourced.js +31 -10
  35. package/dist/es2019/components/Agent/AgentProfileCardTrigger.js +40 -17
  36. package/dist/es2019/components/Agent/hooks/useAgentActions.js +83 -0
  37. package/dist/es2019/components/Agent/hooks/useDeleteAgent.js +33 -0
  38. package/dist/es2019/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +6 -3
  39. package/dist/es2019/components/Agent/index.js +2 -0
  40. package/dist/es2019/components/User/ProfileCardTrigger.js +4 -2
  41. package/dist/es2019/components/common/ProfileCardTrigger.js +10 -3
  42. package/dist/es2019/mocks/simple-mock-clients.js +1 -1
  43. package/dist/es2019/util/analytics.js +23 -9
  44. package/dist/es2019/util/rovoAgentUtils.js +2 -2
  45. package/dist/es2019/util/useProfileInfo.js +3 -1
  46. package/dist/esm/client/ProfileCardClient.js +2 -2
  47. package/dist/esm/client/RovoAgentCardClient.js +11 -11
  48. package/dist/esm/client/UserProfileCardClient.js +111 -17
  49. package/dist/esm/client/getAgentInfo.js +4 -7
  50. package/dist/esm/client/getTeamFromAGG.js +1 -1
  51. package/dist/esm/components/Agent/Actions.js +20 -4
  52. package/dist/esm/components/Agent/AgentDeleteConfirmationModal.js +94 -0
  53. package/dist/esm/components/Agent/AgentProfileCard.js +71 -14
  54. package/dist/esm/components/Agent/AgentProfileCardResourced.js +36 -12
  55. package/dist/esm/components/Agent/AgentProfileCardTrigger.js +43 -17
  56. package/dist/esm/components/Agent/hooks/useAgentActions.js +85 -0
  57. package/dist/esm/components/Agent/hooks/useDeleteAgent.js +63 -0
  58. package/dist/esm/components/Agent/{useSetFavouriteAgent.js → hooks/useSetFavouriteAgent.js} +23 -17
  59. package/dist/esm/components/Agent/index.js +2 -0
  60. package/dist/esm/components/User/ProfileCardTrigger.js +4 -2
  61. package/dist/esm/components/common/ProfileCardTrigger.js +13 -5
  62. package/dist/esm/mocks/simple-mock-clients.js +1 -1
  63. package/dist/esm/util/analytics.js +19 -7
  64. package/dist/esm/util/rovoAgentUtils.js +2 -2
  65. package/dist/esm/util/useProfileInfo.js +11 -6
  66. package/dist/types/client/ProfileCardClient.d.ts +2 -2
  67. package/dist/types/client/RovoAgentCardClient.d.ts +3 -3
  68. package/dist/types/client/UserProfileCardClient.d.ts +7 -1
  69. package/dist/types/components/Agent/AgentDeleteConfirmationModal.d.ts +10 -0
  70. package/dist/types/components/Agent/AgentProfileCard.d.ts +4 -3
  71. package/dist/types/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  72. package/dist/types/components/Agent/{useAgentActions.d.ts → hooks/useAgentActions.d.ts} +6 -0
  73. package/dist/types/components/Agent/hooks/useDeleteAgent.d.ts +8 -0
  74. package/dist/types/components/Agent/{useSetFavouriteAgent.d.ts → hooks/useSetFavouriteAgent.d.ts} +2 -2
  75. package/dist/types/components/Agent/index.d.ts +2 -0
  76. package/dist/types/components/Agent/lazyAgentProfileCard.d.ts +3 -2
  77. package/dist/types/components/User/ProfileCardTrigger.d.ts +1 -1
  78. package/dist/types/components/common/ProfileCardTrigger.d.ts +1 -1
  79. package/dist/types/components/common/types.d.ts +6 -1
  80. package/dist/types/mocks/simple-mock-clients.d.ts +2 -2
  81. package/dist/types/types.d.ts +41 -3
  82. package/dist/types/util/analytics.d.ts +1 -1
  83. package/dist/types/util/rovoAgentUtils.d.ts +1 -0
  84. package/dist/types/util/useProfileInfo.d.ts +1 -0
  85. package/dist/types-ts4.5/client/ProfileCardClient.d.ts +2 -2
  86. package/dist/types-ts4.5/client/RovoAgentCardClient.d.ts +3 -3
  87. package/dist/types-ts4.5/client/UserProfileCardClient.d.ts +7 -1
  88. package/dist/types-ts4.5/components/Agent/AgentDeleteConfirmationModal.d.ts +10 -0
  89. package/dist/types-ts4.5/components/Agent/AgentProfileCard.d.ts +4 -3
  90. package/dist/types-ts4.5/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  91. package/dist/types-ts4.5/components/Agent/{useAgentActions.d.ts → hooks/useAgentActions.d.ts} +6 -0
  92. package/dist/types-ts4.5/components/Agent/hooks/useDeleteAgent.d.ts +8 -0
  93. package/dist/types-ts4.5/components/Agent/{useSetFavouriteAgent.d.ts → hooks/useSetFavouriteAgent.d.ts} +2 -2
  94. package/dist/types-ts4.5/components/Agent/index.d.ts +2 -0
  95. package/dist/types-ts4.5/components/Agent/lazyAgentProfileCard.d.ts +3 -2
  96. package/dist/types-ts4.5/components/User/ProfileCardTrigger.d.ts +1 -1
  97. package/dist/types-ts4.5/components/common/ProfileCardTrigger.d.ts +1 -1
  98. package/dist/types-ts4.5/components/common/types.d.ts +6 -1
  99. package/dist/types-ts4.5/mocks/simple-mock-clients.d.ts +2 -2
  100. package/dist/types-ts4.5/types.d.ts +41 -3
  101. package/dist/types-ts4.5/util/analytics.d.ts +1 -1
  102. package/dist/types-ts4.5/util/rovoAgentUtils.d.ts +1 -0
  103. package/dist/types-ts4.5/util/useProfileInfo.d.ts +1 -0
  104. package/package.json +8 -2
  105. package/dist/cjs/components/Agent/useAgentActions.js +0 -39
  106. package/dist/es2019/components/Agent/useAgentActions.js +0 -34
  107. package/dist/esm/components/Agent/useAgentActions.js +0 -33
@@ -1,12 +1,16 @@
1
- import React from 'react';
1
+ import React, { useCallback, useEffect } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
2
3
  import { Box, Stack, xcss } from '@atlaskit/primitives';
3
4
  import { AgentAvatar, AgentBanner, AgentProfileCreator, AgentProfileInfo, AgentStarCount } from '@atlaskit/rovo-agent-components';
5
+ import { fireEvent, profileCardRendered } from '../../util/analytics';
4
6
  import LoadingState from '../common/LoadingState';
7
+ import { ErrorMessage } from '../Error';
5
8
  import { AgentActions } from './Actions';
6
9
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
7
10
  import { ConversationStarters } from './ConversationStarters';
8
- import { useAgentUrlActions } from './useAgentActions';
9
- import { useSetFavouriteAgent } from './useSetFavouriteAgent';
11
+ import { useAgentUrlActions } from './hooks/useAgentActions';
12
+ import { useDeleteAgent } from './hooks/useDeleteAgent';
13
+ import { useSetFavouriteAgent } from './hooks/useSetFavouriteAgent';
10
14
  const styles = xcss({
11
15
  paddingBlockStart: 'space.400',
12
16
  paddingInline: 'space.200'
@@ -27,13 +31,17 @@ const AgentProfileCard = ({
27
31
  isCreatedByViewingUser,
28
32
  cloudId,
29
33
  onOpenChat,
30
- product = 'rovo'
34
+ product = 'rovo',
35
+ hasError,
36
+ errorType
31
37
  }) => {
32
38
  var _agent$creatorInfo, _agent$creatorInfo2, _agent$creatorInfo3, _agent$creatorInfo4;
33
39
  const {
34
40
  onEditAgent,
35
41
  onCopyAgent,
36
- onDuplicateAgent
42
+ onDuplicateAgent,
43
+ onOpenChat: onOpenChatFullScreecn,
44
+ onConversationStarter
37
45
  } = useAgentUrlActions({
38
46
  cloudId: cloudId || ''
39
47
  });
@@ -41,14 +49,45 @@ const AgentProfileCard = ({
41
49
  isStarred,
42
50
  setFavourite
43
51
  } = useSetFavouriteAgent({
44
- agentId: agent.id,
45
- cloudId: cloudId || '',
46
- isStarred: agent.favourite,
52
+ agentId: agent === null || agent === void 0 ? void 0 : agent.id,
53
+ cloudId: cloudId,
54
+ isStarred: !!(agent !== null && agent !== void 0 && agent.favourite),
47
55
  product
48
56
  });
57
+ const {
58
+ deleteAgent
59
+ } = useDeleteAgent({
60
+ cloudId,
61
+ product
62
+ });
63
+ const {
64
+ createAnalyticsEvent
65
+ } = useAnalyticsEvents();
66
+ const fireAnalytics = useCallback(payload => {
67
+ if (createAnalyticsEvent) {
68
+ fireEvent(createAnalyticsEvent, payload);
69
+ }
70
+ }, [createAnalyticsEvent]);
71
+ const handleOnDelete = async () => {
72
+ if (agent) {
73
+ await deleteAgent(agent.id);
74
+ }
75
+ };
76
+ useEffect(() => {
77
+ if (!isLoading && agent) {
78
+ fireAnalytics(profileCardRendered('agent', 'content'));
79
+ }
80
+ }, [agent, fireAnalytics, isLoading]);
49
81
  if (isLoading) {
50
82
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(LoadingState, {
51
- profileType: "agent"
83
+ profileType: "agent",
84
+ fireAnalytics: fireAnalytics
85
+ }));
86
+ }
87
+ if (hasError || !agent) {
88
+ return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
89
+ errorType: errorType,
90
+ fireAnalytics: fireAnalytics
52
91
  }));
53
92
  }
54
93
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(Box, {
@@ -66,6 +105,7 @@ const AgentProfileCard = ({
66
105
  agentName: agent.name,
67
106
  isStarred: isStarred,
68
107
  onStarToggle: setFavourite,
108
+ isHidden: agent.visibility === 'PRIVATE',
69
109
  creatorRender: ((_agent$creatorInfo = agent.creatorInfo) === null || _agent$creatorInfo === void 0 ? void 0 : _agent$creatorInfo.type) && /*#__PURE__*/React.createElement(AgentProfileCreator, {
70
110
  creator: {
71
111
  type: (_agent$creatorInfo2 = agent.creatorInfo) === null || _agent$creatorInfo2 === void 0 ? void 0 : _agent$creatorInfo2.type,
@@ -83,18 +123,19 @@ const AgentProfileCard = ({
83
123
  }), /*#__PURE__*/React.createElement(ConversationStarters, {
84
124
  isAgentDefault: agent.is_default,
85
125
  userDefinedConversationStarters: agent.user_defined_conversation_starters,
86
- onConversationStarterClick: function (conversationStarter) {
87
- throw new Error('Function not implemented.');
126
+ onConversationStarterClick: conversationStarter => {
127
+ onConversationStarter({
128
+ agentId: agent.id,
129
+ prompt: 'conversationStarter'
130
+ });
88
131
  }
89
132
  })), /*#__PURE__*/React.createElement(AgentActions, {
90
133
  isAgentCreatedByCurrentUser: isCreatedByViewingUser,
91
134
  onEditAgent: () => onEditAgent(agent.id),
92
135
  onCopyAgent: () => onCopyAgent(agent.id),
93
136
  onDuplicateAgent: () => onDuplicateAgent(agent.id),
94
- onDeleteAgent: function () {
95
- throw new Error('Function not implemented.');
96
- },
97
- onChatClick: () => onOpenChat === null || onOpenChat === void 0 ? void 0 : onOpenChat(agent.id)
137
+ onDeleteAgent: handleOnDelete,
138
+ onChatClick: () => onOpenChat ? onOpenChat(agent.id) : onOpenChatFullScreecn()
98
139
  })));
99
140
  };
100
141
  export default AgentProfileCard;
@@ -1,4 +1,6 @@
1
1
  import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
+ import { fireEvent } from '../../util/analytics';
2
4
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
3
5
  import ErrorMessage from '../Error/ErrorMessage';
4
6
  import { AgentProfileCardWrapper } from './AgentProfileCardWrapper';
@@ -7,6 +9,14 @@ export const AgentProfileCardResourced = props => {
7
9
  const [agentData, setAgentData] = useState();
8
10
  const [isLoading, setIsLoading] = useState(false);
9
11
  const [error, setError] = useState();
12
+ const {
13
+ createAnalyticsEvent
14
+ } = useAnalyticsEvents();
15
+ const fireAnalytics = useCallback(payload => {
16
+ if (createAnalyticsEvent) {
17
+ fireEvent(createAnalyticsEvent, payload);
18
+ }
19
+ }, [createAnalyticsEvent]);
10
20
  const creatorUserId = useMemo(() => (agentData === null || agentData === void 0 ? void 0 : agentData.creator_type) === 'CUSTOMER' && agentData.creator ? getAAIDFromARI(agentData.creator) : '', [agentData === null || agentData === void 0 ? void 0 : agentData.creator_type, agentData === null || agentData === void 0 ? void 0 : agentData.creator]);
11
21
  const getCreator = useCallback(async (creator_type, creator) => {
12
22
  if (!creator) {
@@ -23,19 +33,30 @@ export const AgentProfileCardResourced = props => {
23
33
  name: creator !== null && creator !== void 0 ? creator : ''
24
34
  };
25
35
  case 'CUSTOMER':
26
- const creatorInfo = await props.resourceClient.getProfile(creatorUserId || '', props.cloudId || '');
27
- return {
28
- type: 'CUSTOMER',
29
- name: creatorInfo.fullName,
30
- profileLink: `/people/${creatorUserId}`
31
- };
36
+ try {
37
+ if (!creatorUserId || !props.cloudId) {
38
+ return undefined;
39
+ }
40
+ const creatorInfo = await props.resourceClient.getProfile(creatorUserId, props.cloudId, fireAnalytics);
41
+ return {
42
+ type: 'CUSTOMER',
43
+ name: creatorInfo.fullName,
44
+ profileLink: `/people/${creatorUserId}`,
45
+ id: creatorUserId
46
+ };
47
+ } catch (error) {
48
+ return undefined;
49
+ }
32
50
  default:
33
51
  return undefined;
34
52
  }
35
- }, [creatorUserId, props.cloudId, props.resourceClient]);
53
+ }, [creatorUserId, fireAnalytics, props.cloudId, props.resourceClient]);
36
54
  const getAgentInfo = useCallback(() => {
37
- return props.resourceClient.getRovoAgentProfile(props.agentId);
38
- }, [props.agentId, props.resourceClient]);
55
+ return props.resourceClient.getRovoAgentProfile({
56
+ type: 'identity',
57
+ value: props.accountId
58
+ }, fireAnalytics);
59
+ }, [fireAnalytics, props.accountId, props.resourceClient]);
39
60
  const fetchData = useCallback(async () => {
40
61
  setIsLoading(true);
41
62
  const getAgentData = async () => {
@@ -57,7 +78,7 @@ export const AgentProfileCardResourced = props => {
57
78
  setIsLoading(false);
58
79
  setError(error);
59
80
  }
60
- }, [fetchData, getAgentInfo, getCreator, props.agentId, props.cloudId, props.resourceClient]);
81
+ }, [fetchData, getAgentInfo, getCreator, props.accountId, props.cloudId, props.resourceClient]);
61
82
  if (error || !isLoading && !agentData) {
62
83
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
63
84
  reload: () => {
@@ -1,5 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { Suspense } from 'react';
2
+ import React, { Suspense, useCallback } from 'react';
3
+ import { useAnalyticsEvents } from '@atlaskit/analytics-next';
4
+ import { fireEvent } from '../../util/analytics';
3
5
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
4
6
  import ProfileCardTrigger from '../common/ProfileCardTrigger';
5
7
  import { AgentProfileCardLazy } from './lazyAgentProfileCard';
@@ -14,6 +16,14 @@ export const AgentProfileCardTrigger = ({
14
16
  userId,
15
17
  cloudId
16
18
  } = props;
19
+ const {
20
+ createAnalyticsEvent
21
+ } = useAnalyticsEvents();
22
+ const fireAnalytics = useCallback(payload => {
23
+ if (createAnalyticsEvent) {
24
+ fireEvent(createAnalyticsEvent, payload);
25
+ }
26
+ }, [createAnalyticsEvent]);
17
27
  const getCreator = async (creator_type, creator) => {
18
28
  if (!creator) {
19
29
  return undefined;
@@ -30,19 +40,29 @@ export const AgentProfileCardTrigger = ({
30
40
  };
31
41
  case 'CUSTOMER':
32
42
  const userId = getAAIDFromARI(creator) || '';
33
- const creatorInfo = await props.resourceClient.getProfile(userId, cloudId || '');
34
- return {
35
- type: 'CUSTOMER',
36
- name: creatorInfo.fullName,
37
- profileLink: `/people/${userId}`,
38
- id: userId
39
- };
43
+ try {
44
+ if (!userId || !cloudId) {
45
+ return undefined;
46
+ }
47
+ const creatorInfo = await props.resourceClient.getProfile(cloudId, userId, fireAnalytics);
48
+ return {
49
+ type: 'CUSTOMER',
50
+ name: creatorInfo.fullName,
51
+ profileLink: `/people/${userId}`,
52
+ id: userId
53
+ };
54
+ } catch (error) {
55
+ return undefined;
56
+ }
40
57
  default:
41
58
  return undefined;
42
59
  }
43
60
  };
44
61
  const fetchAgentProfile = async () => {
45
- const agentInfo = await resourceClient.getRovoAgentProfile(userId);
62
+ const agentInfo = await resourceClient.getRovoAgentProfile({
63
+ type: 'agent',
64
+ value: userId
65
+ }, fireAnalytics);
46
66
  const agentCreatorInfo = await getCreator(agentInfo.creator_type, agentInfo.creator || undefined);
47
67
  return {
48
68
  ...agentInfo,
@@ -51,25 +71,28 @@ export const AgentProfileCardTrigger = ({
51
71
  };
52
72
  const renderProfileCard = ({
53
73
  profileData,
54
- isLoading
74
+ isLoading,
75
+ error
55
76
  }) => {
56
77
  var _profileData$creatorI;
57
- if (!profileData) {
58
- return /*#__PURE__*/React.createElement(React.Fragment, null);
59
- }
60
78
  return /*#__PURE__*/React.createElement(Suspense, {
61
79
  fallback: null
62
80
  }, /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
63
81
  agent: profileData,
64
82
  isLoading: isLoading,
65
- isCreatedByViewingUser: ((_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
83
+ hasError: !!error,
84
+ isCreatedByViewingUser: (profileData === null || profileData === void 0 ? void 0 : (_profileData$creatorI = profileData.creatorInfo) === null || _profileData$creatorI === void 0 ? void 0 : _profileData$creatorI.id) === viewingUserId,
66
85
  cloudId: props.cloudId,
67
- product: product
86
+ product: product,
87
+ errorType: error,
88
+ onOpenChat: props.onOpenChat
68
89
  }));
69
90
  };
70
91
  return /*#__PURE__*/React.createElement(ProfileCardTrigger, _extends({}, props, {
92
+ trigger: "hover",
71
93
  renderProfileCard: renderProfileCard,
72
- trigger: trigger,
73
- fetchProfile: fetchAgentProfile
94
+ fetchProfile: fetchAgentProfile,
95
+ fireAnalytics: fireAnalytics,
96
+ profileCardType: "agent"
74
97
  }));
75
98
  };
@@ -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,
@@ -9,11 +9,14 @@ export const useSetFavouriteAgent = ({
9
9
  const [isLoading, setIsLoading] = useState(false);
10
10
  const [isFavourite, setIsFavourite] = useState(isStarred);
11
11
  const setFavourite = async () => {
12
+ if (!agentId || !cloudId) {
13
+ return;
14
+ }
12
15
  setIsLoading(true);
13
16
  try {
14
17
  const headers = createHeaders(product, cloudId);
15
18
  if (isFavourite) {
16
- await fetch(new Request(`/agents/v1/${agentId}/favourite`, {
19
+ await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}/favourite`, {
17
20
  method: 'POST',
18
21
  credentials: 'include',
19
22
  mode: 'cors',
@@ -22,7 +25,7 @@ export const useSetFavouriteAgent = ({
22
25
  setIsFavourite(true);
23
26
  });
24
27
  } else {
25
- await fetch(new Request(`/agents/v1/${agentId}/favourite`, {
28
+ await fetch(new Request(`/gateway/api/assist/agents/v1/${agentId}/favourite`, {
26
29
  method: 'DELETE',
27
30
  credentials: 'include',
28
31
  mode: 'cors',
@@ -0,0 +1,2 @@
1
+ import { AgentProfileCardTrigger } from './AgentProfileCardTrigger';
2
+ export default AgentProfileCardTrigger;
@@ -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,
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import Popup from '@atlaskit/popup';
4
4
  import { layers } from '@atlaskit/theme/constants';
5
+ import { cardTriggered } from '../../util/analytics';
5
6
  import { useProfileInfo } from '../../util/useProfileInfo';
6
7
  import { PopupTrigger } from './PopupTrigger';
7
8
  const DELAY_MS_SHOW = 800;
@@ -13,6 +14,8 @@ function ProfileCardTrigger({
13
14
  renderProfileCard,
14
15
  fetchProfile,
15
16
  disabledAriaAttributes,
17
+ profileCardType,
18
+ fireAnalytics,
16
19
  ...popupProps
17
20
  }) {
18
21
  var _popupProps$autoFocus;
@@ -24,7 +27,7 @@ function ProfileCardTrigger({
24
27
  const {
25
28
  profileData,
26
29
  isLoading,
27
- // hasError: Boolean(error) || cannotLoadUser,
30
+ error,
28
31
  getProfileData
29
32
  } = useProfileInfo({
30
33
  fetchUserProfile: fetchProfile
@@ -49,9 +52,12 @@ function ProfileCardTrigger({
49
52
  if (!visible) {
50
53
  await (getProfileData === null || getProfileData === void 0 ? void 0 : getProfileData());
51
54
  setVisible(true);
55
+ if (fireAnalytics) {
56
+ fireAnalytics(cardTriggered(profileCardType, trigger));
57
+ }
52
58
  }
53
59
  }, showDelay);
54
- }, [showDelay, visible, getProfileData]);
60
+ }, [showDelay, visible, getProfileData, fireAnalytics, profileCardType, trigger]);
55
61
  const onMouseEnter = useCallback(() => {
56
62
  showProfilecard();
57
63
  }, [showProfilecard]);
@@ -83,7 +89,8 @@ function ProfileCardTrigger({
83
89
  onFocus: showProfilecard
84
90
  }, renderProfileCard({
85
91
  profileData,
86
- isLoading
92
+ isLoading,
93
+ error
87
94
  }))
88
95
  }));
89
96
  }
@@ -31,7 +31,7 @@ class SimpleMockUserClient extends UserProfileCardClient {
31
31
  }
32
32
  }
33
33
  class SimpleMockAgentClient extends RovoAgentCardClient {
34
- makeRequest(userId) {
34
+ makeRequest(id, cloudId) {
35
35
  return Promise.resolve(agentData);
36
36
  }
37
37
  }
@@ -24,7 +24,7 @@ export const fireEvent = (createAnalyticsEvent, body) => {
24
24
 
25
25
  const TEAM_SUBJECT = 'teamProfileCard';
26
26
  const USER_SUBJECT = 'profilecard';
27
- const RovoAgent = 'rovoAgenrProfilecard';
27
+ const AGENT_SUBJECT = 'rovoAgenrProfilecard';
28
28
  const createEvent = (eventType, action, actionSubject, actionSubjectId, attributes = {}) => ({
29
29
  eventType,
30
30
  action,
@@ -32,21 +32,35 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
32
32
  actionSubjectId,
33
33
  attributes: {
34
34
  packageName: "@atlaskit/profilecard",
35
- packageVersion: "19.18.1",
35
+ packageVersion: "19.20.0",
36
36
  ...attributes,
37
37
  firedAt: Math.round(getPageTime())
38
38
  }
39
39
  });
40
- export const cardTriggered = (type, method) => createEvent('ui', 'triggered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, undefined, {
41
- method
42
- });
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
+ };
52
+ export const cardTriggered = (type, method) => {
53
+ return createEvent('ui', 'triggered', getActionSubject(type), undefined, {
54
+ method
55
+ });
56
+ };
43
57
  export const teamRequestAnalytics = (action, attributes) => createEvent('operational', action, TEAM_SUBJECT, 'request', attributes);
44
58
  export const userRequestAnalytics = (action, attributes) => createEvent('operational', action, USER_SUBJECT, 'request', attributes);
45
- export const profileCardRendered = (type, actionSubjectId, attributes) => createEvent('ui', 'rendered', type === 'user' ? USER_SUBJECT : TEAM_SUBJECT, actionSubjectId, attributes);
46
- 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);
47
61
  export const reportingLinesClicked = attributes => createEvent('ui', 'clicked', USER_SUBJECT, 'reportingLines', attributes);
48
- 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);
49
63
  export const teamAvatarClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'avatar', attributes);
50
64
  export const moreMembersClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'moreMembers', attributes);
51
65
  export const errorRetryClicked = attributes => createEvent('ui', 'clicked', TEAM_SUBJECT, 'errorRetry', attributes);
52
- export const agentRequestAnalytics = (action, attributes) => createEvent('operational', action, RovoAgent, 'request', attributes);
66
+ export const agentRequestAnalytics = (action, attributes) => createEvent('operational', action, AGENT_SUBJECT, 'request', attributes);
@@ -1,3 +1,4 @@
1
+ export const USER_ARI_PREFIX = 'ari:cloud:identity::user/';
1
2
  export const createHeaders = (product, cloudId) => {
2
3
  const config = {
3
4
  headers: {
@@ -11,6 +12,5 @@ export const createHeaders = (product, cloudId) => {
11
12
  });
12
13
  };
13
14
  export const getAAIDFromARI = ari => {
14
- const matched = ari.match(/\/([a-zA-Z0-9_\|\-\:]{1,128})$/);
15
- return matched ? matched[1] : undefined;
15
+ return ari.replace(USER_ARI_PREFIX, '');
16
16
  };
@@ -3,6 +3,7 @@ export const useProfileInfo = ({
3
3
  fetchUserProfile
4
4
  }) => {
5
5
  const [isLoading, setIsLoading] = useState(false);
6
+ const [error, setError] = useState(null);
6
7
  const [profileData, setProfileData] = useState();
7
8
  const getProfileData = async () => {
8
9
  setIsLoading(true);
@@ -11,13 +12,14 @@ export const useProfileInfo = ({
11
12
  setProfileData(profileData);
12
13
  setIsLoading(false);
13
14
  } catch (error) {
15
+ setError(error);
14
16
  setIsLoading(true);
15
17
  }
16
18
  };
17
19
  return {
18
20
  profileData,
19
21
  isLoading,
20
- // hasError: Boolean(error) || cannotLoadUser,
22
+ error,
21
23
  getProfileData
22
24
  };
23
25
  };
@@ -60,9 +60,9 @@ var ProfileCardClient = /*#__PURE__*/function () {
60
60
  }
61
61
  }, {
62
62
  key: "getRovoAgentProfile",
63
- value: function getRovoAgentProfile(agentId, analytics) {
63
+ value: function getRovoAgentProfile(id, analytics) {
64
64
  var _this$rovoAgentClient2;
65
- return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(agentId, analytics);
65
+ return (_this$rovoAgentClient2 = this.rovoAgentClient) === null || _this$rovoAgentClient2 === void 0 ? void 0 : _this$rovoAgentClient2.getProfile(id, analytics);
66
66
  }
67
67
  }]);
68
68
  return ProfileCardClient;