From 2293a0e44d9a297cdcfdbf45d49b41d48ebf8cb3 Mon Sep 17 00:00:00 2001 From: Jacob Overgaard <752371+iOvergaard@users.noreply.github.com> Date: Wed, 9 Oct 2024 09:54:24 +0200 Subject: [PATCH] chore: fix sonarcloud issues and optimise contexts --- .../sysinfo/components/sysinfo.element.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/sysinfo/components/sysinfo.element.ts b/src/Umbraco.Web.UI.Client/src/packages/sysinfo/components/sysinfo.element.ts index 63dfb31984..4d2faef779 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/sysinfo/components/sysinfo.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/sysinfo/components/sysinfo.element.ts @@ -21,23 +21,17 @@ export class UmbSysinfoElement extends UmbModalBaseElement { @state() private _buttonState?: UUIButtonState; - #serverKeyValues: Array = []; - #sysinfoRepository = new UmbSysinfoRepository(this); - #notificationContext?: typeof UMB_NOTIFICATION_CONTEXT.TYPE; - - constructor() { - super(); - - this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => { - this.#notificationContext = context; - }); + readonly #serverKeyValues: Array = []; + readonly #sysinfoRepository = new UmbSysinfoRepository(this); + override connectedCallback(): void { + super.connectedCallback(); this.#populate(); } async #populate() { this._loading = true; - this.#serverKeyValues = []; + this.#serverKeyValues.length = 0; const [serverTroubleshooting, serverInformation] = await Promise.all([ this.#sysinfoRepository.requestTroubleShooting(), @@ -45,7 +39,7 @@ export class UmbSysinfoElement extends UmbModalBaseElement { ]); if (serverTroubleshooting) { - this.#serverKeyValues = serverTroubleshooting.items; + this.#serverKeyValues.push(...serverTroubleshooting.items); } if (serverInformation) { @@ -100,6 +94,8 @@ export class UmbSysinfoElement extends UmbModalBaseElement { } async #copyToClipboard() { + const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT); + try { this._buttonState = 'waiting'; const text = `Umbraco system information @@ -109,7 +105,7 @@ ${this._systemInformation}`; await navigator.clipboard.writeText(textAsCode); setTimeout(() => { - this.#notificationContext?.peek('positive', { + notificationContext?.peek('positive', { data: { headline: 'System information', message: this.localize.term('speechBubbles_copySuccessMessage'), @@ -119,7 +115,7 @@ ${this._systemInformation}`; }, 250); } catch { this._buttonState = 'failed'; - this.#notificationContext?.peek('danger', { + notificationContext?.peek('danger', { data: { headline: 'System information', message: this.localize.term('speechBubbles_cannotCopyInformation'),