11import { getStoragePrefix } from "WoltLabSuite/Core/Core" ;
22import DomUtil from "WoltLabSuite/Core/Dom/Util" ;
33import { 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
77export 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 {
0 commit comments