import { useState, type FormEvent } from 'react'; import type { DevHostFlowEntry, DevHostFlowRunState, DevHostPresetEntry } from '../types.js'; import { ClearIcon, PresetsIcon, SendIcon } from './icons.js'; import { FlowList } from './FlowList.js'; import { DropdownMenu, type DropdownMenuItem } from './ui/DropdownMenu.js'; import { IconButton } from './ui/IconButton.js'; import { Input } from './ui/Input.js'; import { ScrollArea } from './ui/ScrollArea.js'; import { Textarea } from './ui/Textarea.js'; import { ToggleGroup } from './ui/ToggleGroup.js'; type DispatchFormProps = { commandType: string; commandPayload: string; flows: DevHostFlowEntry[]; flowRuns: DevHostFlowRunState[]; hasRunningFlow: (flowName: string) => boolean; presets: DevHostPresetEntry[]; canDispatch: boolean; onRunFlow: (flow: DevHostFlowEntry) => void; onStopFlow: (runId: string) => void; onCommandTypeChange: (value: string) => void; onCommandPayloadChange: (value: string) => void; onApplyPreset: (preset: DevHostPresetEntry) => void; onReset: () => void; onSubmit: (event: FormEvent) => void; }; export const DispatchForm = ({ commandType, commandPayload, flows, flowRuns, hasRunningFlow, presets, canDispatch, onRunFlow, onStopFlow, onCommandTypeChange, onCommandPayloadChange, onApplyPreset, onReset, onSubmit, }: DispatchFormProps) => { const [activeTab, setActiveTab] = useState<'dispatch' | 'flows'>('dispatch'); const presetItems: DropdownMenuItem[] = presets.map((preset) => ({ id: preset.displayName, label: preset.displayName, item: preset, })); const presetButton = ( 0 ? 'Open presets' : 'No presets available'} title={presets.length > 0 ? 'Presets' : 'No presets available'} disabled={presets.length === 0} overrides={{ BaseButton: { style: { borderRadius: '6px', backgroundColor: 'rgba(255, 255, 255, 0.04)', color: 'rgba(255, 255, 255, 0.88)', }, }, }} > ); return (
Actions
setActiveTab(value as 'dispatch' | 'flows')} options={[ { key: 'dispatch', label: 'Dispatch' }, { key: 'flows', label: 'Flows' }, ]} /> {activeTab === 'dispatch' ? presets.length > 0 ? {presetButton} : presetButton : null}
{activeTab === 'dispatch' ? (
onCommandTypeChange(event.currentTarget.value)} placeholder="get-snapshot" spellCheck={false} />