@atlaskit/profilecard 20.10.0 → 20.12.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 (27) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/afm-jira/tsconfig.json +3 -0
  4. package/afm-post-office/tsconfig.json +4 -1
  5. package/dist/cjs/client/getOrgIdForCloudIdFromAGG.js +1 -1
  6. package/dist/cjs/client/getTeamFromAGG.js +1 -1
  7. package/dist/cjs/components/Agent/AgentProfileCard.js +1 -1
  8. package/dist/cjs/components/Agent/AgentProfileCardResourced.js +47 -67
  9. package/dist/cjs/components/Agent/hooks/useAgentActions.js +66 -19
  10. package/dist/cjs/util/analytics.js +1 -1
  11. package/dist/es2019/client/getOrgIdForCloudIdFromAGG.js +1 -1
  12. package/dist/es2019/client/getTeamFromAGG.js +1 -1
  13. package/dist/es2019/components/Agent/AgentProfileCard.js +1 -1
  14. package/dist/es2019/components/Agent/AgentProfileCardResourced.js +29 -37
  15. package/dist/es2019/components/Agent/hooks/useAgentActions.js +67 -19
  16. package/dist/es2019/util/analytics.js +1 -1
  17. package/dist/esm/client/getOrgIdForCloudIdFromAGG.js +1 -1
  18. package/dist/esm/client/getTeamFromAGG.js +1 -1
  19. package/dist/esm/components/Agent/AgentProfileCard.js +1 -1
  20. package/dist/esm/components/Agent/AgentProfileCardResourced.js +48 -68
  21. package/dist/esm/components/Agent/hooks/useAgentActions.js +66 -19
  22. package/dist/esm/util/analytics.js +1 -1
  23. package/dist/types/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  24. package/dist/types/components/Agent/hooks/useAgentActions.d.ts +1 -1
  25. package/dist/types-ts4.5/components/Agent/AgentProfileCardResourced.d.ts +1 -1
  26. package/dist/types-ts4.5/components/Agent/hooks/useAgentActions.d.ts +1 -1
  27. package/package.json +7 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @atlaskit/profilecard
2
2
 
3
+ ## 20.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#162951](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/162951)
8
+ [`17d7f44be2959`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/17d7f44be2959) -
9
+ Agent profile card to use publishWithPostMessage, so `Chat to agent` or conversation starter
10
+ button will open in rovo sidebar if available
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies
15
+
16
+ ## 20.11.0
17
+
18
+ ### Minor Changes
19
+
20
+ - [#163611](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/163611)
21
+ [`559a5e24a2892`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/559a5e24a2892) -
22
+ Fix asynchronous loading of agent profile card
23
+
3
24
  ## 20.10.0
4
25
 
5
26
  ### Minor Changes
@@ -68,6 +68,9 @@
68
68
  {
69
69
  "path": "../../../ai-mate/rovo-agent-components/afm-cc/tsconfig.json"
70
70
  },
71
+ {
72
+ "path": "../../../ai-mate/rovo-triggers/afm-cc/tsconfig.json"
73
+ },
71
74
  {
72
75
  "path": "../../../design-system/spinner/afm-cc/tsconfig.json"
73
76
  },
@@ -68,6 +68,9 @@
68
68
  {
69
69
  "path": "../../../ai-mate/rovo-agent-components/afm-jira/tsconfig.json"
70
70
  },
71
+ {
72
+ "path": "../../../ai-mate/rovo-triggers/afm-jira/tsconfig.json"
73
+ },
71
74
  {
72
75
  "path": "../../../design-system/spinner/afm-jira/tsconfig.json"
73
76
  },
@@ -3,7 +3,7 @@
3
3
  "compilerOptions": {
4
4
  "declaration": true,
5
5
  "target": "es5",
6
- "outDir": "../../../../../tsDist/@atlaskit__profilecard/app",
6
+ "outDir": "../../../../../post-office/tsDist/@atlaskit__profilecard/app",
7
7
  "rootDir": "../",
8
8
  "composite": true
9
9
  },
@@ -68,6 +68,9 @@
68
68
  {
69
69
  "path": "../../../ai-mate/rovo-agent-components/afm-post-office/tsconfig.json"
70
70
  },
71
+ {
72
+ "path": "../../../ai-mate/rovo-triggers/afm-post-office/tsconfig.json"
73
+ },
71
74
  {
72
75
  "path": "../../../design-system/spinner/afm-post-office/tsconfig.json"
73
76
  },
@@ -11,7 +11,7 @@ var _graphqlUtils = require("./graphqlUtils");
11
11
  var ORG_ID_FROM_CLOUD_ID_QUERY = "query OrgIdFromCloudId($cloudId: ID!) {\n\ttenantContexts(cloudIds: [$cloudId]) {\n\t\torgId\n\t}\n}";
12
12
  var addHeaders = function addHeaders(headers) {
13
13
  headers.append('atl-client-name', "@atlaskit/profilecard");
14
- headers.append('atl-client-version', "20.10.0");
14
+ headers.append('atl-client-version', "20.12.0");
15
15
  return headers;
16
16
  };
17
17
  function getOrgIdForCloudIdFromAGG(_x, _x2) {
@@ -57,7 +57,7 @@ var addHeaders = exports.addHeaders = function addHeaders(headers) {
57
57
  headers.append('X-ExperimentalApi', 'teams-beta');
58
58
  headers.append('X-ExperimentalApi', 'team-members-beta');
59
59
  headers.append('atl-client-name', "@atlaskit/profilecard");
60
- headers.append('atl-client-version', "20.10.0");
60
+ headers.append('atl-client-version', "20.12.0");
61
61
  return headers;
62
62
  };
63
63
  function getTeamFromAGG(_x, _x2, _x3) {
@@ -232,7 +232,7 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
232
232
  },
233
233
  onDeleteAgent: handleOnDelete,
234
234
  onChatClick: function onChatClick() {
235
- return _onChatClick ? _onChatClick() : onOpenChatFullScreen(agent.id);
235
+ return _onChatClick ? _onChatClick() : onOpenChatFullScreen(agent.id, agent.name);
236
236
  },
237
237
  resourceClient: resourceClient,
238
238
  onViewFullProfileClick: function onViewFullProfileClick() {
@@ -102,65 +102,46 @@ var AgentProfileCardResourced = exports.AgentProfileCardResourced = function Age
102
102
  return _ref.apply(this, arguments);
103
103
  };
104
104
  }(), [creatorUserId, fireAnalytics, props.cloudId, props.resourceClient]);
105
- var getAgentInfo = (0, _react.useCallback)(function () {
106
- return props.resourceClient.getRovoAgentProfile({
107
- type: 'identity',
108
- value: props.accountId
109
- }, fireAnalytics);
110
- }, [fireAnalytics, props.accountId, props.resourceClient]);
111
- var fetchData = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
112
- var getAgentData, agentData;
113
- return _regenerator.default.wrap(function _callee3$(_context3) {
114
- while (1) switch (_context3.prev = _context3.next) {
105
+ var fetchData = (0, _react.useCallback)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
106
+ var profileData, agentCreatorInfo;
107
+ return _regenerator.default.wrap(function _callee2$(_context2) {
108
+ while (1) switch (_context2.prev = _context2.next) {
115
109
  case 0:
116
110
  setIsLoading(true);
117
- getAgentData = /*#__PURE__*/function () {
118
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
119
- var profileData, agentCreatorInfo;
120
- return _regenerator.default.wrap(function _callee2$(_context2) {
121
- while (1) switch (_context2.prev = _context2.next) {
122
- case 0:
123
- _context2.next = 2;
124
- return getAgentInfo();
125
- case 2:
126
- profileData = _context2.sent;
127
- _context2.next = 5;
128
- return getCreator(profileData === null || profileData === void 0 ? void 0 : profileData.creator_type, (profileData === null || profileData === void 0 ? void 0 : profileData.creator) || undefined);
129
- case 5:
130
- agentCreatorInfo = _context2.sent;
131
- return _context2.abrupt("return", _objectSpread(_objectSpread({}, profileData), {}, {
132
- creatorInfo: agentCreatorInfo
133
- }));
134
- case 7:
135
- case "end":
136
- return _context2.stop();
137
- }
138
- }, _callee2);
139
- }));
140
- return function getAgentData() {
141
- return _ref3.apply(this, arguments);
142
- };
143
- }();
144
- _context3.next = 4;
145
- return getAgentData();
111
+ _context2.prev = 1;
112
+ _context2.next = 4;
113
+ return props.resourceClient.getRovoAgentProfile({
114
+ type: 'identity',
115
+ value: props.accountId
116
+ }, fireAnalytics);
146
117
  case 4:
147
- agentData = _context3.sent;
148
- setAgentData(agentData);
149
- setIsLoading(false);
118
+ profileData = _context2.sent;
119
+ _context2.next = 7;
120
+ return getCreator(profileData === null || profileData === void 0 ? void 0 : profileData.creator_type, (profileData === null || profileData === void 0 ? void 0 : profileData.creator) || undefined);
150
121
  case 7:
122
+ agentCreatorInfo = _context2.sent;
123
+ setAgentData(_objectSpread(_objectSpread({}, profileData), {}, {
124
+ creatorInfo: agentCreatorInfo
125
+ }));
126
+ _context2.next = 14;
127
+ break;
128
+ case 11:
129
+ _context2.prev = 11;
130
+ _context2.t0 = _context2["catch"](1);
131
+ setError(_context2.t0);
132
+ case 14:
133
+ _context2.prev = 14;
134
+ setIsLoading(false);
135
+ return _context2.finish(14);
136
+ case 17:
151
137
  case "end":
152
- return _context3.stop();
138
+ return _context2.stop();
153
139
  }
154
- }, _callee3);
155
- })), [getAgentInfo, getCreator]);
140
+ }, _callee2, null, [[1, 11, 14, 17]]);
141
+ })), [fireAnalytics, getCreator, props.accountId, props.resourceClient]);
156
142
  (0, _react.useEffect)(function () {
157
- try {
158
- fetchData();
159
- } catch (error) {
160
- setIsLoading(false);
161
- setError(error);
162
- }
163
- }, [fetchData, getAgentInfo, getCreator, props.accountId, props.cloudId, props.resourceClient]);
143
+ fetchData();
144
+ }, [fetchData]);
164
145
  if (error || !isLoading && !agentData) {
165
146
  return /*#__PURE__*/_react.default.createElement(_AgentProfileCardWrapper.AgentProfileCardWrapper, null, /*#__PURE__*/_react.default.createElement(_ErrorMessage.default, {
166
147
  reload: function reload() {
@@ -170,19 +151,18 @@ var AgentProfileCardResourced = exports.AgentProfileCardResourced = function Age
170
151
  fireAnalytics: function fireAnalytics() {}
171
152
  }));
172
153
  }
173
- if (agentData) {
174
- return /*#__PURE__*/_react.default.createElement(_lazyAgentProfileCard.AgentProfileCardLazy, {
175
- agent: agentData,
176
- isLoading: isLoading,
177
- hasError: !!error,
178
- isCreatedByViewingUser: creatorUserId === props.viewingUserId,
179
- product: props.product,
180
- onConversationStartersClick: props.onConversationStartersClick,
181
- onChatClick: props.onChatClick,
182
- addFlag: props.addFlag,
183
- resourceClient: props.resourceClient,
184
- cloudId: props.cloudId
185
- });
186
- }
187
- return null;
154
+ return /*#__PURE__*/_react.default.createElement(_react.Suspense, {
155
+ fallback: null
156
+ }, /*#__PURE__*/_react.default.createElement(_lazyAgentProfileCard.AgentProfileCardLazy, {
157
+ agent: agentData,
158
+ isLoading: isLoading,
159
+ hasError: !!error,
160
+ isCreatedByViewingUser: creatorUserId === props.viewingUserId,
161
+ product: props.product,
162
+ onConversationStartersClick: props.onConversationStartersClick,
163
+ onChatClick: props.onChatClick,
164
+ addFlag: props.addFlag,
165
+ resourceClient: props.resourceClient,
166
+ cloudId: props.cloudId
167
+ }));
188
168
  };
@@ -9,6 +9,8 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _react = require("react");
11
11
  var _atlassianContext = require("@atlaskit/atlassian-context");
12
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
13
+ var _rovoTriggers = require("@atlaskit/rovo-triggers");
12
14
  var _url = require("../../../util/url");
13
15
  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; }
14
16
  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) { (0, _defineProperty2.default)(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; }
@@ -28,6 +30,8 @@ var createRovoParams = function createRovoParams(params) {
28
30
  };
29
31
  var useAgentUrlActions = exports.useAgentUrlActions = function useAgentUrlActions(_ref3) {
30
32
  var cloudId = _ref3.cloudId;
33
+ var _useRovoPostMessageTo = (0, _rovoTriggers.useRovoPostMessageToPubsub)(),
34
+ publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage;
31
35
  var onEditAgent = (0, _react.useCallback)(function (agentId) {
32
36
  var url = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat/agents/").concat(agentId, "/edit");
33
37
  var urlWithParams = (0, _url.encodeParamsToUrl)(url, _objectSpread({
@@ -54,26 +58,69 @@ var useAgentUrlActions = exports.useAgentUrlActions = function useAgentUrlAction
54
58
  var onConversationStarter = function onConversationStarter(_ref4) {
55
59
  var agentId = _ref4.agentId,
56
60
  prompt = _ref4.prompt;
57
- var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
58
- var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
59
- cloudId: cloudId
60
- }, createRovoParams({
61
- cloudId: cloudId,
62
- agentId: agentId,
63
- prompt: prompt,
64
- pathway: 'chat'
65
- })));
66
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
61
+ var startConversationInNewTab = function startConversationInNewTab() {
62
+ var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
63
+ var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
64
+ cloudId: cloudId
65
+ }, createRovoParams({
66
+ cloudId: cloudId,
67
+ agentId: agentId,
68
+ prompt: prompt,
69
+ pathway: 'chat'
70
+ })));
71
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
72
+ };
73
+ if ((0, _platformFeatureFlags.fg)('rovo_profile_card_open_chat_sidebar')) {
74
+ publishWithPostMessage({
75
+ targetWindow: window,
76
+ payload: {
77
+ type: 'chat-new',
78
+ source: 'AgentProfileCard',
79
+ data: {
80
+ name: prompt.slice(0, 50),
81
+ prompt: prompt,
82
+ agentId: agentId,
83
+ dialogues: []
84
+ }
85
+ },
86
+ onAcknowledgeTimeout: function onAcknowledgeTimeout() {
87
+ startConversationInNewTab();
88
+ }
89
+ });
90
+ } else {
91
+ startConversationInNewTab();
92
+ }
67
93
  };
68
- var onOpenChat = function onOpenChat(agentId) {
69
- var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
70
- var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
71
- cloudId: cloudId
72
- }, createRovoParams({
73
- cloudId: cloudId,
74
- agentId: agentId
75
- })));
76
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
94
+ var onOpenChat = function onOpenChat(agentId, agentName) {
95
+ var openChatInNewTab = function openChatInNewTab() {
96
+ var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
97
+ var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
98
+ cloudId: cloudId
99
+ }, createRovoParams({
100
+ cloudId: cloudId,
101
+ agentId: agentId
102
+ })));
103
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
104
+ };
105
+ if ((0, _platformFeatureFlags.fg)('rovo_profile_card_open_chat_sidebar')) {
106
+ publishWithPostMessage({
107
+ targetWindow: window,
108
+ payload: {
109
+ type: 'chat-new',
110
+ source: 'AgentProfileCard',
111
+ data: {
112
+ agentId: agentId,
113
+ dialogues: [],
114
+ name: "Chat with ".concat(agentName)
115
+ }
116
+ },
117
+ onAcknowledgeTimeout: function onAcknowledgeTimeout() {
118
+ openChatInNewTab();
119
+ }
120
+ });
121
+ } else {
122
+ openChatInNewTab();
123
+ }
77
124
  };
78
125
  var onViewFullProfile = function onViewFullProfile(agentId) {
79
126
  window.open("".concat(window.location.origin, "/people/agent/").concat(agentId), '_blank', 'noopener, noreferrer');
@@ -45,7 +45,7 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
45
45
  actionSubjectId: actionSubjectId,
46
46
  attributes: _objectSpread(_objectSpread({
47
47
  packageName: "@atlaskit/profilecard",
48
- packageVersion: "20.10.0"
48
+ packageVersion: "20.12.0"
49
49
  }, attributes), {}, {
50
50
  firedAt: Math.round((0, _performance.getPageTime)())
51
51
  })
@@ -6,7 +6,7 @@ const ORG_ID_FROM_CLOUD_ID_QUERY = `query OrgIdFromCloudId($cloudId: ID!) {
6
6
  }`;
7
7
  const addHeaders = headers => {
8
8
  headers.append('atl-client-name', "@atlaskit/profilecard");
9
- headers.append('atl-client-version', "20.10.0");
9
+ headers.append('atl-client-version', "20.12.0");
10
10
  return headers;
11
11
  };
12
12
  export async function getOrgIdForCloudIdFromAGG(url, cloudId) {
@@ -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', "20.10.0");
70
+ headers.append('atl-client-version', "20.12.0");
71
71
  return headers;
72
72
  };
73
73
  export async function getTeamFromAGG(url, teamId, siteId) {
@@ -178,7 +178,7 @@ const AgentProfileCard = ({
178
178
  onCopyAgent: () => onCopyAgent(agent.id),
179
179
  onDuplicateAgent: () => onDuplicateAgent(agent.id),
180
180
  onDeleteAgent: handleOnDelete,
181
- onChatClick: () => onChatClick ? onChatClick() : onOpenChatFullScreen(agent.id),
181
+ onChatClick: () => onChatClick ? onChatClick() : onOpenChatFullScreen(agent.id, agent.name),
182
182
  resourceClient: resourceClient,
183
183
  onViewFullProfileClick: () => onViewFullProfile(agent.id)
184
184
  })));
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
1
+ import React, { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
2
2
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
3
3
  import { fireEvent } from '../../util/analytics';
4
4
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
@@ -51,34 +51,27 @@ export const AgentProfileCardResourced = props => {
51
51
  return undefined;
52
52
  }
53
53
  }, [creatorUserId, fireAnalytics, props.cloudId, props.resourceClient]);
54
- const getAgentInfo = useCallback(() => {
55
- return props.resourceClient.getRovoAgentProfile({
56
- type: 'identity',
57
- value: props.accountId
58
- }, fireAnalytics);
59
- }, [fireAnalytics, props.accountId, props.resourceClient]);
60
54
  const fetchData = useCallback(async () => {
61
55
  setIsLoading(true);
62
- const getAgentData = async () => {
63
- const profileData = await getAgentInfo();
56
+ try {
57
+ const profileData = await props.resourceClient.getRovoAgentProfile({
58
+ type: 'identity',
59
+ value: props.accountId
60
+ }, fireAnalytics);
64
61
  const agentCreatorInfo = await getCreator(profileData === null || profileData === void 0 ? void 0 : profileData.creator_type, (profileData === null || profileData === void 0 ? void 0 : profileData.creator) || undefined);
65
- return {
62
+ setAgentData({
66
63
  ...profileData,
67
64
  creatorInfo: agentCreatorInfo
68
- };
69
- };
70
- const agentData = await getAgentData();
71
- setAgentData(agentData);
72
- setIsLoading(false);
73
- }, [getAgentInfo, getCreator]);
74
- useEffect(() => {
75
- try {
76
- fetchData();
77
- } catch (error) {
65
+ });
66
+ } catch (err) {
67
+ setError(err);
68
+ } finally {
78
69
  setIsLoading(false);
79
- setError(error);
80
70
  }
81
- }, [fetchData, getAgentInfo, getCreator, props.accountId, props.cloudId, props.resourceClient]);
71
+ }, [fireAnalytics, getCreator, props.accountId, props.resourceClient]);
72
+ useEffect(() => {
73
+ fetchData();
74
+ }, [fetchData]);
82
75
  if (error || !isLoading && !agentData) {
83
76
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
84
77
  reload: () => {
@@ -88,19 +81,18 @@ export const AgentProfileCardResourced = props => {
88
81
  fireAnalytics: () => {}
89
82
  }));
90
83
  }
91
- if (agentData) {
92
- return /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
93
- agent: agentData,
94
- isLoading: isLoading,
95
- hasError: !!error,
96
- isCreatedByViewingUser: creatorUserId === props.viewingUserId,
97
- product: props.product,
98
- onConversationStartersClick: props.onConversationStartersClick,
99
- onChatClick: props.onChatClick,
100
- addFlag: props.addFlag,
101
- resourceClient: props.resourceClient,
102
- cloudId: props.cloudId
103
- });
104
- }
105
- return null;
84
+ return /*#__PURE__*/React.createElement(Suspense, {
85
+ fallback: null
86
+ }, /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
87
+ agent: agentData,
88
+ isLoading: isLoading,
89
+ hasError: !!error,
90
+ isCreatedByViewingUser: creatorUserId === props.viewingUserId,
91
+ product: props.product,
92
+ onConversationStartersClick: props.onConversationStartersClick,
93
+ onChatClick: props.onChatClick,
94
+ addFlag: props.addFlag,
95
+ resourceClient: props.resourceClient,
96
+ cloudId: props.cloudId
97
+ }));
106
98
  };
@@ -1,5 +1,7 @@
1
1
  import { useCallback } from 'react';
2
2
  import { getATLContextUrl } from '@atlaskit/atlassian-context';
3
+ import { fg } from '@atlaskit/platform-feature-flags';
4
+ import { useRovoPostMessageToPubsub } from '@atlaskit/rovo-triggers';
3
5
  import { encodeParamsToUrl } from '../../../util/url';
4
6
  export const firstCharUpper = str => str.charAt(0).toUpperCase() + str.slice(1);
5
7
  const ROVO_PARAM_PREFIX = 'rovoChat';
@@ -13,6 +15,9 @@ const createRovoParams = params => {
13
15
  export const useAgentUrlActions = ({
14
16
  cloudId
15
17
  }) => {
18
+ const {
19
+ publishWithPostMessage
20
+ } = useRovoPostMessageToPubsub();
16
21
  const onEditAgent = useCallback(agentId => {
17
22
  const url = `${getATLContextUrl('home')}/chat/agents/${agentId}/edit`;
18
23
  const urlWithParams = encodeParamsToUrl(url, {
@@ -42,28 +47,71 @@ export const useAgentUrlActions = ({
42
47
  agentId,
43
48
  prompt
44
49
  }) => {
45
- const baseUrl = `${getATLContextUrl('home')}/chat`;
46
- const urlWithParams = encodeParamsToUrl(baseUrl, {
47
- cloudId,
48
- ...createRovoParams({
50
+ const startConversationInNewTab = () => {
51
+ const baseUrl = `${getATLContextUrl('home')}/chat`;
52
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
49
53
  cloudId,
50
- agentId,
51
- prompt,
52
- pathway: 'chat'
53
- })
54
- });
55
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
54
+ ...createRovoParams({
55
+ cloudId,
56
+ agentId,
57
+ prompt,
58
+ pathway: 'chat'
59
+ })
60
+ });
61
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
62
+ };
63
+ if (fg('rovo_profile_card_open_chat_sidebar')) {
64
+ publishWithPostMessage({
65
+ targetWindow: window,
66
+ payload: {
67
+ type: 'chat-new',
68
+ source: 'AgentProfileCard',
69
+ data: {
70
+ name: prompt.slice(0, 50),
71
+ prompt,
72
+ agentId,
73
+ dialogues: []
74
+ }
75
+ },
76
+ onAcknowledgeTimeout: () => {
77
+ startConversationInNewTab();
78
+ }
79
+ });
80
+ } else {
81
+ startConversationInNewTab();
82
+ }
56
83
  };
57
- const onOpenChat = agentId => {
58
- const baseUrl = `${getATLContextUrl('home')}/chat`;
59
- const urlWithParams = encodeParamsToUrl(baseUrl, {
60
- cloudId,
61
- ...createRovoParams({
84
+ const onOpenChat = (agentId, agentName) => {
85
+ const openChatInNewTab = () => {
86
+ const baseUrl = `${getATLContextUrl('home')}/chat`;
87
+ const urlWithParams = encodeParamsToUrl(baseUrl, {
62
88
  cloudId,
63
- agentId
64
- })
65
- });
66
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
89
+ ...createRovoParams({
90
+ cloudId,
91
+ agentId
92
+ })
93
+ });
94
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
95
+ };
96
+ if (fg('rovo_profile_card_open_chat_sidebar')) {
97
+ publishWithPostMessage({
98
+ targetWindow: window,
99
+ payload: {
100
+ type: 'chat-new',
101
+ source: 'AgentProfileCard',
102
+ data: {
103
+ agentId,
104
+ dialogues: [],
105
+ name: `Chat with ${agentName}`
106
+ }
107
+ },
108
+ onAcknowledgeTimeout: () => {
109
+ openChatInNewTab();
110
+ }
111
+ });
112
+ } else {
113
+ openChatInNewTab();
114
+ }
67
115
  };
68
116
  const onViewFullProfile = agentId => {
69
117
  window.open(`${window.location.origin}/people/agent/${agentId}`, '_blank', 'noopener, noreferrer');
@@ -32,7 +32,7 @@ const createEvent = (eventType, action, actionSubject, actionSubjectId, attribut
32
32
  actionSubjectId,
33
33
  attributes: {
34
34
  packageName: "@atlaskit/profilecard",
35
- packageVersion: "20.10.0",
35
+ packageVersion: "20.12.0",
36
36
  ...attributes,
37
37
  firedAt: Math.round(getPageTime())
38
38
  }
@@ -4,7 +4,7 @@ import { AGGQuery } from './graphqlUtils';
4
4
  var ORG_ID_FROM_CLOUD_ID_QUERY = "query OrgIdFromCloudId($cloudId: ID!) {\n\ttenantContexts(cloudIds: [$cloudId]) {\n\t\torgId\n\t}\n}";
5
5
  var addHeaders = function addHeaders(headers) {
6
6
  headers.append('atl-client-name', "@atlaskit/profilecard");
7
- headers.append('atl-client-version', "20.10.0");
7
+ headers.append('atl-client-version', "20.12.0");
8
8
  return headers;
9
9
  };
10
10
  export function getOrgIdForCloudIdFromAGG(_x, _x2) {
@@ -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', "20.10.0");
51
+ headers.append('atl-client-version', "20.12.0");
52
52
  return headers;
53
53
  };
54
54
  export function getTeamFromAGG(_x, _x2, _x3) {
@@ -222,7 +222,7 @@ var AgentProfileCard = function AgentProfileCard(_ref) {
222
222
  },
223
223
  onDeleteAgent: handleOnDelete,
224
224
  onChatClick: function onChatClick() {
225
- return _onChatClick ? _onChatClick() : onOpenChatFullScreen(agent.id);
225
+ return _onChatClick ? _onChatClick() : onOpenChatFullScreen(agent.id, agent.name);
226
226
  },
227
227
  resourceClient: resourceClient,
228
228
  onViewFullProfileClick: function onViewFullProfileClick() {
@@ -4,7 +4,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  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; }
5
5
  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; }
6
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
7
- import React, { useCallback, useEffect, useMemo, useState } from 'react';
7
+ import React, { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
8
8
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
9
9
  import { fireEvent } from '../../util/analytics';
10
10
  import { getAAIDFromARI } from '../../util/rovoAgentUtils';
@@ -92,65 +92,46 @@ export var AgentProfileCardResourced = function AgentProfileCardResourced(props)
92
92
  return _ref.apply(this, arguments);
93
93
  };
94
94
  }(), [creatorUserId, fireAnalytics, props.cloudId, props.resourceClient]);
95
- var getAgentInfo = useCallback(function () {
96
- return props.resourceClient.getRovoAgentProfile({
97
- type: 'identity',
98
- value: props.accountId
99
- }, fireAnalytics);
100
- }, [fireAnalytics, props.accountId, props.resourceClient]);
101
- var fetchData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
102
- var getAgentData, agentData;
103
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
104
- while (1) switch (_context3.prev = _context3.next) {
95
+ var fetchData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
96
+ var profileData, agentCreatorInfo;
97
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
98
+ while (1) switch (_context2.prev = _context2.next) {
105
99
  case 0:
106
100
  setIsLoading(true);
107
- getAgentData = /*#__PURE__*/function () {
108
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
109
- var profileData, agentCreatorInfo;
110
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
111
- while (1) switch (_context2.prev = _context2.next) {
112
- case 0:
113
- _context2.next = 2;
114
- return getAgentInfo();
115
- case 2:
116
- profileData = _context2.sent;
117
- _context2.next = 5;
118
- return getCreator(profileData === null || profileData === void 0 ? void 0 : profileData.creator_type, (profileData === null || profileData === void 0 ? void 0 : profileData.creator) || undefined);
119
- case 5:
120
- agentCreatorInfo = _context2.sent;
121
- return _context2.abrupt("return", _objectSpread(_objectSpread({}, profileData), {}, {
122
- creatorInfo: agentCreatorInfo
123
- }));
124
- case 7:
125
- case "end":
126
- return _context2.stop();
127
- }
128
- }, _callee2);
129
- }));
130
- return function getAgentData() {
131
- return _ref3.apply(this, arguments);
132
- };
133
- }();
134
- _context3.next = 4;
135
- return getAgentData();
101
+ _context2.prev = 1;
102
+ _context2.next = 4;
103
+ return props.resourceClient.getRovoAgentProfile({
104
+ type: 'identity',
105
+ value: props.accountId
106
+ }, fireAnalytics);
136
107
  case 4:
137
- agentData = _context3.sent;
138
- setAgentData(agentData);
139
- setIsLoading(false);
108
+ profileData = _context2.sent;
109
+ _context2.next = 7;
110
+ return getCreator(profileData === null || profileData === void 0 ? void 0 : profileData.creator_type, (profileData === null || profileData === void 0 ? void 0 : profileData.creator) || undefined);
140
111
  case 7:
112
+ agentCreatorInfo = _context2.sent;
113
+ setAgentData(_objectSpread(_objectSpread({}, profileData), {}, {
114
+ creatorInfo: agentCreatorInfo
115
+ }));
116
+ _context2.next = 14;
117
+ break;
118
+ case 11:
119
+ _context2.prev = 11;
120
+ _context2.t0 = _context2["catch"](1);
121
+ setError(_context2.t0);
122
+ case 14:
123
+ _context2.prev = 14;
124
+ setIsLoading(false);
125
+ return _context2.finish(14);
126
+ case 17:
141
127
  case "end":
142
- return _context3.stop();
128
+ return _context2.stop();
143
129
  }
144
- }, _callee3);
145
- })), [getAgentInfo, getCreator]);
130
+ }, _callee2, null, [[1, 11, 14, 17]]);
131
+ })), [fireAnalytics, getCreator, props.accountId, props.resourceClient]);
146
132
  useEffect(function () {
147
- try {
148
- fetchData();
149
- } catch (error) {
150
- setIsLoading(false);
151
- setError(error);
152
- }
153
- }, [fetchData, getAgentInfo, getCreator, props.accountId, props.cloudId, props.resourceClient]);
133
+ fetchData();
134
+ }, [fetchData]);
154
135
  if (error || !isLoading && !agentData) {
155
136
  return /*#__PURE__*/React.createElement(AgentProfileCardWrapper, null, /*#__PURE__*/React.createElement(ErrorMessage, {
156
137
  reload: function reload() {
@@ -160,19 +141,18 @@ export var AgentProfileCardResourced = function AgentProfileCardResourced(props)
160
141
  fireAnalytics: function fireAnalytics() {}
161
142
  }));
162
143
  }
163
- if (agentData) {
164
- return /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
165
- agent: agentData,
166
- isLoading: isLoading,
167
- hasError: !!error,
168
- isCreatedByViewingUser: creatorUserId === props.viewingUserId,
169
- product: props.product,
170
- onConversationStartersClick: props.onConversationStartersClick,
171
- onChatClick: props.onChatClick,
172
- addFlag: props.addFlag,
173
- resourceClient: props.resourceClient,
174
- cloudId: props.cloudId
175
- });
176
- }
177
- return null;
144
+ return /*#__PURE__*/React.createElement(Suspense, {
145
+ fallback: null
146
+ }, /*#__PURE__*/React.createElement(AgentProfileCardLazy, {
147
+ agent: agentData,
148
+ isLoading: isLoading,
149
+ hasError: !!error,
150
+ isCreatedByViewingUser: creatorUserId === props.viewingUserId,
151
+ product: props.product,
152
+ onConversationStartersClick: props.onConversationStartersClick,
153
+ onChatClick: props.onChatClick,
154
+ addFlag: props.addFlag,
155
+ resourceClient: props.resourceClient,
156
+ cloudId: props.cloudId
157
+ }));
178
158
  };
@@ -4,6 +4,8 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
4
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
5
  import { useCallback } from 'react';
6
6
  import { getATLContextUrl } from '@atlaskit/atlassian-context';
7
+ import { fg } from '@atlaskit/platform-feature-flags';
8
+ import { useRovoPostMessageToPubsub } from '@atlaskit/rovo-triggers';
7
9
  import { encodeParamsToUrl } from '../../../util/url';
8
10
  export var firstCharUpper = function firstCharUpper(str) {
9
11
  return str.charAt(0).toUpperCase() + str.slice(1);
@@ -21,6 +23,8 @@ var createRovoParams = function createRovoParams(params) {
21
23
  };
22
24
  export var useAgentUrlActions = function useAgentUrlActions(_ref3) {
23
25
  var cloudId = _ref3.cloudId;
26
+ var _useRovoPostMessageTo = useRovoPostMessageToPubsub(),
27
+ publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage;
24
28
  var onEditAgent = useCallback(function (agentId) {
25
29
  var url = "".concat(getATLContextUrl('home'), "/chat/agents/").concat(agentId, "/edit");
26
30
  var urlWithParams = encodeParamsToUrl(url, _objectSpread({
@@ -47,26 +51,69 @@ export var useAgentUrlActions = function useAgentUrlActions(_ref3) {
47
51
  var onConversationStarter = function onConversationStarter(_ref4) {
48
52
  var agentId = _ref4.agentId,
49
53
  prompt = _ref4.prompt;
50
- var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
51
- var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
52
- cloudId: cloudId
53
- }, createRovoParams({
54
- cloudId: cloudId,
55
- agentId: agentId,
56
- prompt: prompt,
57
- pathway: 'chat'
58
- })));
59
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
54
+ var startConversationInNewTab = function startConversationInNewTab() {
55
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
56
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
57
+ cloudId: cloudId
58
+ }, createRovoParams({
59
+ cloudId: cloudId,
60
+ agentId: agentId,
61
+ prompt: prompt,
62
+ pathway: 'chat'
63
+ })));
64
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
65
+ };
66
+ if (fg('rovo_profile_card_open_chat_sidebar')) {
67
+ publishWithPostMessage({
68
+ targetWindow: window,
69
+ payload: {
70
+ type: 'chat-new',
71
+ source: 'AgentProfileCard',
72
+ data: {
73
+ name: prompt.slice(0, 50),
74
+ prompt: prompt,
75
+ agentId: agentId,
76
+ dialogues: []
77
+ }
78
+ },
79
+ onAcknowledgeTimeout: function onAcknowledgeTimeout() {
80
+ startConversationInNewTab();
81
+ }
82
+ });
83
+ } else {
84
+ startConversationInNewTab();
85
+ }
60
86
  };
61
- var onOpenChat = function onOpenChat(agentId) {
62
- var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
63
- var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
64
- cloudId: cloudId
65
- }, createRovoParams({
66
- cloudId: cloudId,
67
- agentId: agentId
68
- })));
69
- window.open(urlWithParams, '_blank', 'noopener, noreferrer');
87
+ var onOpenChat = function onOpenChat(agentId, agentName) {
88
+ var openChatInNewTab = function openChatInNewTab() {
89
+ var baseUrl = "".concat(getATLContextUrl('home'), "/chat");
90
+ var urlWithParams = encodeParamsToUrl(baseUrl, _objectSpread({
91
+ cloudId: cloudId
92
+ }, createRovoParams({
93
+ cloudId: cloudId,
94
+ agentId: agentId
95
+ })));
96
+ window.open(urlWithParams, '_blank', 'noopener, noreferrer');
97
+ };
98
+ if (fg('rovo_profile_card_open_chat_sidebar')) {
99
+ publishWithPostMessage({
100
+ targetWindow: window,
101
+ payload: {
102
+ type: 'chat-new',
103
+ source: 'AgentProfileCard',
104
+ data: {
105
+ agentId: agentId,
106
+ dialogues: [],
107
+ name: "Chat with ".concat(agentName)
108
+ }
109
+ },
110
+ onAcknowledgeTimeout: function onAcknowledgeTimeout() {
111
+ openChatInNewTab();
112
+ }
113
+ });
114
+ } else {
115
+ openChatInNewTab();
116
+ }
70
117
  };
71
118
  var onViewFullProfile = function onViewFullProfile(agentId) {
72
119
  window.open("".concat(window.location.origin, "/people/agent/").concat(agentId), '_blank', 'noopener, noreferrer');
@@ -39,7 +39,7 @@ var createEvent = function createEvent(eventType, action, actionSubject, actionS
39
39
  actionSubjectId: actionSubjectId,
40
40
  attributes: _objectSpread(_objectSpread({
41
41
  packageName: "@atlaskit/profilecard",
42
- packageVersion: "20.10.0"
42
+ packageVersion: "20.12.0"
43
43
  }, attributes), {}, {
44
44
  firedAt: Math.round(getPageTime())
45
45
  })
@@ -10,4 +10,4 @@ export type AgentProfileCardResourcedProps = {
10
10
  product?: string;
11
11
  addFlag?: (flag: Flag) => void;
12
12
  } & AgentActionsType;
13
- export declare const AgentProfileCardResourced: (props: AgentProfileCardResourcedProps) => JSX.Element | null;
13
+ export declare const AgentProfileCardResourced: (props: AgentProfileCardResourcedProps) => JSX.Element;
@@ -5,7 +5,7 @@ export declare const useAgentUrlActions: ({ cloudId }: {
5
5
  onEditAgent: (agentId: string) => void;
6
6
  onCopyAgent: (agentId: string) => void;
7
7
  onDuplicateAgent: (agentId: string) => void;
8
- onOpenChat: (agentId: string) => void;
8
+ onOpenChat: (agentId: string, agentName: string) => void;
9
9
  onConversationStarter: ({ agentId, prompt }: {
10
10
  agentId: string;
11
11
  prompt: string;
@@ -10,4 +10,4 @@ export type AgentProfileCardResourcedProps = {
10
10
  product?: string;
11
11
  addFlag?: (flag: Flag) => void;
12
12
  } & AgentActionsType;
13
- export declare const AgentProfileCardResourced: (props: AgentProfileCardResourcedProps) => JSX.Element | null;
13
+ export declare const AgentProfileCardResourced: (props: AgentProfileCardResourcedProps) => JSX.Element;
@@ -5,7 +5,7 @@ export declare const useAgentUrlActions: ({ cloudId }: {
5
5
  onEditAgent: (agentId: string) => void;
6
6
  onCopyAgent: (agentId: string) => void;
7
7
  onDuplicateAgent: (agentId: string) => void;
8
- onOpenChat: (agentId: string) => void;
8
+ onOpenChat: (agentId: string, agentName: string) => void;
9
9
  onConversationStarter: ({ agentId, prompt }: {
10
10
  agentId: string;
11
11
  prompt: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/profilecard",
3
- "version": "20.10.0",
3
+ "version": "20.12.0",
4
4
  "description": "A React component to display a card with user information.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -65,8 +65,9 @@
65
65
  "@atlaskit/modal-dialog": "^12.17.0",
66
66
  "@atlaskit/platform-feature-flags": "^0.3.0",
67
67
  "@atlaskit/popup": "^1.29.0",
68
- "@atlaskit/primitives": "^13.1.0",
68
+ "@atlaskit/primitives": "^13.2.0",
69
69
  "@atlaskit/rovo-agent-components": "^1.12.0",
70
+ "@atlaskit/rovo-triggers": "^1.3.0",
70
71
  "@atlaskit/spinner": "^16.3.0",
71
72
  "@atlaskit/theme": "^14.0.0",
72
73
  "@atlaskit/tokens": "^2.2.0",
@@ -90,6 +91,7 @@
90
91
  "@atlassian/feature-flags-test-utils": "*",
91
92
  "@atlassian/ptc-test-utils": "^0.8.0",
92
93
  "@testing-library/react": "^12.1.5",
94
+ "@testing-library/react-hooks": "^8.0.1",
93
95
  "@testing-library/user-event": "^14.4.3",
94
96
  "enzyme": "^3.10.0",
95
97
  "es6-promise": "^4.0.5",
@@ -130,6 +132,9 @@
130
132
  },
131
133
  "platform_profile_card_css_refactor": {
132
134
  "type": "boolean"
135
+ },
136
+ "rovo_profile_card_open_chat_sidebar": {
137
+ "type": "boolean"
133
138
  }
134
139
  }
135
140
  }