Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ui_suite_bootstrap
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
ui_suite_bootstrap
Merge requests
!283
Issue
#3517904
by grimreaper: LB + LBB: Filter by block name broken
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3517904
by grimreaper: LB + LBB: Filter by block name broken
issue/ui_suite_bootstrap-3517904:3517904-lb-filter-by
into
5.1.x
Overview
0
Commits
3
Pipelines
4
Changes
5
Merged
Florent Torregrosa
requested to merge
issue/ui_suite_bootstrap-3517904:3517904-lb-filter-by
into
5.1.x
2 months ago
Overview
0
Commits
3
Pipelines
4
Changes
5
Expand
Closes
#3517904
0
0
Merge request reports
Compare
5.1.x
version 2
e7b91c2f
2 months ago
version 1
316240e0
2 months ago
5.1.x (base)
and
latest version
latest version
d5dee2fb
3 commits,
2 months ago
version 2
e7b91c2f
2 commits,
2 months ago
version 1
316240e0
1 commit,
2 months ago
5 files
+
201
−
82
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
assets/js/layout-builder/layout-builder.js
0 → 100644
+
112
−
0
Options
/**
* @file
* Attaches the behaviors for the Layout Builder module.
*/
((
$
,
Drupal
)
=>
{
const
{
behaviors
,
debounce
,
announce
,
formatPlural
}
=
Drupal
;
/*
* Boolean that tracks if block listing is currently being filtered. Declared
* outside of behaviors so value is retained on rebuild.
*/
let
layoutBuilderBlocksFiltered
=
false
;
/**
* Provides the ability to filter the block listing in "Add block" dialog.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attach block filtering behavior to "Add block" dialog.
*/
behaviors
.
layoutBuilderBlockFilter
=
{
attach
(
context
)
{
const
$categories
=
$
(
'
.js-layout-builder-categories
'
,
context
);
const
$filterLinks
=
$categories
.
find
(
'
.js-layout-builder-block-link
'
);
/**
* Filters the block list.
*
* @param {jQuery.Event} e
* The jQuery event for the keyup event that triggered the filter.
*/
const
filterBlockList
=
(
e
)
=>
{
const
query
=
e
.
target
.
value
.
toLowerCase
();
/**
* Shows or hides the block entry based on the query.
*
* @param {number} index
* The index in the loop, as provided by `jQuery.each`
* @param {HTMLElement} link
* The link to add the block.
*/
const
toggleBlockEntry
=
(
index
,
link
)
=>
{
const
$link
=
$
(
link
);
const
textMatch
=
link
.
textContent
.
toLowerCase
().
includes
(
query
);
// Checks if a category is currently hidden.
// Toggles the category on if so.
if
(
Drupal
.
elementIsHidden
(
$link
.
closest
(
'
.js-layout-builder-category
'
)[
0
],
)
)
{
$link
.
closest
(
'
.js-layout-builder-category
'
).
show
();
}
// Toggle the li tag of the matching link.
$link
.
parent
().
toggle
(
textMatch
);
};
// Filter if the length of the query is at least 2 characters.
if
(
query
.
length
>=
2
)
{
// Attribute to note which categories are closed before opening all.
$categories
.
find
(
'
.js-layout-builder-category .accordion-button.collapsed
'
)
.
attr
(
'
remember-closed
'
,
''
);
// Open all categories so every block is available to filtering.
$categories
.
find
(
'
.js-layout-builder-category .accordion-button.collapsed
'
)
.
click
();
// Toggle visibility of links based on query.
$filterLinks
.
each
(
toggleBlockEntry
);
// Only display categories containing visible links.
$categories
.
find
(
'
.js-layout-builder-category:not(:has(.js-layout-builder-block-link:visible))
'
,
)
.
hide
();
announce
(
formatPlural
(
$categories
.
find
(
'
.js-layout-builder-block-link:visible
'
).
length
,
'
1 block is available in the modified list.
'
,
'
@count blocks are available in the modified list.
'
,
),
);
layoutBuilderBlocksFiltered
=
true
;
}
else
if
(
layoutBuilderBlocksFiltered
)
{
layoutBuilderBlocksFiltered
=
false
;
// Re-open categories that were closed pre-filtering.
$categories
.
find
(
'
.js-layout-builder-category .accordion-button[remember-closed]
'
,
)
.
removeAttr
(
'
remember-closed
'
)
.
click
();
// Show all categories since filter is turned off.
$categories
.
find
(
'
.js-layout-builder-category
'
).
show
();
// Show all li tags since filter is turned off.
$filterLinks
.
parent
().
show
();
announce
(
Drupal
.
t
(
'
All available blocks are listed.
'
));
}
};
$
(
once
(
'
block-filter-text
'
,
'
input.js-layout-builder-filter
'
,
context
),
).
on
(
'
input
'
,
debounce
(
filterBlockList
,
200
));
},
};
})(
jQuery
,
Drupal
,
Sortable
);
Loading