Skip to content

Page Attachment can be copied to a Page where CTA already exists #3575

@miina

Description

@miina

Bug Description

Page Attachment can be copied to a Page where CTA already exists.

Expected Behaviour

Each Page can only have exactly 0 or 1 unmovable block. If either a CTA block or a Page Attachment block already exists on a Page then it should not be possible to Paste another unmovable block to that Page.

  • The Paste option should not appear in the context menu if Pasting the block is forbidden.
  • PasteHandler should consider Page Attachment block as well and prevent Pasting, currently, it does have a case but it does not handle it properly:
    case 'amp/amp-story-page-attachment':
    case 'amp/amp-story-cta':
    const currentBlock = getPageBlockByName( clientId, block.name );
    if ( currentBlock || ( isFirstPage && block.name === 'amp/amp-story-cta' ) ) {
    return;
    }
    allowedBlocks.push( block );
    break;

Steps to reproduce

  1. Add 2 Pages
  2. Add Page Attachment to the first Page
  3. Add CTA block to the second Page
  4. Right-click on the Page Attachment and choose "Copy" from the context menu
  5. Right-click on the second Page and choose "Paste" from the context menu.
  6. See both CTA block and Page Attachment block on the second Page.

Screenshots

Screenshot 2019-10-21 at 14 47 42

Additional context


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  1. When pasting, page attachment blocks should not be inserted when there already is another page attachment block on the page.
  2. When pasting, page attachment blocks should not be inserted when there already is a CTA block on the page.
  3. When pasting, CTA blocks should not be inserted when there already is another CTA block on the page.
  4. When pasting, CTA blocks should not be inserted when there already is a page attachment block on the page.

Implementation brief

  • Replace usage of ensureAllowedBlocksOnPaste with isBlockAllowedOnPage hook, as this check is more robust.

  • Remove all references to ensureAllowedBlocksOnPaste.

  • Check a block can not be pasted, display a 'snap' message to inform user the block could not be pasted.

QA testing instructions

  1. Add 2 Pages
  2. Add Page Attachment to the first Page
  3. Add CTA block to the second Page
  4. Right-click on the Page Attachment and choose "Copy" from the context menu
  5. Right-click on the second Page and choose "Paste" from the context menu.
  6. Verify that Page Attachment is not allowed on the second page and a snackbar with a notice appears.

Repeat with CTA block copied to page with Page Attachment and vice-versa.
Repeat with pasting via keyboard.

Demo

Changelog entry

  • Prevent pasting CTA or Page Attachment blocks when one already exists.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions