Skip to content

Commit

Permalink
Don't remove references to DamFile from blocks when copying a docum…
Browse files Browse the repository at this point in the history
…ent from one scope to another if DAM scoping is not enabled (#1992)
  • Loading branch information
thomasdax98 authored Apr 25, 2024
1 parent a696ec7 commit c1ca9c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/new-mugs-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@comet/cms-admin": patch
---

Don't remove references to `DamFile` from blocks when copying a document from one scope to another if DAM scoping is not enabled
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export async function sendPages(
if (sourcePage.document && !isEqual(sourceContentScope, targetContentScope)) {
const unhandledDependencies = unhandledDependenciesFromDocument(documentType, sourcePage.document, {
existingReplacements: dependencyReplacements,
hasDamScope,
});
const replacementsForUnhandledDependencies = createUndefinedReplacementsForDependencies(unhandledDependencies);
dependencyReplacements.push(...replacementsForUnhandledDependencies);
Expand Down Expand Up @@ -413,16 +414,18 @@ function createPageTreeNodeIdReplacements(nodes: PageClipboard[]): ReplaceDepend
function unhandledDependenciesFromDocument(
documentType: DocumentInterface,
document: GQLDocument,
{ existingReplacements }: { existingReplacements: ReplaceDependencyObject[] },
{ existingReplacements, hasDamScope = false }: { existingReplacements: ReplaceDependencyObject[]; hasDamScope?: boolean },
) {
const unhandledDependencies = documentType
.dependencies(document)
.filter(
(dependency) =>
!existingReplacements.some(
(replacement) => replacement.originalId === dependency.id && replacement.type === dependency.targetGraphqlObjectType,
),
const unhandledDependencies = documentType.dependencies(document).filter((dependency) => {
if (dependency.targetGraphqlObjectType === "DamFile" && !hasDamScope) {
// If there is no DAM scoping (DAM = global), the dependency is not unhandled. It's handled correctly by doing nothing
return false;
}

return !existingReplacements.some(
(replacement) => replacement.originalId === dependency.id && replacement.type === dependency.targetGraphqlObjectType,
);
});

return unhandledDependencies;
}
Expand Down

0 comments on commit c1ca9c3

Please sign in to comment.