mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-21 00:02:23 +00:00
feat(frontend): restored-from-local toast in resource/variable editors
Resource and variable editors silently loaded LS autosaves over the backend value, leaving users with no signal that the form wasn't reflecting deployed state. Both now fire the standard `notifyRestoredFromLocal` toast (with a "Reset to deployed" action that re-seeds the handle from the just-fetched backend) the first time a lazy-fetch finds the local draft diverging from the remote.
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
import { getUserExt } from '$lib/user'
|
||||
import type { UserExt } from '$lib/stores'
|
||||
import { UserDraft, type UserDraftHandle } from '$lib/userDraft.svelte'
|
||||
import { notifyRestoredFromLocal } from '$lib/userDraftToast'
|
||||
|
||||
interface Props {
|
||||
canSave?: boolean
|
||||
@@ -204,6 +205,21 @@
|
||||
labels: r.labels ?? undefined,
|
||||
wsSpecific: r.ws_specific ?? false
|
||||
}
|
||||
// Surface the local autosave-vs-backend divergence before the
|
||||
// handle is registered, so the user knows the form is showing
|
||||
// their unsaved work. The "Reset to deployed" action drops the
|
||||
// LS entry and re-seeds the handle from the just-fetched
|
||||
// backend state.
|
||||
const persisted = UserDraft.get<ResourceState>('resource', initialPath ?? '', {
|
||||
workspace: ws
|
||||
})
|
||||
if (persisted !== undefined && !deepEqual(persisted, s)) {
|
||||
notifyRestoredFromLocal(false, true, {
|
||||
onResetToDeployed: () => {
|
||||
UserDraft.save('resource', initialPath ?? '', s, { workspace: ws })
|
||||
}
|
||||
})
|
||||
}
|
||||
ensureHandle(ws, s)
|
||||
initialStates[ws] = structuredClone(s)
|
||||
existedInitially[ws] = true
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
import { getUserExt } from '$lib/user'
|
||||
import type { UserExt } from '$lib/stores'
|
||||
import { UserDraft, type UserDraftHandle } from '$lib/userDraft.svelte'
|
||||
import { notifyRestoredFromLocal } from '$lib/userDraftToast'
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
@@ -129,6 +130,17 @@
|
||||
labels: v.labels ?? undefined,
|
||||
wsSpecific: v.ws_specific ?? false
|
||||
}
|
||||
// See ResourceEditor for the same pattern: tell the user the
|
||||
// form is showing their local autosave (not the backend),
|
||||
// with a one-click "Reset to deployed" escape.
|
||||
const persisted = UserDraft.get<VariableState>('variable', p, { workspace: ws })
|
||||
if (persisted !== undefined && !deepEqual(persisted, s)) {
|
||||
notifyRestoredFromLocal(false, true, {
|
||||
onResetToDeployed: () => {
|
||||
UserDraft.save('variable', p, s, { workspace: ws })
|
||||
}
|
||||
})
|
||||
}
|
||||
ensureHandle(ws, s)
|
||||
initialStates[ws] = structuredClone(s)
|
||||
existedInitially[ws] = true
|
||||
|
||||
Reference in New Issue
Block a user