Fix Agent Flow toggle state sync (#5348)
This commit is contained in:
parent
a841486c5e
commit
3c2682eb5f
@ -12,6 +12,7 @@ function ManageFlowMenu({ flow, onDelete }) {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
async function deleteFlow() {
|
async function deleteFlow() {
|
||||||
|
setOpen(false);
|
||||||
if (
|
if (
|
||||||
!window.confirm(
|
!window.confirm(
|
||||||
"Are you sure you want to delete this flow? This action cannot be undone."
|
"Are you sure you want to delete this flow? This action cannot be undone."
|
||||||
@ -28,6 +29,8 @@ function ManageFlowMenu({ flow, onDelete }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!open) return;
|
||||||
|
|
||||||
const handleClickOutside = (event) => {
|
const handleClickOutside = (event) => {
|
||||||
if (menuRef.current && !menuRef.current.contains(event.target)) {
|
if (menuRef.current && !menuRef.current.contains(event.target)) {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
@ -38,7 +41,7 @@ function ManageFlowMenu({ flow, onDelete }) {
|
|||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener("mousedown", handleClickOutside);
|
document.removeEventListener("mousedown", handleClickOutside);
|
||||||
};
|
};
|
||||||
}, []);
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative" ref={menuRef}>
|
<div className="relative" ref={menuRef}>
|
||||||
@ -71,23 +74,15 @@ function ManageFlowMenu({ flow, onDelete }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FlowPanel({ flow, toggleFlow, onDelete }) {
|
export default function FlowPanel({ flow, toggleFlow, enabled, onDelete }) {
|
||||||
const [isActive, setIsActive] = useState(flow.active);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setIsActive(flow.active);
|
|
||||||
}, [flow.uuid, flow.active]);
|
|
||||||
|
|
||||||
const handleToggle = async () => {
|
const handleToggle = async () => {
|
||||||
try {
|
try {
|
||||||
const { success, error } = await AgentFlows.toggleFlow(
|
const { success, error } = await AgentFlows.toggleFlow(
|
||||||
flow.uuid,
|
flow.uuid,
|
||||||
!isActive
|
!enabled
|
||||||
);
|
);
|
||||||
if (!success) throw new Error(error);
|
if (!success) throw new Error(error);
|
||||||
setIsActive(!isActive);
|
|
||||||
toggleFlow(flow.uuid);
|
toggleFlow(flow.uuid);
|
||||||
showToast("Flow status updated successfully", "success", { clear: true });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to toggle flow:", error);
|
console.error("Failed to toggle flow:", error);
|
||||||
showToast("Failed to toggle flow", "error", { clear: true });
|
showToast("Failed to toggle flow", "error", { clear: true });
|
||||||
@ -106,7 +101,7 @@ export default function FlowPanel({ flow, toggleFlow, onDelete }) {
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-x-2">
|
<div className="flex items-center gap-x-2">
|
||||||
<Toggle size="lg" enabled={isActive} onChange={handleToggle} />
|
<Toggle size="lg" enabled={enabled} onChange={handleToggle} />
|
||||||
<ManageFlowMenu flow={flow} onDelete={onDelete} />
|
<ManageFlowMenu flow={flow} onDelete={onDelete} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,6 +5,7 @@ export default function AgentFlowsList({
|
|||||||
flows = [],
|
flows = [],
|
||||||
selectedFlow,
|
selectedFlow,
|
||||||
handleClick,
|
handleClick,
|
||||||
|
activeFlowIds = [],
|
||||||
}) {
|
}) {
|
||||||
if (flows.length === 0) {
|
if (flows.length === 0) {
|
||||||
return (
|
return (
|
||||||
@ -43,7 +44,7 @@ export default function AgentFlowsList({
|
|||||||
<div className="text-sm font-light">{flow.name}</div>
|
<div className="text-sm font-light">{flow.name}</div>
|
||||||
<div className="flex items-center gap-x-2">
|
<div className="flex items-center gap-x-2">
|
||||||
<div className="text-sm text-theme-text-secondary font-medium">
|
<div className="text-sm text-theme-text-secondary font-medium">
|
||||||
{flow.active ? "On" : "Off"}
|
{activeFlowIds.includes(flow.uuid) ? "On" : "Off"}
|
||||||
</div>
|
</div>
|
||||||
<CaretRight
|
<CaretRight
|
||||||
size={14}
|
size={14}
|
||||||
|
|||||||
@ -111,7 +111,7 @@ export default function AdminAgents() {
|
|||||||
_preferences.settings?.disabled_agent_skills ?? []
|
_preferences.settings?.disabled_agent_skills ?? []
|
||||||
);
|
);
|
||||||
setImportedSkills(_preferences.settings?.imported_agent_skills ?? []);
|
setImportedSkills(_preferences.settings?.imported_agent_skills ?? []);
|
||||||
setActiveFlowIds(_preferences.settings?.active_agent_flows ?? []);
|
setActiveFlowIds(flows.filter((f) => f.active).map((f) => f.uuid));
|
||||||
setAgentFlows(flows);
|
setAgentFlows(flows);
|
||||||
setFileSystemAgentAvailable(fsAgentAvailable);
|
setFileSystemAgentAvailable(fsAgentAvailable);
|
||||||
setCreateFilesAgentAvailable(createFilesAvailable);
|
setCreateFilesAgentAvailable(createFilesAvailable);
|
||||||
@ -385,6 +385,7 @@ export default function AdminAgents() {
|
|||||||
flows={agentFlows}
|
flows={agentFlows}
|
||||||
selectedFlow={selectedFlow}
|
selectedFlow={selectedFlow}
|
||||||
handleClick={handleFlowClick}
|
handleClick={handleFlowClick}
|
||||||
|
activeFlowIds={activeFlowIds}
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
@ -601,6 +602,7 @@ export default function AdminAgents() {
|
|||||||
flows={agentFlows}
|
flows={agentFlows}
|
||||||
selectedFlow={selectedFlow}
|
selectedFlow={selectedFlow}
|
||||||
handleClick={handleFlowClick}
|
handleClick={handleFlowClick}
|
||||||
|
activeFlowIds={activeFlowIds}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MCPServerHeader
|
<MCPServerHeader
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user