feat: restore flow version as fork (#4032)

* feat: restore flow version as fork

* fix: use goto instead of open
This commit is contained in:
HugoCasa
2024-07-05 13:10:00 +02:00
committed by GitHub
parent a9c455567b
commit d724761ecc
2 changed files with 22 additions and 5 deletions
@@ -11,6 +11,7 @@
import Button from '../common/button/Button.svelte'
import { ArrowRight, Pencil, X } from 'lucide-svelte'
import { createEventDispatcher } from 'svelte'
import { goto } from '$app/navigation'
export let path: string
let drawer: Drawer
@@ -191,6 +192,13 @@
{/if}
</span>
<div class="flex p-1 gap-2">
<Button
size="xs"
on:click={() =>
goto(`/flows/add?template_id=${selectedVersion?.id}&template=${path}`)}
>
Restore as fork
</Button>
<Button size="xs" on:click={() => restoreVersion(selected)}
>Redeploy with that version
</Button>
@@ -25,6 +25,7 @@
const hubId = $page.url.searchParams.get('hub')
const templatePath = $page.url.searchParams.get('template')
const templateId = $page.url.searchParams.get('template_id')
const initialState = hubId || templatePath || nodraft ? undefined : localStorage.getItem('flow')
let selectedId: string = 'settings-metadata'
@@ -98,13 +99,21 @@
state?.selectedId && (selectedId = state?.selectedId)
} else {
if (templatePath) {
const template = await FlowService.getFlowByPath({
workspace: $workspaceStore!,
path: templatePath
})
let template: Flow
if (templateId) {
template = await FlowService.getFlowVersion({
workspace: $workspaceStore!,
path: templatePath,
version: parseInt(templateId)
})
} else {
template = await FlowService.getFlowByPath({
workspace: $workspaceStore!,
path: templatePath
})
}
Object.assign(flow, template)
const oldPath = templatePath.split('/')
console.log(oldPath)
initialPath = `u/${$userStore?.username.split('@')[0]}/${oldPath[oldPath.length - 1]}_fork`
flow = flow
goto('?', { replaceState: true })