From b68eea42867275a7d84c60265924da16eea45cb7 Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 29 Jul 2024 10:46:40 +0200 Subject: [PATCH] ActionList: getDirectionNext(): Return list's first/last elem if null is passed as item --- asset/js/widget/ActionList.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/asset/js/widget/ActionList.js b/asset/js/widget/ActionList.js index 17038465..4772b4aa 100644 --- a/asset/js/widget/ActionList.js +++ b/asset/js/widget/ActionList.js @@ -262,29 +262,17 @@ define(["../notjQuery"], function ($) { `[data-icinga-detail-filter="${ this.lastActivatedItemUrl }"]` ); - if (! lastActivatedItem && activeItems.length) { - lastActivatedItem = activeItems[activeItems.length - 1]; - } - let directionalNextItem = this.getDirectionalNext(lastActivatedItem, event.key); if (activeItems.length === 0) { - toActiveItem = pressedArrowDownKey ? firstListItem : lastListItem; + toActiveItem = directionalNextItem; // reset all on manual page refresh this.clearSelection(activeItems); } else if (this.isMultiSelectable && event.shiftKey) { if (activeItems.length === 1) { toActiveItem = directionalNextItem; - } else if (wasAllSelected && ( - (lastActivatedItem !== firstListItem && pressedArrowDownKey) - || (lastActivatedItem !== lastListItem && pressedArrowUpKey) - )) { - if (pressedArrowDownKey) { - toActiveItem = lastActivatedItem === lastListItem ? null : lastListItem; - } else { - toActiveItem = lastActivatedItem === firstListItem ? null : lastListItem; - } - + } else if (wasAllSelected && (lastActivatedItem !== firstListItem && pressedArrowDownKey)) { + toActiveItem = lastActivatedItem === lastListItem ? null : lastListItem; } else if (directionalNextItem && directionalNextItem.classList.contains('active')) { // deactivate last activated by down to up select this.clearSelection([lastActivatedItem]); @@ -327,7 +315,11 @@ define(["../notjQuery"], function ($) { */ getDirectionalNext(item, eventKey) { if (! item) { - return null; + item = eventKey === 'ArrowUp' ? this.list.lastChild : this.list.firstChild; + + if (item && item.hasAttribute(this.removeBrackets(LIST_ITEM_IDENTIFIER))) { + return item; + } } let nextItem = null;