Skip to content

Commit 33ea066

Browse files
committed
AC-12481: JS code optimised
1 parent 984293c commit 33ea066

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

app/code/Magento/CatalogSearch/view/adminhtml/web/js/search-engine-comment.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,21 @@ require([
1111

1212
$(function () {
1313
const engineField = $('#catalog_search_engine'),
14-
commentContainer = $('#row_catalog_search_engine p');
14+
commentContainer = $('#row_catalog_search_engine p'),
15+
defaultText = $.mage.__('If not specified, Default Search Engine will be used.'),
16+
unsupportedText = $.mage.__('This search engine option is no longer supported by Adobe. ' +
17+
'It is recommended to use OpenSearch as a search engine instead.'),
18+
updateCommentText = () => {
19+
const engineValue = engineField.val(),
20+
newCommentText = ['elasticsearch7', 'elasticsearch8'].includes(engineValue) ?
21+
unsupportedText : defaultText;
1522

16-
engineField.change(() => {
17-
const engineValue = engineField.val();
18-
let commentText = $.mage.__('If not specified, Default Search Engine will be used.');
23+
if (commentContainer.text() !== newCommentText) {
24+
commentContainer.text(newCommentText);
25+
}
26+
};
1927

20-
if (['elasticsearch7', 'elasticsearch8'].includes(engineValue)) {
21-
commentText = $.mage.__('This search engine option is no longer supported by Adobe. ' +
22-
'It is recommended to use OpenSearch as a search engine instead.');
23-
}
24-
25-
commentContainer.text(commentText);
26-
});
28+
engineField.change(updateCommentText);
29+
updateCommentText();
2730
});
2831
});

0 commit comments

Comments
 (0)