mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
Added console open state and made it open on run
This commit is contained in:
@@ -14,9 +14,11 @@ import { useWorkflowRegistry } from '@/stores/workflow/registry'
|
||||
import { ConsoleEntry } from './components/console-entry/console-entry'
|
||||
|
||||
export function Console() {
|
||||
const [isCollapsed, setIsCollapsed] = useState(true)
|
||||
const [width, setWidth] = useState(336) // 84 * 4 = 336px (default width)
|
||||
const [isDragging, setIsDragging] = useState(false)
|
||||
|
||||
const isOpen = useConsoleStore((state) => state.isOpen)
|
||||
const toggleConsole = useConsoleStore((state) => state.toggleConsole)
|
||||
const entries = useConsoleStore((state) => state.entries)
|
||||
const clearConsole = useConsoleStore((state) => state.clearConsole)
|
||||
const { activeWorkflowId } = useWorkflowRegistry()
|
||||
@@ -53,12 +55,12 @@ export function Console() {
|
||||
}
|
||||
}, [isDragging])
|
||||
|
||||
if (isCollapsed) {
|
||||
if (!isOpen) {
|
||||
return (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
onClick={() => setIsCollapsed(false)}
|
||||
onClick={toggleConsole}
|
||||
className="fixed right-4 bottom-[18px] z-10 flex h-9 w-9 items-center justify-center rounded-lg bg-background text-muted-foreground transition-colors hover:text-foreground hover:bg-accent border"
|
||||
>
|
||||
<Terminal className="h-5 w-5" />
|
||||
@@ -110,7 +112,7 @@ export function Console() {
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
onClick={() => setIsCollapsed(true)}
|
||||
onClick={toggleConsole}
|
||||
className="absolute left-4 bottom-[18px] flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:text-foreground hover:bg-accent"
|
||||
>
|
||||
<PanelLeftClose className="h-5 w-5" />
|
||||
|
||||
@@ -13,10 +13,17 @@ export function useWorkflowExecution() {
|
||||
const { blocks, edges } = useWorkflowStore()
|
||||
const { activeWorkflowId } = useWorkflowRegistry()
|
||||
const { addNotification } = useNotificationStore()
|
||||
const { addConsole } = useConsoleStore()
|
||||
const { addConsole, toggleConsole, isOpen } = useConsoleStore()
|
||||
|
||||
const handleRunWorkflow = useCallback(async () => {
|
||||
if (!activeWorkflowId) return
|
||||
setIsExecuting(true)
|
||||
|
||||
// Open console if it's not already open
|
||||
if (!isOpen) {
|
||||
toggleConsole()
|
||||
}
|
||||
|
||||
try {
|
||||
// Extract existing block states
|
||||
const currentBlockStates = Object.entries(blocks).reduce((acc, [id, block]) => {
|
||||
@@ -97,7 +104,7 @@ export function useWorkflowExecution() {
|
||||
} finally {
|
||||
setIsExecuting(false)
|
||||
}
|
||||
}, [blocks, edges, addNotification, activeWorkflowId, addConsole])
|
||||
}, [activeWorkflowId, blocks, edges, addNotification, addConsole, isOpen, toggleConsole])
|
||||
|
||||
return { isExecuting, executionResult, handleRunWorkflow }
|
||||
}
|
||||
@@ -9,6 +9,7 @@ export const useConsoleStore = create<ConsoleStore>()(
|
||||
persist(
|
||||
(set, get) => ({
|
||||
entries: [],
|
||||
isOpen: true,
|
||||
|
||||
addConsole: (entry) => {
|
||||
set((state) => {
|
||||
@@ -34,6 +35,10 @@ export const useConsoleStore = create<ConsoleStore>()(
|
||||
getWorkflowEntries: (workflowId) => {
|
||||
return get().entries.filter((entry) => entry.workflowId === workflowId)
|
||||
},
|
||||
|
||||
toggleConsole: () => {
|
||||
set((state) => ({ isOpen: !state.isOpen }))
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'console-store',
|
||||
|
||||
@@ -13,7 +13,9 @@ export interface ConsoleEntry {
|
||||
|
||||
export interface ConsoleStore {
|
||||
entries: ConsoleEntry[]
|
||||
isOpen: boolean
|
||||
addConsole: (entry: Omit<ConsoleEntry, 'id'>) => void
|
||||
clearConsole: (workflowId: string | null) => void
|
||||
getWorkflowEntries: (workflowId: string) => ConsoleEntry[]
|
||||
toggleConsole: () => void
|
||||
}
|
||||
Reference in New Issue
Block a user