Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

2.4 KB
Raw Blame
import { Permission } from '@activepieces/core-utils';
import { AgentSummary } from '@activepieces/shared';
import { t } from 'i18next';
import { FolderInput, MoreHorizontal, Trash2 } from 'lucide-react';
import { useState } from 'react';

import { Button } from '@/components/ui/button';
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { DeleteAgentDialog } from '@/features/agents/delete-agent-dialog';
import { MoveAgentDialog } from '@/features/agents/move-agent-dialog';
import { projectCollectionUtils } from '@/features/projects';
import { useAuthorization } from '@/hooks/authorization-hooks';

export const AgentActionsMenu = ({ agent }: AgentActionsMenuProps) => {
  const [deleting, setDeleting] = useState(false);
  const [moving, setMoving] = useState(false);
  const { checkAccess } = useAuthorization(agent.projectId);
  const { data: allProjects } = projectCollectionUtils.useAll();
  const canMove = (allProjects ?? []).length > 1;

  if (!checkAccess(Permission.WRITE_AGENT)) {
    return null;
  }

  return (
    <>
      <DropdownMenu>
        <DropdownMenuTrigger asChild>
          <Button
            variant="ghost"
            size="icon-xs"
            aria-label={t('Agent actions')}
            className="pointer-events-none rounded-full opacity-0 transition-opacity focus-visible:opacity-100 group-hover:pointer-events-auto group-hover:opacity-100 data-[state=open]:pointer-events-auto data-[state=open]:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100"
          >
            <MoreHorizontal size={16} />
          </Button>
        </DropdownMenuTrigger>
        <DropdownMenuContent align="end">
          {canMove && (
            <DropdownMenuItem onSelect={() => setMoving(true)}>
              <FolderInput />
              {t('Move to another project')}
            </DropdownMenuItem>
          )}
          <DropdownMenuItem
            variant="destructive"
            onSelect={() => setDeleting(true)}
          >
            <Trash2 />
            {t('Delete')}
          </DropdownMenuItem>
        </DropdownMenuContent>
      </DropdownMenu>
      <DeleteAgentDialog
        agent={agent}
        open={deleting}
        onOpenChange={setDeleting}
      />
      <MoveAgentDialog agent={agent} open={moving} onOpenChange={setMoving} />
    </>
  );
};

type AgentActionsMenuProps = {
  agent: AgentSummary;
};