From 080b62c2e36ac85799f7f6788a71bd44aab82a40 Mon Sep 17 00:00:00 2001 From: Emir Karabeg Date: Mon, 3 Feb 2025 23:36:57 -0800 Subject: [PATCH] Fixed sidebar colors ordering when creating new workflow --- app/w/components/sidebar/sidebar.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/w/components/sidebar/sidebar.tsx b/app/w/components/sidebar/sidebar.tsx index 44e934029..0710edef5 100644 --- a/app/w/components/sidebar/sidebar.tsx +++ b/app/w/components/sidebar/sidebar.tsx @@ -29,13 +29,23 @@ export function Sidebar() { const handleCreateWorkflow = () => { const id = crypto.randomUUID() - const colorIndex = Object.keys(workflows).length % WORKFLOW_COLORS.length + const workflowArray = Object.values(workflows) + const lastWorkflow = workflowArray[workflowArray.length - 1] + + // Find the index of the last used color, defaulting to first color if undefined + const lastColorIndex = lastWorkflow?.color + ? WORKFLOW_COLORS.indexOf(lastWorkflow.color) + : -1 + + // Get next color index, wrapping around to 0 if we reach the end + const nextColorIndex = (lastColorIndex + 1) % WORKFLOW_COLORS.length + const newWorkflow = { id, - name: `Workflow ${Object.keys(workflows).length + 1}`, + name: `Workflow ${workflowArray.length + 1}`, lastModified: new Date(), description: 'New workflow', - color: WORKFLOW_COLORS[colorIndex], + color: WORKFLOW_COLORS[nextColorIndex], } addWorkflow(newWorkflow)