From e3d10def5fa3e97c1dc6b6e621b3791c0836b104 Mon Sep 17 00:00:00 2001 From: pyranota <92104930+pyranota@users.noreply.github.com> Date: Fri, 15 Nov 2024 18:24:57 +0000 Subject: [PATCH] Ignore fields with `false` value in DiffViewer (#4712) * Convert false to undefined * Remove comments * Make it consistent * Formatting * Apply at downstream --- frontend/src/lib/components/DiffDrawer.svelte | 4 +- .../src/lib/components/FlowBuilder.svelte | 30 +++++++------ .../src/lib/components/ScriptBuilder.svelte | 45 ++++++++++++------- .../apps/editor/AppEditorHeader.svelte | 34 +++++++++----- frontend/src/lib/utils.ts | 24 ++++++++++ .../flows/edit/[...path]/+page.svelte | 2 +- 6 files changed, 97 insertions(+), 42 deletions(-) diff --git a/frontend/src/lib/components/DiffDrawer.svelte b/frontend/src/lib/components/DiffDrawer.svelte index 7b461534c9..37979e28d0 100644 --- a/frontend/src/lib/components/DiffDrawer.svelte +++ b/frontend/src/lib/components/DiffDrawer.svelte @@ -8,6 +8,7 @@ cleanValueProperties, orderedJsonStringify, orderedYamlStringify, + replaceFalseWithUndefined, type Value } from '$lib/utils' import type { Script } from '$lib/gen' @@ -54,8 +55,9 @@ diffViewer.closeDrawer() } + function prepareDiff(data: Value) { - const metadata = structuredClone(cleanValueProperties(data)) + const metadata = structuredClone(cleanValueProperties(replaceFalseWithUndefined(data))) const content = metadata['content'] if (metadata['content'] !== undefined) { metadata['content'] = 'check content diff' diff --git a/frontend/src/lib/components/FlowBuilder.svelte b/frontend/src/lib/components/FlowBuilder.svelte index c90525db4b..1835c4f330 100644 --- a/frontend/src/lib/components/FlowBuilder.svelte +++ b/frontend/src/lib/components/FlowBuilder.svelte @@ -25,6 +25,7 @@ encodeState, formatCron, orderedJsonStringify, + replaceFalseWithUndefined, sleep, type Value } from '$lib/utils' @@ -294,12 +295,21 @@ // We need it for diff await syncWithDeployed() - // Handle through confirmation modal - confirmCallback = async () => { + if ( + deployedValue && + $flowStore && + orderedJsonStringify(deployedValue) === + orderedJsonStringify(replaceFalseWithUndefined({ ...$flowStore, path: $pathStore })) + ) { await saveFlow(deploymentMsg) + } else { + // Handle through confirmation modal + confirmCallback = async () => { + await saveFlow(deploymentMsg) + } + // Open confirmation modal + open = true } - // Open confirmation modal - open = true } } async function syncWithDeployed() { @@ -308,18 +318,12 @@ path: initialPath, withStarredInfo: true }) - deployedValue = { + deployedValue = replaceFalseWithUndefined({ ...flow, - starred: undefined, - id: undefined, edited_at: undefined, edited_by: undefined, - workspace_id: undefined, - archived: undefined, - same_worker: undefined, - visible_to_runner_only: undefined, - ws_error_handler_muted: undefined - } + workspace_id: undefined + }) deployedBy = flow.edited_by } diff --git a/frontend/src/lib/components/ScriptBuilder.svelte b/frontend/src/lib/components/ScriptBuilder.svelte index 44a73f5bdd..4728ae8294 100644 --- a/frontend/src/lib/components/ScriptBuilder.svelte +++ b/frontend/src/lib/components/ScriptBuilder.svelte @@ -18,6 +18,7 @@ encodeState, formatCron, orderedJsonStringify, + replaceFalseWithUndefined, type Value } from '$lib/utils' import Path from './Path.svelte' @@ -278,17 +279,28 @@ // Fetch entire script, since we need it to show Diff await syncWithDeployed() - // Handle through confirmation modal - confirmCallback = async () => { - open = false - if (actual_parent_hash) { - await editScript(stay, actual_parent_hash, deployMsg) - } else { - sendUserToast('Could not fetch latest version of the script', true) + if ( + deployedValue && + script && + orderedJsonStringify({ ...deployedValue, hash: undefined }) === + orderedJsonStringify( + replaceFalseWithUndefined({ ...script, hash: undefined, parent_hash: undefined }) + ) + ) { + await editScript(stay, actual_parent_hash, deployMsg) + } else { + // Handle through confirmation modal + confirmCallback = async () => { + open = false + if (actual_parent_hash) { + await editScript(stay, actual_parent_hash, deployMsg) + } else { + sendUserToast('Could not fetch latest version of the script', true) + } } + // Open confirmation modal + open = true } - // Open confirmation modal - open = true } } @@ -299,20 +311,16 @@ withStarredInfo: true }) - deployedValue = { + deployedValue = replaceFalseWithUndefined({ ...latestScript, - starred: undefined, workspace_id: undefined, - archived: undefined, created_at: undefined, created_by: undefined, - deleted: undefined, extra_perms: undefined, - is_template: undefined, lock: undefined, lock_error_logs: undefined, parent_hashes: undefined - } + }) deployedBy = latestScript.created_by } @@ -691,8 +699,11 @@