Skip to content

Enhance duplicate page action#985

Merged
rchlfryn merged 15 commits intomainfrom
duplicate-to-enhance
Mar 25, 2026
Merged

Enhance duplicate page action#985
rchlfryn merged 15 commits intomainfrom
duplicate-to-enhance

Conversation

@rchlfryn
Copy link
Collaborator

@rchlfryn rchlfryn commented Mar 12, 2026

Description

Improves the page duplication and provisioning logic introduced in #974. The clearLayoutRelationships utility properly clears relationship and upload fields from any block — keeping the block structure intact and letting editors repopulate the tenant-specific references.

Provisioning is now driven by DVAC's navigation structure. It queries the template tenant's published navigation to determine which pages and built-in pages to create — only pages referenced in navigation are provisioned. Pages are created as blank published pages (title, slug, empty content block) with no copied content. Built-in pages are also filtered to those referenced in the navigation. Navigation and all pages are published immediately. The duplicatePageToTenant action still uses clearLayoutRelationships to copy layout structure while clearing tenant-specific references, and now only appends " - Copy" to the title/slug when a page with the same slug already exists for the target tenant.

The clearLayoutRelationships utility currently handles all field types in Payload's schema (group, array, tabs, row, collapsible, richText with Lexical blocks), including Lexical-embedded blocks like ButtonBlock and CalloutBlock. If new field container types are added to Payload in the future, the utility would need updating.

Related Issues

Part of #533 (follow-up to #974)
Closes #625

Key Changes

  • Navigation-driven provisioning — queries DVAC's published navigation to extract referenced page slugs and built-in page URLs via extractNavReferences. Only pages and built-in pages that appear in the navigation are created for the new tenant. If DVAC's navigation changes, provisioning automatically adjusts.
  • clearLayoutRelationships utility — recursively clears relationship and upload fields from any block in a page layout (including nested groups, arrays, tabs, and Lexical rich-text blocks with ButtonBlock and CalloutBlock), keeping structure intact so editors repopulate tenant-specific references after duplication.
  • Provisioning creates blank published pages — pages use DVAC's titles and slugs but contain only an empty content block. Navigation and pages are published immediately.
  • Conditional " - Copy" suffixduplicatePageToTenant now only appends " - Copy" to the title and "-copy" to the slug when a page with the same slug already exists for the target tenant.
  • Bug fixduplicatePageToTenant was spreading the cleaned layout array into data instead of assigning it as data.layout.
  • Tests — unit tests for clearLayoutRelationships (relationships, uploads, groups, arrays, tabs, Lexical blocks, id stripping) and integration tests for duplicatePageToTenant (slug conflict and no-conflict cases), backed by a shared fixtures/mockBlocks.ts.

How to test

Added tests

  1. pnpm seed to get a fresh database with the DVAC template tenant
  2. Provisioning: Create a new avalanche center in the admin panel. Verify the onboarding checklist shows automated steps as complete. Only pages and built-in pages referenced in DVAC's navigation are created. Pages are blank (empty content block) and published.
  3. Duplicate to Tenant: Open any published page on DVAC → ⋮ menu → "Duplicate to Tenant" → pick another tenant. Verify the new page is created as a draft with the original title/slug (no " - Copy" if no conflict), relationship fields are cleared (empty), and non-relationship fields (text, colors, layout structure) are preserved.

Screenshots / Demo video

Screenshot 2026-03-11 at 17 48 34

Duplicate page to... demo
Provisioning tenant demo

Migration Explanation

No schema changes — no migration needed.

Future enhancements

Should we include ButtonBlock & CalloutBlock in DEFAULT_BLOCKS? They are the only 2 not included. #1001

@github-actions
Copy link
Contributor

Preview deployment: https://duplicate-to-enhance.preview.avy-fx.org

Copy link
Collaborator

@busbyk busbyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One relationship removal isn't working (ButtonBlock inside of a richText field in EventList (likely BlogList too)): https://www.loom.com/share/777dddf99b784ec7b60e67ffa792a844

@rchlfryn
Copy link
Collaborator Author

One relationship removal isn't working (ButtonBlock inside of a richText field in EventList (likely BlogList too))

Good catch! ButtonBlock & CalloutBlock are the only 2 not included in DEFAULT_BLOCKS? I added a note under Future Enhancement of this PR to make an issue since I do not want to scope creep this PR.

I added ButtonBlock & CalloutBlock to the allBlocksMap in clearLayoutRelationships so it will copy as expected now.

@rchlfryn rchlfryn requested a review from busbyk March 22, 2026 17:43
@rchlfryn rchlfryn linked an issue Mar 23, 2026 that may be closed by this pull request
Base automatically changed from endpoint-new-tenant to main March 24, 2026 12:51
@rchlfryn rchlfryn added this pull request to the merge queue Mar 25, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 25, 2026
@rchlfryn rchlfryn enabled auto-merge March 25, 2026 13:15
@rchlfryn rchlfryn added this pull request to the merge queue Mar 25, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 25, 2026
@rchlfryn rchlfryn enabled auto-merge March 25, 2026 13:57
@rchlfryn rchlfryn added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit 2f5b564 Mar 25, 2026
9 checks passed
@rchlfryn rchlfryn deleted the duplicate-to-enhance branch March 25, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate page to... enhancements

2 participants