From 9e0e67918fb2ec5388b9fe70379416315f7a5896 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Fri, 22 Sep 2023 15:19:24 +0200 Subject: [PATCH] [Editor] Report telemetry when closing the altText dialog with `Esc` (PR 16987 follow-up) The dialog element handles closing with Esc automatically, however we're not reporting telemetry in that case. In order to fix that the easiest solution, as far as I'm concerned, seem to be moving the telemetry reporting into the dialog-close handler since it's always invoked. --- web/alt_text_manager.js | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/web/alt_text_manager.js b/web/alt_text_manager.js index a572c95d8..f08a7badc 100644 --- a/web/alt_text_manager.js +++ b/web/alt_text_manager.js @@ -52,6 +52,8 @@ class AltTextManager { #container; + #telemetryData = null; + constructor( { dialog, @@ -76,7 +78,7 @@ class AltTextManager { this.#container = container; dialog.addEventListener("close", this.#close.bind(this)); - cancelButton.addEventListener("click", this.#cancel.bind(this)); + cancelButton.addEventListener("click", this.#finish.bind(this)); saveButton.addEventListener("click", this.#save.bind(this)); optionDescription.addEventListener("change", this.#boundUpdateUIState); optionDecorative.addEventListener("change", this.#boundUpdateUIState); @@ -240,22 +242,20 @@ class AltTextManager { } } - #cancel() { + #close() { this.#eventBus.dispatch("reporttelemetry", { source: this, details: { type: "editing", subtype: this.#currentEditor.editorType, - data: { + data: this.#telemetryData || { action: "alt_text_cancel", alt_text_keyboard: !this.#hasUsedPointer, }, }, }); - this.#finish(); - } + this.#telemetryData = null; - #close() { this.#removeOnClickListeners(); this.#uiManager?.addEditListeners(); this.#eventBus._off("resize", this.#boundSetPosition); @@ -274,21 +274,14 @@ class AltTextManager { altText, decorative, }; - this.#eventBus.dispatch("reporttelemetry", { - source: this, - details: { - type: "editing", - subtype: this.#currentEditor.editorType, - data: { - action: "alt_text_save", - alt_text_description: !!altText, - alt_text_edit: - !!this.#previousAltText && this.#previousAltText !== altText, - alt_text_decorative: decorative, - alt_text_keyboard: !this.#hasUsedPointer, - }, - }, - }); + this.#telemetryData = { + action: "alt_text_save", + alt_text_description: !!altText, + alt_text_edit: + !!this.#previousAltText && this.#previousAltText !== altText, + alt_text_decorative: decorative, + alt_text_keyboard: !this.#hasUsedPointer, + }; this.#finish(); }