fix(drafts): suppress 'You have unsaved changes' banner when deployed baseline is null

A brand-new variable/resource/trigger (no deployed row yet) has
`getDeployed() == null`, but the caller's `show` prop is computed
off `current != deployed` which is trivially true while the user
types. Result: the banner appeared with 'Show diff' (no-op — the
drawer early-returns on null deployed) and a 'Discard' that's
semantically backwards (there's nothing to revert to).

Gate `show` internally on `getDeployed() != null`. The check sits
in the banner rather than each caller because every caller would
otherwise need the same boilerplate guard.
This commit is contained in:
Diego Imbert
2026-06-09 14:43:26 +02:00
parent 35c9dbda9a
commit 2b61c052b4
@@ -31,6 +31,15 @@
title = 'Deployed <> Local changes'
}: Props = $props()
// Suppress the banner when there's no deployed baseline to diff
// against — a brand-new entity (variable/resource/trigger with no
// deployed row yet) has deployed == null, so "Show diff" would do
// nothing (the drawer early-returns) and "Discard changes" is
// semantically backwards (there's nothing to revert to). The
// callers' own `show` is computed off `current != deployed` which
// is trivially true in that case, so the gate has to live here.
let visible = $derived(show && getDeployed() != null)
let diffDrawer: DiffDrawer | undefined = $state()
function showDiff() {
@@ -66,7 +75,7 @@
<DiffDrawer bind:this={diffDrawer} />
{#if show}
{#if visible}
<div
transition:slide|local={{ duration: 120 }}
class={twMerge(