Layout Builder Add Block filter doesn't update after changing a matching string to a shorter matching string

Created on 28 December 2019, over 4 years ago
Updated 6 February 2023, over 1 year ago

Problem/Motivation

In the "Choose a Block" form in the #drupal-off-canvas section, there's a field for filtering. You can see this in Drupal\Tests\layout_builder\FunctionalJavascript\BlockFilterTest.

It updates the list of visible blocks as you type into the filter textfield. So as you change the value from "a" to "ab" it updates. But if you change the value from "ab " to "ab" it doesn't (notice the space after the "b" in "ab ").

Expected, when you delete an errant space after your search string, it should trigger another round of filtering.
Actual, nothing happens when you remove the trailing space, and nothing is displayed, even if the string matches one of the links.

Video:
https://www.drupal.org/files/issues/2019-12-28/filtering-bug.mov

The logic here has a false assumption:

$categories
            .find(
              '.js-layout-builder-category:not(:has(.js-layout-builder-block-link:visible))',
            )
            .hide();

It assumes if a link isn't marked as 'display: none' it is visible, but that is dependent on the categories not being hidden. When you start from a place where they are all hidden, this fails to detect that the links are visible, and all the categories stay hidden.

Proposed resolution

Make sure all the categories are visible before filtering.

Remaining tasks

test coverage

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Closed: duplicate

Version

10.1

Component
Layout builder 

Last updated about 2 hours ago

Created by

🇺🇸United States oknate Greater New York City Area

Live updates comments and jobs are added and updated live.
  • Blocks-Layouts

    Blocks and Layouts Initiative. See the #2811175 Add layouts to Drupal issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

    Hiding #31 as that seems to be unrelevant to this issue

    Can confirm the issue still in D10

    This may also be solved with 🐛 Layout builder filter leaves blank space Fixed could someone test that patch out?

  • 🇮🇳India _utsavsharma

    Patch for 10.1.x.

  • Status changed to Needs work over 1 year ago
  • 🇮🇳India sonam.chaturvedi Pune

    Tested patch #35 on 10.1.x-dev. Patch does not apply cleanly.

    Checking patch core/modules/layout_builder/js/layout-builder.js...
    Checking patch core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php...
    error: while searching for:
        $this->assertCount(1, $visible_categories);
        $this->assertAnnounceContains('1 block is available in the modified list.');
    
        // Test Drupal.announce() message when no matches are present.
        $filter->setValue('Pan-Galactic Gargle Blaster');
        $visible_rows = $this->filterVisibleElements($blocks);
        $this->assertCount(0, $visible_rows);
        $visible_categories = $this->filterVisibleElements($categories);
        $this->assertCount(0, $visible_categories);
        $announce_element = $page->find('css', '#drupal-live-announce');
        $page->waitFor(2, function () use ($announce_element) {
          return str_starts_with($announce_element->getText(), '0 blocks are available');
        });
    
        // Test Drupal.announce() message when all blocks are listed.
        $filter->setValue('');
        $this->assertAnnounceContains('All available blocks are listed.');
    
    error: patch failed: core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php:108
    error: core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFilterTest.php: patch does not apply
    

    Needs work

  • 🇺🇸United States smustgrave

    Can you test 🐛 Layout builder filter leaves blank space Fixed to see if it solves your problem? When I tested over there it does. So this could maybe be marked a duplicate.

  • 🇮🇳India sonam.chaturvedi Pune

    Tested 🐛 Layout builder filter leaves blank space Fixed and it resolves the filtering issue on 10.1.x-dev.
    I have added my results in there.

  • Status changed to Closed: duplicate over 1 year ago
  • 🇺🇸United States smustgrave

    Thanks closing as duplicate and moving credit.

Production build 0.69.0 2024