UNPKG

@atlaskit/profilecard

Version:

A React component to display a card with user information.

148 lines 5.97 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; 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) { _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; } import { useCallback } from 'react'; import { getATLContextUrl } from '@atlaskit/atlassian-context'; import { fg } from '@atlaskit/platform-feature-flags'; import { useRovoPostMessageToPubsub } from '@atlaskit/rovo-triggers/post-message-to-pubsub'; import { navigateToTeamsApp } from '@atlaskit/teams-app-config/navigation'; import { useAnalyticsEvents } from '@atlaskit/teams-app-internal-analytics'; import { encodeParamsToUrl } from '../../../util/url'; import { getAtlassianStudioAgentDuplicateUrl, getAtlassianStudioAgentEditUrl } from '../utils'; export var 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 = _slicedToArray(_ref, 2), key = _ref2[0], value = _ref2[1]; rovoParams["".concat(ROVO_PARAM_PREFIX).concat(firstCharUpper(key))] = encodeURIComponent(value); }); return rovoParams; }; export var useAgentUrlActions = function useAgentUrlActions(_ref3) { var cloudId = _ref3.cloudId, source = _ref3.source; var _useRovoPostMessageTo = useRovoPostMessageToPubsub(), publishWithPostMessage = _useRovoPostMessageTo.publishWithPostMessage; var _useAnalyticsEvents = useAnalyticsEvents(), fireEvent = _useAnalyticsEvents.fireEvent; var onEditAgent = useCallback(function (agentId) { var url = 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 = encodeParamsToUrl(url, { cloudId: cloudId }); navigator.clipboard.writeText(urlWithParams); fireEvent('ui.button.clicked.copyAgentLinkButton', { agentId: agentId, source: source }); }; var onDuplicateAgent = useCallback(function (agentId) { var url = 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(getATLContextUrl('home'), "/chat"); var urlWithParams = 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(getATLContextUrl('home'), "/chat"); var urlWithParams = 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 = navigateToTeamsApp({ type: 'AGENT', payload: { agentId: agentId }, cloudId: cloudId, shouldOpenInSameTab: false }), onNavigate = _navigateToTeamsApp.onNavigate; if (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 }; };