UNPKG

@atlaskit/rovo-agent-components

Version:

This package host public components related to rovo agents, the components here are needed for other public atlaskit packages

238 lines (237 loc) 10.9 kB
/* index.tsx generated by @compiled/babel-plugin v0.39.1 */ import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator"; import _slicedToArray from "@babel/runtime/helpers/slicedToArray"; var _excluded = ["triggerRef"]; import "./index.compiled.css"; import { ax, ix } from "@compiled/react/runtime"; import _regeneratorRuntime from "@babel/runtime/regenerator"; import React, { useEffect, useState } from 'react'; import { useIntl } from 'react-intl'; import Button, { IconButton } from '@atlaskit/button/new'; import DropdownMenu, { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu'; import MoreIcon from '@atlaskit/icon/core/show-more-horizontal'; import { fg } from '@atlaskit/platform-feature-flags'; import { Box, Inline } from '@atlaskit/primitives/compiled'; import Spinner from '@atlaskit/spinner'; import { ChatPillIcon } from '../../common/ui/chat-icon'; import { AgentVerificationDropdownItem } from '../agent-verification-dropdown-item'; import messages from './messages'; var styles = { chatToAgentButtonContainer: "_1bsb1osq", chatToAgentButtonWrapper: "_1e0c1txw _1bah1h6o _k48p1wq8", chatPillButtonInline: "_18zrv77o", chatPillText: "_1nmz1hna _y3gn1e5h _o5721jtm", chatPillIconWrapper: "_1ul9gktf _4t3igktf" }; export var ChatToAgentButton = function ChatToAgentButton(_ref) { var onClick = _ref.onClick; var _useIntl = useIntl(), formatMessage = _useIntl.formatMessage; return /*#__PURE__*/React.createElement(Box, { xcss: styles.chatToAgentButtonContainer }, /*#__PURE__*/React.createElement(Button, { testId: "view-agent-modal-chat-to-agent-button", shouldFitContainer: true, onClick: onClick }, /*#__PURE__*/React.createElement(Box, { xcss: styles.chatToAgentButtonWrapper }, /*#__PURE__*/React.createElement(Inline, { space: "space.050", xcss: styles.chatPillButtonInline }, /*#__PURE__*/React.createElement(Box, { xcss: styles.chatPillIconWrapper }, /*#__PURE__*/React.createElement(ChatPillIcon, null)), /*#__PURE__*/React.createElement(Box, { xcss: styles.chatPillText }, formatMessage(messages.chatToAgentButton)))))); }; export var AgentDropdownMenu = function AgentDropdownMenu(_ref2) { var isAutodevTemplateAgent = _ref2.isAutodevTemplateAgent, onEditAgent = _ref2.onEditAgent, onCopyAgent = _ref2.onCopyAgent, onDuplicateAgent = _ref2.onDuplicateAgent, onDeleteAgent = _ref2.onDeleteAgent, onViewAgentFullProfileClick = _ref2.onViewAgentFullProfileClick, _onOpenChange = _ref2.onOpenChange, isForgeAgent = _ref2.isForgeAgent, _ref2$showViewAgentOp = _ref2.showViewAgentOption, showViewAgentOption = _ref2$showViewAgentOp === void 0 ? false : _ref2$showViewAgentOp, onViewAgentClick = _ref2.onViewAgentClick, onDropdownTriggerClick = _ref2.onDropdownTriggerClick, spacing = _ref2.spacing, appearance = _ref2.appearance, dropdownMenuTestId = _ref2.dropdownMenuTestId, doesAgentHaveIdentityAccountId = _ref2.doesAgentHaveIdentityAccountId, loadAgentPermissions = _ref2.loadAgentPermissions, loadPermissionsOnMount = _ref2.loadPermissionsOnMount, shouldTriggerStopPropagation = _ref2.shouldTriggerStopPropagation, agentName = _ref2.agentName, agentRef = _ref2.agentRef, userPermissionsRef = _ref2.userPermissionsRef, onVerificationSuccess = _ref2.onVerificationSuccess, customDropdownOptions = _ref2.customDropdownOptions; var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isLoading = _useState2[0], setIsLoading = _useState2[1]; var _useState3 = useState(false), _useState4 = _slicedToArray(_useState3, 2), isDuplicating = _useState4[0], setIsDuplicating = _useState4[1]; var _useIntl2 = useIntl(), formatMessage = _useIntl2.formatMessage; var _useState5 = useState(false), _useState6 = _slicedToArray(_useState5, 2), hasBeenCopied = _useState6[0], setHasBeenCopied = _useState6[1]; var _useState7 = useState(false), _useState8 = _slicedToArray(_useState7, 2), isOpen = _useState8[0], setIsOpen = _useState8[1]; var _useState9 = useState(), _useState0 = _slicedToArray(_useState9, 2), permissions = _useState0[0], setPermissions = _useState0[1]; useEffect(function () { var fetchData = /*#__PURE__*/function () { var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() { var _yield$loadAgentPermi, isCreateEnabled, isEditEnabled, isDeleteEnabled; return _regeneratorRuntime.wrap(function (_context) { while (1) switch (_context.prev = _context.next) { case 0: setIsLoading(true); _context.next = 1; return loadAgentPermissions(); case 1: _yield$loadAgentPermi = _context.sent; isCreateEnabled = _yield$loadAgentPermi.isCreateEnabled; isEditEnabled = _yield$loadAgentPermi.isEditEnabled; isDeleteEnabled = _yield$loadAgentPermi.isDeleteEnabled; setIsLoading(false); setPermissions({ isCreateEnabled: isCreateEnabled, isEditEnabled: isEditEnabled, isDeleteEnabled: isDeleteEnabled }); case 2: case "end": return _context.stop(); } }, _callee); })); return function fetchData() { return _ref3.apply(this, arguments); }; }(); // Only load once if (!permissions && (isOpen || loadPermissionsOnMount)) { fetchData(); } }, [isOpen, loadAgentPermissions, loadPermissionsOnMount, permissions]); useEffect(function () { if (!isOpen) { setHasBeenCopied(false); } }, [isOpen]); var renderEditDelete = function renderEditDelete() { if (!(permissions !== null && permissions !== void 0 && permissions.isEditEnabled) && !(permissions !== null && permissions !== void 0 && permissions.isDeleteEnabled)) { return null; } return /*#__PURE__*/React.createElement(DropdownItemGroup, { hasSeparator: true }, permissions.isEditEnabled && /*#__PURE__*/React.createElement(DropdownItem, { onClick: onEditAgent }, formatMessage(messages.editAgent)), permissions.isDeleteEnabled && /*#__PURE__*/React.createElement(DropdownItem, { onClick: onDeleteAgent }, formatMessage(messages.deleteAgent))); }; var isCreateAgentsEnabled = permissions === null || permissions === void 0 ? void 0 : permissions.isCreateEnabled; return /*#__PURE__*/React.createElement(DropdownMenu, { isLoading: isLoading, isOpen: isOpen, testId: dropdownMenuTestId, trigger: function trigger(_ref4) { var triggerRef = _ref4.triggerRef, props = _objectWithoutProperties(_ref4, _excluded); return /*#__PURE__*/React.createElement(IconButton, _extends({}, props, { icon: MoreIcon, label: agentName ? formatMessage(messages.moreActionsForLabel, { agentName: agentName }) : formatMessage(messages.moreActionsLabel), ref: triggerRef, spacing: spacing, appearance: appearance, onClick: function onClick(e, analyticsEvent) { var _props$onClick; if (onDropdownTriggerClick) { onDropdownTriggerClick(e, analyticsEvent); } if (shouldTriggerStopPropagation) { e.stopPropagation(); } (_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, e); } })); }, onOpenChange: function onOpenChange(args) { setIsOpen(args.isOpen); _onOpenChange === null || _onOpenChange === void 0 || _onOpenChange(args); if (!args.isOpen) { setHasBeenCopied(false); } } }, /*#__PURE__*/React.createElement(DropdownItemGroup, null, fg('jira_browse_agents_modal') && (customDropdownOptions === null || customDropdownOptions === void 0 ? void 0 : customDropdownOptions.map(function (option) { return /*#__PURE__*/React.createElement(DropdownItem, { key: option.id, onClick: option.onClick }, option.label); })), showViewAgentOption && /*#__PURE__*/React.createElement(DropdownItem, { onClick: onViewAgentClick }, formatMessage(messages.viewAgent)), doesAgentHaveIdentityAccountId && onViewAgentFullProfileClick && /*#__PURE__*/React.createElement(DropdownItem, { onClick: onViewAgentFullProfileClick }, formatMessage(messages.viewAgentFullProfile)), !isForgeAgent && isCreateAgentsEnabled && /*#__PURE__*/React.createElement(DropdownItem, { onClick: ( /*#__PURE__*/function () { var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(e) { return _regeneratorRuntime.wrap(function (_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: if (fg('rovo_agent_versioning_enabled')) { e.stopPropagation(); } setIsDuplicating(true); _context2.prev = 1; _context2.next = 2; return onDuplicateAgent === null || onDuplicateAgent === void 0 ? void 0 : onDuplicateAgent(e); case 2: _context2.prev = 2; setIsDuplicating(false); return _context2.finish(2); case 3: case "end": return _context2.stop(); } }, _callee2, null, [[1,, 2, 3]]); })); return function (_x) { return _ref5.apply(this, arguments); }; }()), isDisabled: isDuplicating }, /*#__PURE__*/React.createElement(Inline, { space: "space.050" }, isDuplicating && /*#__PURE__*/React.createElement(Spinner, { size: "small" }), isAutodevTemplateAgent ? formatMessage(messages.useTemplateButton) : formatMessage(messages.duplicateAgent))), /*#__PURE__*/React.createElement(DropdownItem, { onClick: function onClick(e) { e.stopPropagation(); setHasBeenCopied(true); onCopyAgent === null || onCopyAgent === void 0 || onCopyAgent(e); } }, formatMessage(hasBeenCopied ? messages.linkedCopiedToProfile : messages.copyLinkToProfile)), agentRef && userPermissionsRef && fg('rovo_agents_agent_verification') && /*#__PURE__*/React.createElement(AgentVerificationDropdownItem, { agentRef: agentRef !== null && agentRef !== void 0 ? agentRef : null, userPermissionsRef: userPermissionsRef !== null && userPermissionsRef !== void 0 ? userPermissionsRef : null, onVerificationSuccess: onVerificationSuccess, testId: "agent-actions-menu-verification" })), renderEditDelete()); };