@atlaskit/profilecard
Version:
A React component to display a card with user information.
127 lines (126 loc) • 5.49 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 _rovoTriggers = require("@atlaskit/rovo-triggers");
var _url = require("../../../util/url");
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;
var _useRovoPostMessageTo = (0, _rovoTriggers.useRovoPostMessageToPubsub)(),
publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage;
var onEditAgent = (0, _react.useCallback)(function (agentId) {
var url = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat/agents/").concat(agentId, "/edit");
var urlWithParams = (0, _url.encodeParamsToUrl)(url, _objectSpread({
cloudId: cloudId
}, createRovoParams({
cloudId: cloudId
})));
window.open(urlWithParams, '_blank', 'noopener, noreferrer');
}, [cloudId]);
var onCopyAgent = function onCopyAgent(agentId) {
navigator.clipboard.writeText("".concat(window.location.origin, "/people/agent/").concat(agentId));
};
var onDuplicateAgent = (0, _react.useCallback)(function (agentId) {
var baseUrl = "".concat((0, _atlassianContext.getATLContextUrl)('home'), "/chat/agents/new");
var urlWithParams = (0, _url.encodeParamsToUrl)(baseUrl, _objectSpread({
cloudId: cloudId
}, createRovoParams({
cloudId: cloudId,
agentId: agentId,
pathway: 'agents-create'
})));
window.open(urlWithParams, '_blank', 'noopener, noreferrer');
}, [cloudId]);
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) {
window.open("".concat(window.location.origin, "/people/agent/").concat(agentId), '_blank', 'noopener, noreferrer');
};
return {
onEditAgent: onEditAgent,
onCopyAgent: onCopyAgent,
onDuplicateAgent: onDuplicateAgent,
onOpenChat: onOpenChat,
onConversationStarter: onConversationStarter,
onViewFullProfile: onViewFullProfile
};
};