Skip to content

Commit 0782c48

Browse files
authored
action-list: Take items with css propery display:contents into account (#1038)
2 parents 8afbb73 + e7a67f8 commit 0782c48

File tree

1 file changed

+49
-12
lines changed

1 file changed

+49
-12
lines changed

public/js/action-list.js

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,7 @@
133133

134134
let dashboard = list.closest('.dashboard');
135135
if (dashboard) {
136-
dashboard.querySelectorAll('.action-list').forEach(otherList => {
137-
if (otherList !== list) {
138-
toDeactivateItems.push(..._this.getAllItems(otherList));
139-
}
140-
})
136+
_this.clearDashboardSelections(dashboard, list);
141137
}
142138

143139
let lastActivatedUrl = null;
@@ -151,11 +147,7 @@
151147

152148
_this.clearSelection(toDeactivateItems);
153149
_this.setActive(toActiveItems);
154-
155-
if (! dashboard) {
156-
_this.addSelectionCountToFooter(list);
157-
}
158-
150+
_this.addSelectionCountToFooter(list);
159151
_this.setLastActivatedItemUrl(lastActivatedUrl);
160152
_this.loadDetailUrl(list, target.matches('a') ? target.getAttribute('href') : null);
161153
}
@@ -166,7 +158,7 @@
166158
* @param list
167159
*/
168160
addSelectionCountToFooter(list) {
169-
if (! list.matches('[data-icinga-multiselect-url]')) {
161+
if (! list.matches('[data-icinga-multiselect-url]') || list.closest('.dashboard')) {
170162
return;
171163
}
172164

@@ -208,6 +200,8 @@
208200
/**
209201
* Key navigation for .action-list
210202
*
203+
* Only for primary lists (dashboard or lists in detail view are not taken into account)
204+
*
211205
* - `Shift + ArrowUp|ArrowDown` = Multiselect
212206
* - `ArrowUp|ArrowDown` = Select next/previous
213207
* - `Ctrl|cmd + A` = Select all on currect page
@@ -432,14 +426,28 @@
432426
* @param pressedKey Pressed key (`ArrowUp` or `ArrowDown`)
433427
*/
434428
scrollItemIntoView(item, pressedKey) {
435-
item.scrollIntoView({block: "nearest"});
436429
let directionalNext = this.getDirectionalNext(item, pressedKey);
437430

431+
if ("isDisplayContents" in item.parentElement.dataset) {
432+
item = item.firstChild;
433+
directionalNext = directionalNext ? directionalNext.firstChild : null;
434+
}
435+
// required when ArrowUp is pressed in new list OR after selecting all items with ctrl+A
436+
item.scrollIntoView({block: "nearest"});
437+
438438
if (directionalNext) {
439439
directionalNext.scrollIntoView({block: "nearest"});
440440
}
441441
}
442442

443+
clearDashboardSelections(dashboard, currentList) {
444+
dashboard.querySelectorAll('.action-list').forEach(otherList => {
445+
if (otherList !== currentList) {
446+
this.clearSelection(this.getActiveItems(otherList));
447+
}
448+
})
449+
}
450+
443451
/**
444452
* Load the detail url with selected items
445453
*
@@ -737,6 +745,30 @@
737745
list = _this.findDetailUrlActionList(container);
738746
}
739747

748+
if (! list || ! ("isDisplayContents" in list.dataset)) {
749+
// no detail view || ignore when already set
750+
let actionLists = null;
751+
if (! list) {
752+
actionLists = document.querySelectorAll('.action-list');
753+
} else {
754+
actionLists = [list];
755+
}
756+
757+
for (let actionList of actionLists) {
758+
let firstSelectableItem = actionList.querySelector(':scope > [data-action-item]');
759+
if (
760+
firstSelectableItem
761+
&& (
762+
! firstSelectableItem.checkVisibility()
763+
&& firstSelectableItem.firstChild
764+
&& firstSelectableItem.firstChild.checkVisibility()
765+
)
766+
) {
767+
actionList.dataset.isDisplayContents = "";
768+
}
769+
}
770+
}
771+
740772
if (list && list.matches('[data-icinga-multiselect-url], [data-icinga-detail-url]')) {
741773
let detailUrl = _this.icinga.utils.parseUrl(
742774
_this.icinga.history.getCol2State().replace(/^#!/, '')
@@ -762,6 +794,11 @@
762794
}
763795
}
764796

797+
let dashboard = list.closest('.dashboard');
798+
if (dashboard) {
799+
_this.clearDashboardSelections(dashboard, list);
800+
}
801+
765802
_this.clearSelection(_this.getAllItems(list).filter(item => !toActiveItems.includes(item)));
766803
_this.setActive(toActiveItems);
767804
}

0 commit comments

Comments
 (0)