diff --git a/frontend/src/lib/components/DeployWorkspace.svelte b/frontend/src/lib/components/DeployWorkspace.svelte index b2ac609e59..a539fbeedf 100644 --- a/frontend/src/lib/components/DeployWorkspace.svelte +++ b/frontend/src/lib/components/DeployWorkspace.svelte @@ -19,8 +19,7 @@ import Toggle from './Toggle.svelte' import { Loader2 } from 'lucide-svelte' import Badge from './common/badge/Badge.svelte' - import * as Diff from 'diff' - import { Drawer, DrawerContent } from './common' + import DiffDrawer from './DiffDrawer.svelte' const dispatch = createEventDispatcher() @@ -37,7 +36,9 @@ const allAlreadyExists: { [key: string]: boolean } = {} + let diffDrawer: DiffDrawer let notSet: boolean | undefined = undefined + $: WorkspaceService.getDeployTo({ workspace: $workspaceStore! }).then((x) => { workspaceToDeployTo = x.deploy_to if (x.deploy_to == undefined) { @@ -348,33 +349,6 @@ return `${kind}:${path}` } - export function showDiff(local: string, remote: string) { - let finalString = '' - for (const part of Diff.diffLines(local, remote)) { - if (part.removed) { - // print red if removed without newline - finalString += `${part.value}` - } else if (part.added) { - // print green if added - finalString += `${part.value}` - } else { - let lines = part.value.split('\n') - - if (lines.length > 12) { - lines = lines.slice(0, 6) - lines.push('...') - lines = lines.concat(part.value.split('\n').slice(-6)) - } - // print white if unchanged - finalString += `${lines.join('\n')}` - } - } - return finalString - } - - let diffViewer: Drawer - let diffContent: string | undefined = undefined - async function getValue(kind: Kind, path: string, workspace: string) { try { if (kind == 'flow') { @@ -439,12 +413,13 @@ } } - async function computeDiff(kind: Kind, path: string) { + async function showDiff(kind: Kind, path: string) { + diffDrawer.openDrawer() let values = await Promise.all([ getValue(kind, path, $workspaceStore!), getValue(kind, path, workspaceToDeployTo!) ]) - diffContent = showDiff(JSON.stringify(values[0], null, 2), JSON.stringify(values[1], null, 2)) + diffDrawer.setDiff(JSON.stringify(values[0], null, 2), JSON.stringify(values[1], null, 2)) } @@ -477,20 +452,7 @@ {:else if seeTarget == true}
{@html diffContent}
- {@html diffContent}
+