Add Slug Parameter to Action Loader for Programmatic Identification (#5490) * feat: add slug parameter to action-loader for programmatic identification Add optional `slug` parameter to ActionLoaderHandle for easier identification via code or CSS. Update all loader.show() calls across the codebase to include descriptive slugs ('app-init', 'chat-rename', 'chat-delete', 'bulk-delete', 'chat-load', 'image-generation', 'legacy-loader'). Add data attributes (data-slug, data-loader-id, data-blocking) to toast content div. Expose slug via getter and make id private with getter. * Apply suggestions from code review Fix slug jsdoc wording Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * fix: Add identifier to second loader in img gen --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
Signed| @@ -717,6 +717,7 @@ async function firstLoadInit() { | ||
| 717 | 717 | initLoaderOverlay.appendChild(splashMessage); |
| 718 | 718 | |
| 719 | 719 | const initLoaderHandle = loader.show({ |
| 720 | + slug: 'app-init', | |
| 720 | 721 | toastMode: loader.ToastMode.NONE, |
| 721 | 722 | overlayContent: initLoaderOverlay, |
| 722 | 723 | }); |
| @@ -10592,6 +10593,7 @@ export async function renameGroupOrCharacterChat({ characterId, groupId, oldFile | ||
| 10592 | 10593 | } |
| 10593 | 10594 | |
| 10594 | 10595 | const loaderHandle = showLoader ? loader.show({ |
| 10596 | + slug: 'chat-rename', | |
| 10595 | 10597 | title: t`Rename Chat`, |
| 10596 | 10598 | message: t`Renaming chat…`, |
| 10597 | 10599 | toastMode: loader.ToastMode.STATIC, |
| @@ -11196,6 +11198,7 @@ jQuery(async function () { | ||
| 11196 | 11198 | $('#select_chat_cross').trigger('click'); |
| 11197 | 11199 | |
| 11198 | 11200 | const loaderHandle = loader.show({ |
| 11201 | + slug: 'chat-delete', | |
| 11199 | 11202 | title: t`Delete Chat`, |
| 11200 | 11203 | message: t`Deleting chat…`, |
| 11201 | 11204 | toastMode: loader.ToastMode.STATIC, |
| @@ -848,6 +848,7 @@ class BulkEditOverlay { | ||
| 848 | 848 | const deleteChats = checkbox.prop('checked') ?? false; |
| 849 | 849 | |
| 850 | 850 | const loaderHandle = loader.show({ |
| 851 | + slug: 'bulk-delete', | |
| 851 | 852 | title: t`Bulk Delete`, |
| 852 | 853 | message: t`Deleting ${characterIds.length} character(s)…`, |
| 853 | 854 | toastMode: loader.ToastMode.STATIC, |
| @@ -1,4 +1,4 @@ | ||
| 1 | 1 | import { ActionLoaderToastMode, getActiveLoaderHandles, getLoaderHandleById, hideActionLoader, showActionLoaderloader } from './action-loader.js'; |
| 2 | 2 | import { t } from './i18n.js'; |
| 3 | 3 | import { SlashCommand } from './slash-commands/SlashCommand.js'; |
| 4 | 4 | import { SlashCommandNamedArgument, ARGUMENT_TYPE, SlashCommandArgument } from './slash-commands/SlashCommandArgument.js'; |
| @@ -116,6 +116,12 @@ export function registerActionLoaderSlashCommands() { | ||
| 116 | 116 | typeList: [ARGUMENT_TYPE.STRING], |
| 117 | 117 | }), |
| 118 | 118 | SlashCommandNamedArgument.fromProps({ |
| 119 | + name: 'slug', | |
| 120 | + description: 'Unique slug for the loader (to identify it easily via code or CSS)', | |
| 121 | + typeList: [ARGUMENT_TYPE.STRING], | |
| 122 | + defaultValue: 'slash-wrap', | |
| 123 | + }), | |
| 124 | + SlashCommandNamedArgument.fromProps({ | |
| 119 | 125 | name: 'stopTooltip', |
| 120 | 126 | description: 'Tooltip text for the stop button (only used when toast=stoppable)', |
| 121 | 127 | typeList: [ARGUMENT_TYPE.STRING], |
| @@ -148,7 +154,8 @@ export function registerActionLoaderSlashCommands() { | ||
| 148 | 154 | const title = args.title ? String(args.title) : ''; |
| 149 | 155 | const stopTooltip = String(args.stopTooltip ?? t`Stop`); |
| 150 | 156 | |
| 151 | 157 | const loaderactionLoader = showActionLoaderloader.show({ |
| 158 | + slug: typeof args.slug === 'string' ? String(args.slug) : 'slash-wrap', | |
| 152 | 159 | blocking, |
| 153 | 160 | toastMode, |
| 154 | 161 | message, |
| @@ -162,7 +169,7 @@ export function registerActionLoaderSlashCommands() { | ||
| 162 | 169 | const result = await closureCopy.execute(); |
| 163 | 170 | return result.pipe; |
| 164 | 171 | } finally { |
| 165 | 172 | await loaderactionLoader.hide(); |
| 166 | 173 | } |
| 167 | 174 | }, |
| 168 | 175 | })); |
| @@ -232,6 +239,12 @@ export function registerActionLoaderSlashCommands() { | ||
| 232 | 239 | typeList: [ARGUMENT_TYPE.STRING], |
| 233 | 240 | }), |
| 234 | 241 | SlashCommandNamedArgument.fromProps({ |
| 242 | + name: 'slug', | |
| 243 | + description: 'Unique slug for the loader (to identify it easily via code or CSS)', | |
| 244 | + typeList: [ARGUMENT_TYPE.STRING], | |
| 245 | + defaultValue: 'slash-show', | |
| 246 | + }), | |
| 247 | + SlashCommandNamedArgument.fromProps({ | |
| 235 | 248 | name: 'stopTooltip', |
| 236 | 249 | description: 'Tooltip text for the stop button (only used when toast=stoppable)', |
| 237 | 250 | typeList: [ARGUMENT_TYPE.STRING], |
| @@ -258,7 +271,8 @@ export function registerActionLoaderSlashCommands() { | ||
| 258 | 271 | const title = args.title ? String(args.title) : ''; |
| 259 | 272 | const stopTooltip = String(args.stopTooltip ?? t`Stop`); |
| 260 | 273 | |
| 261 | 274 | const handle = showActionLoaderloader.show({ |
| 275 | + slug: typeof args.slug === 'string' ? String(args.slug) : 'slash-show', | |
| 262 | 276 | blocking, |
| 263 | 277 | toastMode, |
| 264 | 278 | message, |
| @@ -307,7 +321,7 @@ export function registerActionLoaderSlashCommands() { | ||
| 307 | 321 | } |
| 308 | 322 | |
| 309 | 323 | // No handle provided - hide all active loaders |
| 310 | 324 | const result = await hideActionLoaderloader.hide(); |
| 311 | 325 | return result ? 'true' : 'false'; |
| 312 | 326 | }, |
| 313 | 327 | })); |
| @@ -33,6 +33,7 @@ export const ActionLoaderToastMode = { | ||
| 33 | 33 | * @typedef {object} ActionLoaderOptions |
| 34 | 34 | * @property {boolean} [blocking=true] - Whether to show the blocking overlay. Set to false for non-blocking toast-only loaders. |
| 35 | 35 | * @property {ActionLoaderToastMode} [toastMode='stoppable'] - Toast display mode |
| 36 | + * @property {string} [slug=null] - Unique slug for the loader to identify it easily via code or CSS | |
| 36 | 37 | * @property {string} [message='Generating...'] - The message to display in the toast |
| 37 | 38 | * @property {string} [title] - Optional title for the toast notification |
| 38 | 39 | * @property {string} [stopTooltip='Stop'] - Tooltip text for the stop button |
| @@ -83,7 +84,10 @@ export class ActionLoaderHandle { | ||
| 83 | 84 | } |
| 84 | 85 | |
| 85 | 86 | /** @type {string} Unique identifier for this handle */ |
| 86 | 87 | #id; |
| 88 | + | |
| 89 | + /** @type {string|null} Unique slug for the loader */ | |
| 90 | + #slug = null; | |
| 87 | 91 | |
| 88 | 92 | /** @type {JQuery<HTMLElement>|null} The toast element for this loader */ |
| 89 | 93 | #toast = null; |
| @@ -105,6 +109,7 @@ export class ActionLoaderHandle { | ||
| 105 | 109 | * @param {object} options - Configuration options |
| 106 | 110 | * @param {boolean} [options.blocking=true] - Whether to show blocking overlay |
| 107 | 111 | * @param {ActionLoaderToastMode} [options.toastMode] - Toast display mode |
| 112 | + * @param {string|null} [options.slug] - Unique slug for the loader (to identify it easily via code or CSS) | |
| 108 | 113 | * @param {string} [options.message='Generating...'] - Message to display in the toast |
| 109 | 114 | * @param {string} [options.title] - Title for the toast notification |
| 110 | 115 | * @param {string} [options.stopTooltip='Stop'] - Tooltip for the stop button |
| @@ -116,6 +121,7 @@ export class ActionLoaderHandle { | ||
| 116 | 121 | constructor({ |
| 117 | 122 | blocking = true, |
| 118 | 123 | toastMode = ActionLoaderToastMode.STOPPABLE, |
| 124 | + slug = null, | |
| 119 | 125 | message = t`Generating...`, |
| 120 | 126 | title = '', |
| 121 | 127 | stopTooltip = t`Stop`, |
| @@ -129,7 +135,8 @@ export class ActionLoaderHandle { | ||
| 129 | 135 | return; |
| 130 | 136 | } |
| 131 | 137 | |
| 132 | 138 | this.#id = generateLoaderId(); |
| 139 | + this.#slug = slug; | |
| 133 | 140 | this.#blocking = blocking; |
| 134 | 141 | this.#onStop = onStop; |
| 135 | 142 | this.#onHide = onHide; |
| @@ -164,6 +171,12 @@ export class ActionLoaderHandle { | ||
| 164 | 171 | const toastContent = document.createElement('div'); |
| 165 | 172 | toastContent.className = 'action-loader-toast'; |
| 166 | 173 | |
| 174 | + if (this.#slug) { | |
| 175 | + toastContent.dataset.slug = this.#slug; | |
| 176 | + } | |
| 177 | + toastContent.dataset.loaderId = this.#id; | |
| 178 | + toastContent.dataset.blocking = this.#blocking.toString(); | |
| 179 | + | |
| 167 | 180 | const messageSpan = document.createElement('span'); |
| 168 | 181 | messageSpan.className = 'action-loader-message'; |
| 169 | 182 | messageSpan.textContent = message; |
| @@ -218,6 +231,22 @@ export class ActionLoaderHandle { | ||
| 218 | 231 | } |
| 219 | 232 | |
| 220 | 233 | /** |
| 234 | + * The unique identifier for this loader handle. | |
| 235 | + * @returns {string} | |
| 236 | + */ | |
| 237 | + get id() { | |
| 238 | + return this.#id; | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** | |
| 242 | + * The unique slug for this loader handle, used to identify it easily via code or CSS. | |
| 243 | + * @returns {string|null} | |
| 244 | + */ | |
| 245 | + get slug() { | |
| 246 | + return this.#slug; | |
| 247 | + } | |
| 248 | + | |
| 249 | + /** | |
| 221 | 250 | * Whether this handle is still active (not disposed). |
| 222 | 251 | * @returns {boolean} |
| 223 | 252 | */ |
| @@ -700,6 +700,7 @@ export function initBookmarks() { | ||
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | const loaderHandle = loader.show({ |
| 703 | + slug: 'chat-load', | |
| 703 | 704 | title: t`Chat History`, |
| 704 | 705 | message: t`Loading chat…`, |
| 705 | 706 | toastMode: loader.ToastMode.STATIC, |
| @@ -3061,6 +3061,7 @@ async function generatePicture(initiator, args, trigger, message, callback) { | ||
| 3061 | 3061 | // Show non-blocking stoppable toast for this generation |
| 3062 | 3062 | loaderHandle = loader.show({ |
| 3063 | 3063 | blocking: false, |
| 3064 | + slug: `${MODULE_NAME}-image-generation`, | |
| 3064 | 3065 | title: t`Image Generation`, |
| 3065 | 3066 | message: t`Generating an image...`, |
| 3066 | 3067 | onStop: stopListener, |
| @@ -5300,6 +5301,7 @@ async function generateMediaSwipe(mediaAttachment, message, onStart, onComplete, | ||
| 5300 | 5301 | // Show non-blocking stoppable toast for this generation |
| 5301 | 5302 | loaderHandle = loader.show({ |
| 5302 | 5303 | blocking: false, |
| 5304 | + slug: `${MODULE_NAME}-image-generation`, | |
| 5303 | 5305 | title: t`Image Generation`, |
| 5304 | 5306 | message: t`Generating an image...`, |
| 5305 | 5307 | onStop: stopListener, |
| @@ -28,6 +28,7 @@ export function showLoader() { | ||
| 28 | 28 | |
| 29 | 29 | // Create a blocking loader with no toast (matches old behavior) |
| 30 | 30 | legacyLoaderHandle = loader.show({ |
| 31 | + slug: 'legacy-loader', | |
| 31 | 32 | blocking: true, |
| 32 | 33 | toastMode: loader.ToastMode.NONE, |
| 33 | 34 | }); |