From c65492386018c76c4eef8de2a0c6fc2a2bfdd1e1 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Wed, 11 Jan 2023 16:27:44 +0100 Subject: [PATCH] use tryExecuteAndNotify --- .../dashboard-health-check.element.ts | 2 +- .../health-check/health-check.context.ts | 38 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/dashboard-health-check.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/dashboard-health-check.element.ts index dd588a9c76..690c35e992 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/dashboard-health-check.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/dashboard-health-check.element.ts @@ -2,9 +2,9 @@ import { html, css, nothing } from 'lit'; import { customElement, state } from 'lit/decorators.js'; import { IRoute, IRoutingInfo, path } from 'router-slot'; import { UmbDashboardHealthCheckGroupElement } from './views/health-check-group'; +import { UmbHealthCheckDashboardContext } from './health-check-dashboard.context'; import { UmbLitElement } from '@umbraco-cms/element'; import { ManifestHealthCheck, umbExtensionsRegistry } from '@umbraco-cms/extensions-registry'; -import { UmbHealthCheckDashboardContext } from './health-check-dashboard.context'; @customElement('umb-dashboard-health-check') export class UmbDashboardHealthCheckElement extends UmbLitElement { diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts index e70e48856e..58c4c0fb4e 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts @@ -1,5 +1,7 @@ import { BehaviorSubject, Observable } from 'rxjs'; import { HealthCheckResource, HealthCheckWithResult } from '@umbraco-cms/backend-api'; +import { tryExecuteAndNotify } from '@umbraco-cms/resources'; +import { UmbControllerHostInterface } from 'src/core/controller/controller-host.mixin'; export class UmbHealthCheckContext { private _checks: BehaviorSubject> = new BehaviorSubject(>[]); @@ -8,32 +10,36 @@ export class UmbHealthCheckContext { private _results: BehaviorSubject> = new BehaviorSubject(>[]); public readonly results: Observable> = this._results.asObservable(); - public host = null; + public host: UmbControllerHostInterface; - constructor(host: any) { + constructor(host: UmbControllerHostInterface) { this.host = host; } async getGroupChecks(name: string) { - const response = await HealthCheckResource.getHealthCheckGroupByName({ name }); - response.checks?.forEach((check) => { - delete check.results; - }); + const { data } = await tryExecuteAndNotify(this.host, HealthCheckResource.getHealthCheckGroupByName({ name })); - this._checks.next(response.checks as HealthCheckWithResult[]); + if (data) { + data.checks?.forEach((check) => { + delete check.results; + }); + this._checks.next(data.checks as HealthCheckWithResult[]); + } } async checkGroup(name: string) { - const response = await HealthCheckResource.getHealthCheckGroupByName({ name }); + const { data } = await tryExecuteAndNotify(this.host, HealthCheckResource.getHealthCheckGroupByName({ name })); - const results = - response.checks?.map((check) => { - return { - key: check.key, - results: check.results, - }; - }) || []; + if (data) { + const results = + data.checks?.map((check) => { + return { + key: check.key, + results: check.results, + }; + }) || []; - this._results.next(results); + this._results.next(results); + } } }