feat(frontend): disable change agent button while agent is running (#11691)

This commit is contained in:
Hiep Le 2025-11-12 00:46:12 +07:00 committed by GitHub
parent cdd8aace86
commit 915c180ba7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
import React, { useMemo } from "react";
import React, { useMemo, useEffect } from "react";
import { useTranslation } from "react-i18next";
import { Typography } from "#/ui/typography";
import { I18nKey } from "#/i18n/declaration";
@ -9,6 +9,8 @@ import { useConversationStore } from "#/state/conversation-store";
import { ChangeAgentContextMenu } from "./change-agent-context-menu";
import { cn } from "#/utils/utils";
import { USE_PLANNING_AGENT } from "#/utils/feature-flags";
import { useAgentState } from "#/hooks/use-agent-state";
import { AgentState } from "#/types/agent-state";
export function ChangeAgentButton() {
const { t } = useTranslation();
@ -24,6 +26,17 @@ export function ChangeAgentButton() {
const shouldUsePlanningAgent = USE_PLANNING_AGENT();
const { curAgentState } = useAgentState();
const isAgentRunning = curAgentState === AgentState.RUNNING;
// Close context menu when agent starts running
useEffect(() => {
if (isAgentRunning && contextMenuOpen) {
setContextMenuOpen(false);
}
}, [isAgentRunning, contextMenuOpen]);
const handleButtonClick = (event: React.MouseEvent<HTMLButtonElement>) => {
event.preventDefault();
event.stopPropagation();
@ -67,9 +80,13 @@ export function ChangeAgentButton() {
<button
type="button"
onClick={handleButtonClick}
disabled={isAgentRunning}
className={cn(
"flex items-center border border-[#4B505F] rounded-[100px] cursor-pointer hover:opacity-80",
"flex items-center border border-[#4B505F] rounded-[100px] transition-opacity",
!isExecutionAgent && "border-[#597FF4] bg-[#4A67BD]",
isAgentRunning
? "opacity-50 cursor-not-allowed"
: "cursor-pointer hover:opacity-80",
)}
>
<div className="flex items-center gap-1 pl-1.5">