From 7f933f382f8dead4e610e75163e420d69d285b43 Mon Sep 17 00:00:00 2001 From: Amol Anand Date: Wed, 15 Oct 2025 19:59:33 -0400 Subject: [PATCH 1/3] fix: update snapshot content correctly when clicking on sync --- nx/blocks/snapshot-admin/utils/utils.js | 22 +++++++++++++--------- nx/blocks/snapshot-admin/views/snapshot.js | 10 ++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/nx/blocks/snapshot-admin/utils/utils.js b/nx/blocks/snapshot-admin/utils/utils.js index 58e0df6c..c3d3dd24 100644 --- a/nx/blocks/snapshot-admin/utils/utils.js +++ b/nx/blocks/snapshot-admin/utils/utils.js @@ -103,6 +103,17 @@ export function setOrgSite(suppliedOrg, suppliedSite) { site = suppliedSite; } +export async function addResourcesToSnapshot(name, resources) { + const opts = { + method: 'POST', + body: JSON.stringify({ paths: resources }), + headers: { 'Content-Type': 'application/json' }, + }; + const resp = await daFetch(`${AEM_ORIGIN}/snapshot/${org}/${site}/main/${name}/*`, opts); + if (!resp.ok) return formatError(resp); + return { success: true }; +} + export async function updatePaths(name, currPaths, editedHrefs) { const paths = filterPaths(editedHrefs); const { removed, added } = comparePaths(currPaths, paths); @@ -115,15 +126,8 @@ export async function updatePaths(name, currPaths, editedHrefs) { // Handle adds if (added.length > 0) { - const opts = { - method: 'POST', - body: JSON.stringify({ paths: added }), - headers: { 'Content-Type': 'application/json' }, - }; - - // This is technically a bulk ops request - const resp = await daFetch(`${AEM_ORIGIN}/snapshot/${org}/${site}/main/${name}/*`, opts); - if (!resp.ok) return formatError(resp); + const result = await addResourcesToSnapshot(name, added); + if (result.error) return result; } // The formatting of the response will be bulk job-like, diff --git a/nx/blocks/snapshot-admin/views/snapshot.js b/nx/blocks/snapshot-admin/views/snapshot.js index 48d2804b..ab52e6ec 100644 --- a/nx/blocks/snapshot-admin/views/snapshot.js +++ b/nx/blocks/snapshot-admin/views/snapshot.js @@ -10,6 +10,7 @@ import { reviewSnapshot, updateSchedule, formatLocalDate, + addResourcesToSnapshot, } from '../utils/utils.js'; const nx = `${new URL(import.meta.url).origin}/nx`; @@ -176,6 +177,15 @@ class NxSnapshot extends LitElement { ? 'Forking content into snapshot.' : 'Promoting content from snapshot.'; await copyManifest(this.basics.name, this._manifest.resources, direction); + if (this._action === 'fork') { + // we copied the content into the snapshot + // now we need to add the resources to the snapshot again to update aem.reviews + const result = await addResourcesToSnapshot(this.basics.name, this._manifest.resources); + if (result.error) { + this._message = { heading: 'Note', message: result.error, open: true }; + return; + } + } this._action = undefined; } From f540c00a16c4e33d3a71bb9641f8ffcc5e931dc2 Mon Sep 17 00:00:00 2001 From: Amol Anand Date: Wed, 15 Oct 2025 20:40:03 -0400 Subject: [PATCH 2/3] fix: delete the snapshot once all resources are deleted --- nx/blocks/snapshot-admin/utils/utils.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nx/blocks/snapshot-admin/utils/utils.js b/nx/blocks/snapshot-admin/utils/utils.js index c3d3dd24..ba496eeb 100644 --- a/nx/blocks/snapshot-admin/utils/utils.js +++ b/nx/blocks/snapshot-admin/utils/utils.js @@ -95,7 +95,11 @@ export async function deleteSnapshot(name, paths = ['/*']) { })); const firstError = results.find((result) => result.error); if (firstError) return firstError; - return results[0]; + // once all resources are deleted, delete the snapshot as well + const opts = { method: 'DELETE' }; + const resp = await daFetch(`${AEM_ORIGIN}/snapshot/${org}/${site}/main/${name}`, opts); + if (!resp.ok) return formatError(resp); + return { success: true }; } export function setOrgSite(suppliedOrg, suppliedSite) { From 1a60320c889494bb447db0f55a38fc19bbcc4d1c Mon Sep 17 00:00:00 2001 From: Amol Anand Date: Wed, 15 Oct 2025 20:58:40 -0400 Subject: [PATCH 3/3] chore: backing out the sync stuff since it is not needed --- nx/blocks/snapshot-admin/utils/utils.js | 22 +++++++++------------- nx/blocks/snapshot-admin/views/snapshot.js | 10 ---------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/nx/blocks/snapshot-admin/utils/utils.js b/nx/blocks/snapshot-admin/utils/utils.js index ba496eeb..e7993072 100644 --- a/nx/blocks/snapshot-admin/utils/utils.js +++ b/nx/blocks/snapshot-admin/utils/utils.js @@ -107,17 +107,6 @@ export function setOrgSite(suppliedOrg, suppliedSite) { site = suppliedSite; } -export async function addResourcesToSnapshot(name, resources) { - const opts = { - method: 'POST', - body: JSON.stringify({ paths: resources }), - headers: { 'Content-Type': 'application/json' }, - }; - const resp = await daFetch(`${AEM_ORIGIN}/snapshot/${org}/${site}/main/${name}/*`, opts); - if (!resp.ok) return formatError(resp); - return { success: true }; -} - export async function updatePaths(name, currPaths, editedHrefs) { const paths = filterPaths(editedHrefs); const { removed, added } = comparePaths(currPaths, paths); @@ -130,8 +119,15 @@ export async function updatePaths(name, currPaths, editedHrefs) { // Handle adds if (added.length > 0) { - const result = await addResourcesToSnapshot(name, added); - if (result.error) return result; + const opts = { + method: 'POST', + body: JSON.stringify({ paths: added }), + headers: { 'Content-Type': 'application/json' }, + }; + + // This is technically a bulk ops request + const resp = await daFetch(`${AEM_ORIGIN}/snapshot/${org}/${site}/main/${name}/*`, opts); + if (!resp.ok) return formatError(resp); } // The formatting of the response will be bulk job-like, diff --git a/nx/blocks/snapshot-admin/views/snapshot.js b/nx/blocks/snapshot-admin/views/snapshot.js index ab52e6ec..48d2804b 100644 --- a/nx/blocks/snapshot-admin/views/snapshot.js +++ b/nx/blocks/snapshot-admin/views/snapshot.js @@ -10,7 +10,6 @@ import { reviewSnapshot, updateSchedule, formatLocalDate, - addResourcesToSnapshot, } from '../utils/utils.js'; const nx = `${new URL(import.meta.url).origin}/nx`; @@ -177,15 +176,6 @@ class NxSnapshot extends LitElement { ? 'Forking content into snapshot.' : 'Promoting content from snapshot.'; await copyManifest(this.basics.name, this._manifest.resources, direction); - if (this._action === 'fork') { - // we copied the content into the snapshot - // now we need to add the resources to the snapshot again to update aem.reviews - const result = await addResourcesToSnapshot(this.basics.name, this._manifest.resources); - if (result.error) { - this._message = { heading: 'Note', message: result.error, open: true }; - return; - } - } this._action = undefined; }