mirror of
https://github.com/simstudioai/sim.git
synced 2026-01-10 07:27:57 -05:00
Fixed workflow naming and added to control bar
This commit is contained in:
@@ -51,7 +51,9 @@ export function ControlBar() {
|
||||
<div className="flex h-16 w-full items-center justify-between bg-background px-6 border-b transition-all duration-300">
|
||||
{/* Left Section - Workflow Info */}
|
||||
<div className="flex flex-col gap-[2px]">
|
||||
<h2 className="font-semibold text-sm">Workflow 1</h2>
|
||||
<h2 className="font-semibold text-sm">
|
||||
{activeWorkflowId ? workflows[activeWorkflowId].name : 'Workflow'}
|
||||
</h2>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Saved{' '}
|
||||
{formatDistanceToNow(history.present.timestamp, { addSuffix: true })}
|
||||
|
||||
@@ -67,10 +67,13 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
|
||||
},
|
||||
|
||||
addWorkflow: (metadata: WorkflowMetadata) => {
|
||||
const uniqueName = generateUniqueName(get().workflows)
|
||||
const updatedMetadata = { ...metadata, name: uniqueName }
|
||||
|
||||
set((state) => ({
|
||||
workflows: {
|
||||
...state.workflows,
|
||||
[metadata.id]: metadata
|
||||
[metadata.id]: updatedMetadata
|
||||
},
|
||||
error: null
|
||||
}))
|
||||
@@ -167,6 +170,24 @@ export const useWorkflowRegistry = create<WorkflowRegistry>()(
|
||||
)
|
||||
)
|
||||
|
||||
const generateUniqueName = (existingWorkflows: Record<string, WorkflowMetadata>): string => {
|
||||
// Extract numbers from existing workflow names using regex
|
||||
const numbers = Object.values(existingWorkflows)
|
||||
.map(w => {
|
||||
const match = w.name.match(/Workflow (\d+)/)
|
||||
return match ? parseInt(match[1]) : 0
|
||||
})
|
||||
.filter(n => n > 0)
|
||||
|
||||
if (numbers.length === 0) {
|
||||
return 'Workflow 1'
|
||||
}
|
||||
|
||||
// Find the maximum number and add 1
|
||||
const nextNumber = Math.max(...numbers) + 1
|
||||
return `Workflow ${nextNumber}`
|
||||
}
|
||||
|
||||
// Initialize registry from localStorage
|
||||
const initializeRegistry = () => {
|
||||
const savedRegistry = localStorage.getItem('workflow-registry')
|
||||
@@ -179,4 +200,4 @@ const initializeRegistry = () => {
|
||||
// Call this in your app's entry point
|
||||
if (typeof window !== 'undefined') {
|
||||
initializeRegistry()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user