@atlaskit/profilecard
Version:
A React component to display a card with user information.
155 lines (154 loc) • 6.48 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useAgentUrlActions = exports.firstCharUpper = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = require("react");
var _atlassianContext = require("@atlaskit/atlassian-context");
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _postMessageToPubsub = require("@atlaskit/rovo-triggers/post-message-to-pubsub");
var _navigation = require("@atlaskit/teams-app-config/navigation");
var _teamsAppInternalAnalytics = require("@atlaskit/teams-app-internal-analytics");
var _url = require("../../../util/url");
var _utils = require("../utils");
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; }
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; }
var firstCharUpper = exports.firstCharUpper = function firstCharUpper(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
};
var ROVO_PARAM_PREFIX = 'rovoChat';
var createRovoParams = function createRovoParams(params) {
var rovoParams = {};
Object.entries(params).forEach(function (_ref) {
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
key = _ref2[0],
value = _ref2[1];
rovoParams["".concat(ROVO_PARAM_PREFIX).concat(firstCharUpper(key))] = encodeURIComponent(value);
});
return rovoParams;
};
var useAgentUrlActions = exports.useAgentUrlActions = function useAgentUrlActions(_ref3) {
var cloudId = _ref3.cloudId,
source = _ref3.source;
var _useRovoPostMessageTo = (0, _postMessageToPubsub.useRovoPostMessageToPubsub)(),
publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage;
var _useAnalyticsEvents = (0, _teamsAppInternalAnalytics.useAnalyticsEvents)(),
fireEvent = _useAnalyticsEvents.fireEvent;
var onEditAgent = (0, _react.useCallback)(function (agentId) {
var url = (0, _utils.getAtlassianStudioAgentEditUrl)(cloudId, agentId);
window.open(url, '_blank', 'noopener, noreferrer');
fireEvent('ui.button.clicked.editAgentButton', {
agentId: agentId,
source: source
});
}, [cloudId, fireEvent, source]);
var onCopyAgent = function onCopyAgent(agentId) {
var url = "".concat(window.location.origin, "/people/agent/").concat(agentId);
var urlWithParams = (0, _url.encodeParamsToUrl)(url, {
cloudId: cloudId
});
navigator.clipboard.writeText(urlWithParams);
fireEvent('ui.button.clicked.copyAgentLinkButton', {
agentId: agentId,
source: source
});
};
var onDuplicateAgent = (0, _react.useCallback)(function (agentId) {
var url = (0, _utils.getAtlassianStudioAgentDuplicateUrl)(cloudId, agentId);
window.open(url, '_blank', 'noopener, noreferrer');
fireEvent('ui.button.clicked.duplicateAgentButton', {
agentId: agentId,
source: source
});
}, [cloudId, fireEvent, source]);
var onConversationStarter = function onConversationStarter(_ref4) {
var agentId = _ref4.agentId,
prompt = _ref4.prompt;
var startConversationInNewTab = function startConversationInNewTab() {
var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
cloudId: cloudId
}, createRovoParams({
cloudId: cloudId,
agentId: agentId,
prompt: prompt,
pathway: 'chat'
})));
window.open(urlWithParams, '_blank', 'noopener, noreferrer');
};
publishWithPostMessage({
targetWindow: window,
payload: {
type: 'chat-new',
source: 'AgentProfileCard',
data: {
name: prompt.slice(0, 50),
prompt: prompt,
agentId: agentId,
dialogues: []
}
},
onAcknowledgeTimeout: function onAcknowledgeTimeout() {
startConversationInNewTab();
}
});
};
var onOpenChat = function onOpenChat(agentId, agentName) {
var openChatInNewTab = function openChatInNewTab() {
var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat");
var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
cloudId: cloudId
}, createRovoParams({
cloudId: cloudId,
agentId: agentId
})));
window.open(urlWithParams, '_blank', 'noopener, noreferrer');
};
publishWithPostMessage({
targetWindow: window,
payload: {
type: 'chat-new',
source: 'AgentProfileCard',
data: {
agentId: agentId,
dialogues: [],
name: "Chat with ".concat(agentName)
}
},
onAcknowledgeTimeout: function onAcknowledgeTimeout() {
openChatInNewTab();
}
});
};
var onViewFullProfile = function onViewFullProfile(agentId) {
var _navigateToTeamsApp = (0, _navigation.navigateToTeamsApp)({
type: 'AGENT',
payload: {
agentId: agentId
},
cloudId: cloudId,
shouldOpenInSameTab: false
}),
onNavigate = _navigateToTeamsApp.onNavigate;
if ((0, _platformFeatureFlags.fg)('platform-adopt-teams-nav-config')) {
onNavigate();
} else {
window.open("".concat(window.location.origin, "/people/agent/").concat(agentId), '_blank', 'noopener, noreferrer');
}
fireEvent('ui.button.clicked.viewAgentFullProfileButton', {
agentId: agentId,
source: source
});
};
return {
onEditAgent: onEditAgent,
onCopyAgent: onCopyAgent,
onDuplicateAgent: onDuplicateAgent,
onOpenChat: onOpenChat,
onConversationStarter: onConversationStarter,
onViewFullProfile: onViewFullProfile
};
};