@atlaskit/rovo-agent-components
Version:
This package host public components related to rovo agents, the components here are needed for other public atlaskit packages
187 lines (186 loc) • 7.42 kB
JavaScript
/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _extends from "@babel/runtime/helpers/extends";
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
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';
const styles = {
chatToAgentButtonContainer: "_1bsb1osq",
chatToAgentButtonWrapper: "_1e0c1txw _1bah1h6o _k48p1wq8",
chatPillButtonInline: "_18zrv77o",
chatPillText: "_1nmz1hna _y3gn1e5h _o5721jtm",
chatPillIconWrapper: "_1ul9gktf _4t3igktf"
};
export const ChatToAgentButton = ({
onClick
}) => {
const {
formatMessage
} = useIntl();
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 const AgentDropdownMenu = ({
isAutodevTemplateAgent,
onEditAgent,
onCopyAgent,
onDuplicateAgent,
onDeleteAgent,
onViewAgentFullProfileClick,
onOpenChange,
isForgeAgent,
showViewAgentOption = false,
onViewAgentClick,
onDropdownTriggerClick,
spacing,
appearance,
dropdownMenuTestId,
doesAgentHaveIdentityAccountId,
loadAgentPermissions,
loadPermissionsOnMount,
shouldTriggerStopPropagation,
agentName,
agentRef,
userPermissionsRef,
onVerificationSuccess,
customDropdownOptions
}) => {
const [isLoading, setIsLoading] = useState(false);
const [isDuplicating, setIsDuplicating] = useState(false);
const {
formatMessage
} = useIntl();
const [hasBeenCopied, setHasBeenCopied] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [permissions, setPermissions] = useState();
useEffect(() => {
const fetchData = async () => {
setIsLoading(true);
const {
isCreateEnabled,
isEditEnabled,
isDeleteEnabled
} = await loadAgentPermissions();
setIsLoading(false);
setPermissions({
isCreateEnabled,
isEditEnabled,
isDeleteEnabled
});
};
// Only load once
if (!permissions && (isOpen || loadPermissionsOnMount)) {
fetchData();
}
}, [isOpen, loadAgentPermissions, loadPermissionsOnMount, permissions]);
useEffect(() => {
if (!isOpen) {
setHasBeenCopied(false);
}
}, [isOpen]);
const 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)));
};
const isCreateAgentsEnabled = permissions === null || permissions === void 0 ? void 0 : permissions.isCreateEnabled;
return /*#__PURE__*/React.createElement(DropdownMenu, {
isLoading: isLoading,
isOpen: isOpen,
testId: dropdownMenuTestId,
trigger: ({
triggerRef,
...props
}) => /*#__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: (e, analyticsEvent) => {
var _props$onClick;
if (onDropdownTriggerClick) {
onDropdownTriggerClick(e, analyticsEvent);
}
if (shouldTriggerStopPropagation) {
e.stopPropagation();
}
(_props$onClick = props.onClick) === null || _props$onClick === void 0 ? void 0 : _props$onClick.call(props, e);
}
})),
onOpenChange: args => {
setIsOpen(args.isOpen);
onOpenChange === null || onOpenChange === void 0 ? 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(option => /*#__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: async e => {
if (fg('rovo_agent_versioning_enabled')) {
e.stopPropagation();
}
setIsDuplicating(true);
try {
await (onDuplicateAgent === null || onDuplicateAgent === void 0 ? void 0 : onDuplicateAgent(e));
} finally {
setIsDuplicating(false);
}
},
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: e => {
e.stopPropagation();
setHasBeenCopied(true);
onCopyAgent === null || onCopyAgent === void 0 ? 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());
};