fix(import): preserve workflow colors during import (#3130)

* fix(import): preserve workflow colors during import

* cleanup
This commit is contained in:
Waleed
2026-02-03 20:18:08 -08:00
committed by GitHub
parent 7977ac88ca
commit 0a08ac03b9
2 changed files with 25 additions and 19 deletions

View File

@@ -52,9 +52,8 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
const workflowName = extractWorkflowName(content, filename)
clearDiff()
const parsedContent = JSON.parse(content)
const workflowColor =
parsedContent.state?.metadata?.color || parsedContent.metadata?.color || '#3972F6'
(workflowData.metadata as { color?: string } | undefined)?.color || '#3972F6'
const result = await createWorkflowMutation.mutateAsync({
name: workflowName,
@@ -62,23 +61,20 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
workspaceId,
folderId: folderId || undefined,
sortOrder,
color: workflowColor,
})
const newWorkflowId = result.id
if (workflowColor !== '#3972F6') {
await fetch(`/api/workflows/${newWorkflowId}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ color: workflowColor }),
})
}
await fetch(`/api/workflows/${newWorkflowId}/state`, {
const stateResponse = await fetch(`/api/workflows/${newWorkflowId}/state`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(workflowData),
})
if (!stateResponse.ok) {
logger.error(`Failed to save workflow state for ${newWorkflowId}`)
}
if (workflowData.variables) {
const variablesArray = Array.isArray(workflowData.variables)
? workflowData.variables
@@ -101,11 +97,15 @@ export function useImportWorkflow({ workspaceId }: UseImportWorkflowProps) {
}
}
await fetch(`/api/workflows/${newWorkflowId}/variables`, {
const variablesResponse = await fetch(`/api/workflows/${newWorkflowId}/variables`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ variables: variablesRecord }),
})
if (!variablesResponse.ok) {
logger.error(`Failed to save variables for ${newWorkflowId}`)
}
}
}

View File

@@ -160,9 +160,8 @@ export function useImportWorkspace({ onSuccess }: UseImportWorkspaceProps = {})
const workflowName = extractWorkflowName(workflow.content, workflow.name)
clearDiff()
const parsedContent = JSON.parse(workflow.content)
const workflowColor =
parsedContent.state?.metadata?.color || parsedContent.metadata?.color || '#3972F6'
(workflowData.metadata as { color?: string } | undefined)?.color || '#3972F6'
const createWorkflowResponse = await fetch('/api/workflows', {
method: 'POST',
@@ -216,11 +215,18 @@ export function useImportWorkspace({ onSuccess }: UseImportWorkspaceProps = {})
}
}
await fetch(`/api/workflows/${newWorkflow.id}/variables`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ variables: variablesRecord }),
})
const variablesResponse = await fetch(
`/api/workflows/${newWorkflow.id}/variables`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ variables: variablesRecord }),
}
)
if (!variablesResponse.ok) {
logger.error(`Failed to save variables for ${newWorkflow.id}`)
}
}
}