Skip to content

Commit 5200d20

Browse files
committed
refactor(asset/ui): improve searchInputHandler container handling
- Fix no-ternary lint error by replacing ternary with if/else - Remove hardcoded .cs_container selector coupling - Eliminate redundant isSearchActive computation
1 parent a67b2be commit 5200d20

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

website/modules/asset/ui/src/searchInputHandler.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ const filterTags = function (
4040
filterValue,
4141
getLabel,
4242
defaultVisibleCount,
43+
isSearchActive,
4344
) {
4445
let hasVisible = false;
45-
const isSearchActive = filterValue.length > 0;
4646

4747
tagItems.forEach(function (tag, index) {
4848
if (isSearchActive) {
@@ -76,11 +76,10 @@ const removePreviousHandler = function (input) {
7676
}
7777
};
7878

79-
const getDefaultVisibleCount = function () {
80-
const csContainer = document.querySelector('.cs_container');
79+
const getDefaultVisibleCount = function (container) {
8180
let defaultVisibleCount = 5;
82-
if (csContainer) {
83-
const parsed = parseInt(csContainer.dataset.defaultVisibleTags, 10);
81+
if (container) {
82+
const parsed = parseInt(container.dataset.defaultVisibleTags, 10);
8483
if (parsed > 0) {
8584
defaultVisibleCount = parsed;
8685
}
@@ -99,8 +98,11 @@ const toggleShowMoreButtonVisibility = function (
9998
if (isSearchActive) {
10099
showMoreButton.style.display = 'none';
101100
} else {
102-
showMoreButton.style.display =
103-
totalTags > defaultVisibleCount ? 'flex' : 'none';
101+
if (totalTags > defaultVisibleCount) {
102+
showMoreButton.style.display = 'flex';
103+
} else {
104+
showMoreButton.style.display = 'none';
105+
}
104106
}
105107
}
106108
};
@@ -114,20 +116,20 @@ const setupTagSearchForInput = function (input, options) {
114116

115117
removePreviousHandler(input);
116118

117-
const defaultVisibleCount = getDefaultVisibleCount();
118-
119119
const handler = function () {
120120
const filterValue = input.value.trim().toLowerCase();
121121
const container = input.closest(containerSelector);
122122
if (!container) return;
123123

124+
const defaultVisibleCount = getDefaultVisibleCount(container);
124125
const tagItems = container.querySelectorAll(tagSelector);
125126
const isSearchActive = filterValue.length > 0;
126127
const hasVisible = filterTags(
127128
tagItems,
128129
filterValue,
129130
getTagLabelFn,
130131
defaultVisibleCount,
132+
isSearchActive,
131133
);
132134
toggleNoTagsMessage(container, hasVisible);
133135

0 commit comments

Comments
 (0)