Problem/Motivation

Duplicate puts a copy next to the node, in the same root or slot. When that root or slot is full, the copy is refused with "There is no room left here.", from #3626659: Paste, duplicate and preset insert end in a server error when the target is full or gone. The contextual menu still offers Duplicate there, and so does the mod+d shortcut.

It always happens on the root node of a pattern preset: the root of a preset holds one node. It also happens on the root of an entity view override limited by its field, and in a slot whose component sets a maximum.

Nodes inside a slot with room left duplicate as before, in a preset builder too.

The builder already knows. Every limited dropzone carries data-max-items, the root and the slots, from ViewPanelBase::addDropzoneConstraints(). Drag and drop reads it: isDropzoneFull() in dropzone.js refuses a drop into a full dropzone before any request.

Steps to reproduce

  1. Open the builder of a pattern preset.
  2. Right-click its root node and choose Duplicate.
  3. The toast says there is no room left. Nothing told the user before the click.

Proposed resolution

  • Disable Duplicate in the contextual menu when the dropzone around the node is full, and say why in the item itself: "Duplicate: no room left here". The menu already rewrites the label of Paste and Remove when it opens, in updateMenuItems().
  • The reason is the item's text, not a tooltip. A tooltip needs a hover, which a keyboard user does not have and a disabled item may not react to.
  • mod+d keeps sending the request and showing the toast: there is no menu to carry the reason. A disabled state left by an earlier right-click must not swallow it.
  • One check shared with drag and drop, not a second copy of isDropzoneFull().
  • The server check and its toast stay: the screen can be out of date.
  • A Playwright test with a slot that has a maximum: Duplicate is enabled below it, and disabled with its reason once it is reached.

Remaining tasks

  • Settle the wording of the reason.
  • Decide whether Paste gets the same check on its destination. Paste is already disabled with no reason when nothing was copied: the same rule could cover it.

User interface changes

Duplicate is disabled where the copy has no room, and its label says so.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mogtofu33 created an issue. See original summary.

mogtofu33’s picture

pdureau’s picture

Assigned: Unassigned » pdureau

This is an issue more generic than being full or not.

We already have isDropzoneLocked(element) in dropzone.js which is only wrapping isDropzoneFull(element) for now, but there will be other mechanisms locking the dropzone (lock panel, SDC expected constraint...).

So, we must check isDropzoneLocked(element)

Settle the wording of the reason.

It is a good idea to add a message in the menu item but there will be many reasons for a slot to be locked, so I will propose something without message for now.

About keyboard shortcuts, I will let the "There is no room left here." message returned by ApiExceptionSubscriber to not mess with an adjacent scope.

Decide whether Paste gets the same check on its destination. Paste is already disabled with no reason when nothing was copied: the same rule could cover it.

Yes, it would be nice to address also "Paste" once "Duplicate" is OK.

How to test

We have a display_builder_test:test_slot_constraints component with maxItems: 2 in slot_1 to test.

The menu part:

Step Expectations Results
Drag a source in slot_1 The source must be added
Open the menu "Duplicate" must be available.
Duplicate. We now have twice the same source in the slot
Open the menu "Duplicate" must be disabled.
Drag a source out of the slot / Remove the source We now have a single source in the slot
Open the menu "Duplicate" must be available again.

There is also a keyboard shortcut part.

pdureau’s picture

Status: Active » Needs work

Duplicate is OK:

Step Expectations Results
Drag a source in slot_1 The source must be added ✅
Open the menu "Duplicate" must be available. ✅
Duplicate. We now have twice the same source in the slot ✅
Open the menu "Duplicate" must be disabled. ✅
Drag a source out of the slot / Remove the source We now have a single source in the slot ✅
Open the menu "Duplicate" must be available again. ✅

Let's try with "Paste" now.

pdureau’s picture

Assigned: pdureau » Unassigned
Status: Needs work » Needs review

"Paste" works too. The test steps are kind of the same as the "Duplicate" ones.

There are 2 removed lines to be careful about in the MR:

const pasteMenu = this.menu.querySelector('.menu__item[value="paste"]');
pasteMenu ? (pasteMenu.disabled = !copyInstance?.id) : '';

I am not sure why it was removed, but everything I tried work without them.

andres alvarez’s picture

I did some testing on MR !516 (commit 875278a) with display_builder_test:test_slot_constraints in Firefox.

- Slot with room: Duplicate and Paste are enabled.
- Full slot (slot_1, max 2): Duplicate and Paste are disabled. On 1.0.x both are offered and clicking Duplicate shows "There is no room left here."
- mod+d on a full slot still sends the request and shows the toast.
- Pattern preset root with 1 node and data-max-items=1: Duplicate is disabled.

pdureau’s picture

Thanks Andres. So is it OK ? If so, you can move to RTBC.

andres alvarez’s picture

Status: Needs review » Reviewed & tested by the community
andres alvarez’s picture

Thanks, pdureau. It's acceptable to me and I set it to RTBC. The suggestions in my previous comment are optional, mainly the test for mod+d on a full slot. The two removed Paste lines come from #3527510 and their condition now lives in the per-item loop, so I don't see a problem removing them. I didn't test Chromium or WebKit.

pdureau’s picture

Assigned: Unassigned » mogtofu33

Muchas gracias :)

mogtofu33’s picture

Assigned: mogtofu33 » Unassigned
Status: Reviewed & tested by the community » Fixed

Thanks a lot!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • mogtofu33 committed a3482d99 on 1.0.x authored by pdureau
    task: #3627023 Duplicate is offered where it can only fail: a full root...
pdureau’s picture

Status: Fixed » Closed (fixed)

Shipped in beta10 release.