From 712c44d819b3cacaf8fe2a6c752fbe64467cf30c Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Mon, 23 Mar 2026 16:39:08 +0100 Subject: [PATCH] fix: run datatable cloning before workspace fork creation Co-Authored-By: Claude Opus 4.5 --- .../CreateWorkspaceInner.svelte | 139 +++++++++--------- 1 file changed, 68 insertions(+), 71 deletions(-) diff --git a/frontend/src/lib/components/workspaceSettings/CreateWorkspaceInner.svelte b/frontend/src/lib/components/workspaceSettings/CreateWorkspaceInner.svelte index 123d8b03d3..6e5fc13871 100644 --- a/frontend/src/lib/components/workspaceSettings/CreateWorkspaceInner.svelte +++ b/frontend/src/lib/components/workspaceSettings/CreateWorkspaceInner.svelte @@ -137,67 +137,7 @@ failedSyncJobs = [] forkCreationError = '' - let gitSyncJobIds = await WorkspaceService.createWorkspaceForkGitBranch({ - workspace: $workspaceStore!, - requestBody: { - id: prefixed_id, - name, - color: colorEnabled && workspaceColor ? workspaceColor : undefined - } - }) - - try { - await Promise.all( - gitSyncJobIds.map((jobId) => - jobManager.runWithProgress(() => Promise.resolve(jobId), { - workspace: $workspaceStore, - timeout: 60000, - timeoutMessage: `Deploy fork job timed out after 60s`, - onProgress: (status) => { - if (status.status === 'failure') { - errorMsgs.push(status.error ?? 'Deploy fork job failed') - failedSyncJobs.push(jobId) - } - } - }) - ) - ) - } catch (error) { - forkCreationLoading = false - sendUserToast( - `Could not fork workspace ${$workspaceStore} because branch creation failed: ${errorMsgs} - ${error}`, - true - ) - return - } - if (errorMsgs.length != 0) { - forkCreationError = 'Failed to create a branch for this fork on the git sync repo(s)' - forkCreationLoading = false - sendUserToast( - `Could not fork workspace ${$workspaceStore} because branch creation failed: ${errorMsgs}`, - true - ) - return - } - - try { - await WorkspaceService.createWorkspaceFork({ - workspace: $workspaceStore!, - requestBody: { - id: prefixed_id, - name, - color: colorEnabled && workspaceColor ? workspaceColor : undefined - } - }) - } catch (e) { - forkCreationError = `Failed to create fork '${prefixed_id}'` - errorMsgs.push(e?.body ?? e ?? 'Unknown error') - forkCreationLoading = false - sendUserToast(`Could not create fork '${prefixed_id}' ${e}`, true) - return - } - - // Check if any datatables need cloning + // Clone datatables BEFORE creating the workspace fork if (forkDatatableSection) { const queue = forkDatatableSection.buildCloneQueue(prefixed_id) if (queue.length > 0) { @@ -206,13 +146,77 @@ } } - forkCreationLoading = false - sendUserToast(`Successfully forked workspace ${$workspaceStore} as: wm-fork-${id}`) + await completeFork(prefixed_id) } else { sendUserToast('No workspace selected, cannot fork non-existent workspace', true) } } + async function completeFork(prefixed_id: string): Promise { + let gitSyncJobIds = await WorkspaceService.createWorkspaceForkGitBranch({ + workspace: $workspaceStore!, + requestBody: { + id: prefixed_id, + name, + color: colorEnabled && workspaceColor ? workspaceColor : undefined + } + }) + + try { + await Promise.all( + gitSyncJobIds.map((jobId) => + jobManager.runWithProgress(() => Promise.resolve(jobId), { + workspace: $workspaceStore!, + timeout: 60000, + timeoutMessage: `Deploy fork job timed out after 60s`, + onProgress: (status) => { + if (status.status === 'failure') { + errorMsgs.push(status.error ?? 'Deploy fork job failed') + failedSyncJobs.push(jobId) + } + } + }) + ) + ) + } catch (error) { + forkCreationLoading = false + sendUserToast( + `Could not fork workspace ${$workspaceStore} because branch creation failed: ${errorMsgs} - ${error}`, + true + ) + return + } + if (errorMsgs.length != 0) { + forkCreationError = 'Failed to create a branch for this fork on the git sync repo(s)' + forkCreationLoading = false + sendUserToast( + `Could not fork workspace ${$workspaceStore} because branch creation failed: ${errorMsgs}`, + true + ) + return + } + + try { + await WorkspaceService.createWorkspaceFork({ + workspace: $workspaceStore!, + requestBody: { + id: prefixed_id, + name, + color: colorEnabled && workspaceColor ? workspaceColor : undefined + } + }) + } catch (e) { + forkCreationError = `Failed to create fork '${prefixed_id}'` + errorMsgs.push(e?.body ?? e ?? 'Unknown error') + forkCreationLoading = false + sendUserToast(`Could not create fork '${prefixed_id}' ${e}`, true) + return + } + + forkCreationLoading = false + sendUserToast(`Successfully forked workspace ${$workspaceStore} as: wm-fork-${id}`) + } + async function createWorkspace(): Promise { await WorkspaceService.createWorkspace({ requestBody: { @@ -483,13 +487,7 @@ { - forkCreationLoading = false - sendUserToast(`Successfully forked workspace ${$workspaceStore} as: wm-fork-${id}`) - usersWorkspaceStore.set(undefined) - WorkspaceService.listUserWorkspaces().then((ws) => { - usersWorkspaceStore.set(ws) - switchWorkspace(`wm-fork-${id}`) - }) + completeFork(`${WM_FORK_PREFIX}${id}`) }} onCanceled={() => { forkCreationLoading = false @@ -648,4 +646,3 @@ {/if} -