Skip to content

Commit fe07fd7

Browse files
committed
Improve the UX when loading options and when there are no options
1 parent 99c5726 commit fe07fd7

File tree

3 files changed

+48
-12
lines changed

3 files changed

+48
-12
lines changed

ts/WoltLabSuite/Core/Component/GridView/Selection.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getStoragePrefix } from "WoltLabSuite/Core/Core";
22
import DomUtil from "WoltLabSuite/Core/Dom/Util";
33
import { wheneverFirstSeen } from "WoltLabSuite/Core/Helper/Selector";
4-
import { getDropdownMenu } from "WoltLabSuite/Core/Ui/Dropdown/Simple";
4+
import { getDropdownMenu, setAlignmentById } from "WoltLabSuite/Core/Ui/Dropdown/Simple";
55

66
// eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
77
export class Selection extends EventTarget {
@@ -10,6 +10,7 @@ export class Selection extends EventTarget {
1010
readonly #selectionBar: HTMLElement | null = null;
1111
readonly #bulkInteractionButton: HTMLButtonElement | null = null;
1212
#bulkInteractionsPlaceholder: HTMLLIElement | null = null;
13+
#bulkInteractionsLoadingDelay: number | undefined = undefined;
1314

1415
constructor(gridId: string, table: HTMLTableElement) {
1516
super();
@@ -172,6 +173,16 @@ export class Selection extends EventTarget {
172173
}
173174

174175
this.dispatchEvent(new CustomEvent("getBulkInteractions", { detail: { objectIds: this.getSelectedIds() } }));
176+
177+
if (this.#bulkInteractionsLoadingDelay !== undefined) {
178+
window.clearTimeout(this.#bulkInteractionsLoadingDelay);
179+
}
180+
181+
// Delays the display of the available actions to prevent flicker and to
182+
// smooth out the UX.
183+
this.#bulkInteractionsLoadingDelay = window.setTimeout(() => {
184+
this.#bulkInteractionsLoadingDelay = undefined;
185+
}, 200);
175186
}
176187

177188
setBulkInteractionContextMenuOptions(options: string): void {
@@ -185,14 +196,23 @@ export class Selection extends EventTarget {
185196
return;
186197
}
187198

188-
const menu = getDropdownMenu(this.#bulkInteractionButton!.parentElement!.id);
199+
if (this.#bulkInteractionsLoadingDelay !== undefined && fragment !== undefined) {
200+
// The server has already replied but the delay isn't over yet.
201+
window.setTimeout(() => {
202+
this.#rebuildBulkInteractions(fragment);
203+
}, 20);
204+
205+
return;
206+
}
207+
208+
const menuId = this.#bulkInteractionButton!.parentElement!.id;
209+
const menu = getDropdownMenu(menuId);
189210
if (menu === undefined) {
190211
throw new Error("Could not find the dropdown menu for " + this.#bulkInteractionButton!.id);
191212
}
192213

193214
const dividers = Array.from(menu.querySelectorAll<HTMLElement>(".dropdownDivider"));
194215
const lastDivider = dividers[dividers.length - 1];
195-
lastDivider.hidden = false;
196216

197217
if (fragment === undefined) {
198218
while (lastDivider.previousElementSibling !== null) {
@@ -208,11 +228,9 @@ export class Selection extends EventTarget {
208228
}
209229

210230
menu.prepend(fragment);
211-
212-
if (lastDivider.previousElementSibling === null) {
213-
lastDivider.hidden = true;
214-
}
215231
}
232+
233+
setAlignmentById(menuId);
216234
}
217235

218236
#resetSelection(): void {

wcfsetup/install/files/js/WoltLabSuite/Core/Component/GridView/Selection.js

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/system/interaction/bulk/BulkInteractionContextMenuView.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public function renderContextMenuOptions(array $objects): string
3232
}
3333
}
3434

35+
if ($html === '') {
36+
$html = '<li class="disabled"><span>TODO: Keine Aktionen verfügbar</span></li>';
37+
}
38+
3539
return $html;
3640
}
3741

0 commit comments

Comments
 (0)