From fd99208cc81a7d72cc671d1ca284b844d50c717d Mon Sep 17 00:00:00 2001 From: Lone Iversen <108085781+loivsen@users.noreply.github.com> Date: Wed, 11 Jan 2023 11:01:22 +0100 Subject: [PATCH] create manifest from server response --- .../health-check-group-two.element.ts | 91 ------------------- .../health-check-overview-group.element.ts | 67 ++++++++++++++ .../health-check/health-check.context.ts | 29 ++++++ .../dashboards/health-check/manifests.ts | 29 +++++- .../health-check/views/health-check-group.ts | 30 +++--- .../views/health-check-overview.ts | 27 +----- .../extension-slot/extension-slot.element.ts | 2 +- 7 files changed, 142 insertions(+), 133 deletions(-) delete mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-group-two.element.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-overview-group.element.ts create mode 100644 src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-group-two.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-group-two.element.ts deleted file mode 100644 index 70b6f8b677..0000000000 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-group-two.element.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { UUITextStyles } from '@umbraco-ui/uui-css/lib'; -import { css, html, LitElement, nothing } from 'lit'; -import { customElement, property, state } from 'lit/decorators.js'; -import type { ManifestHealthCheck } from '@umbraco-cms/models'; -import { StatusResultType } from '@umbraco-cms/backend-api'; - -@customElement('umb-health-check-group-two') -export class UmbSecurityHealthCheckGroupTwoElement extends LitElement { - static styles = [UUITextStyles, css``]; - - @property({ type: Object }) - manifest?: ManifestHealthCheck; - - @state() - private _checkResponse? = []; - - private async checkGroup() { - console.log('group checked'); - - // Default options are marked with * - const url = '/umbraco/management/api/v1/health-check/Security/'; - const response = await fetch(url, { - method: 'GET', // *GET, POST, PUT, DELETE, etc. - mode: 'cors', // no-cors, *cors, same-origin - cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached - credentials: 'same-origin', // include, *same-origin, omit - headers: { - 'Content-Type': 'application/json', - // 'Content-Type': 'application/x-www-form-urlencoded', - }, - }); - - this._checkResponse = await response.json(); // parses JSON response into native JavaScript objects - console.log(this._checkResponse); - } - - render() { - return html` - -
- ${this.manifest?.meta.label} - Check group -
-
- ${this.manifest?.meta.checks.map((check) => { - return html` -

${check.description}

- ${this.renderCheckResults(check.alias)} -
`; - })} -
-
- `; - } - - renderCheckResults(alias: string) { - const checkResults = this._checkResponse?.find((result: any) => result.alias === alias); - return html` -
- ${checkResults?.results.map((result: any) => { - return html`
-

${this.renderIcon(result.resultType)} ${result.message}

- ${result.readMoreLink ? html`Read more` : nothing} -
`; - })} -
-
`; - } - - private renderIcon(type?: StatusResultType) { - switch (type) { - case 'Success': - return html``; - case 'Warning': - return html``; - case 'Error': - return html``; - case 'Info': - return html``; - default: - return nothing; - } - } -} - -export default UmbSecurityHealthCheckGroupTwoElement; -declare global { - interface HTMLElementTagNameMap { - 'umb-health-check-group-two': UmbSecurityHealthCheckGroupTwoElement; - } -} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-overview-group.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-overview-group.element.ts new file mode 100644 index 0000000000..9503442677 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check-overview-group.element.ts @@ -0,0 +1,67 @@ +import { UUITextStyles } from '@umbraco-ui/uui-css/lib'; +import { css, html, nothing } from 'lit'; +import { customElement, property, state } from 'lit/decorators.js'; +import { UmbHealthCheckContext } from './health-check.context'; +import type { ManifestHealthCheck } from '@umbraco-cms/models'; +import { StatusResultType } from '@umbraco-cms/backend-api'; +import { UmbLitElement } from '@umbraco-cms/element'; + +@customElement('umb-health-check-overview-group') +export class UmbHealthCheckOverviewGroupElement extends UmbLitElement { + static styles = [ + UUITextStyles, + css` + .group-box { + position: relative; + } + + .group-box:hover::after { + content: ''; + width: 100%; + height: 100%; + position: absolute; + top: 0; + bottom: 0; + left: 0; + right: 0; + border-radius: var(--uui-border-radius); + transition: opacity 100ms ease-out 0s; + opacity: 0.33; + outline-color: var(--uui-color-selected); + outline-width: 4px; + outline-style: solid; + } + + a { + text-align: center; + font-weight: bold; + cursor: pointer; + text-decoration: none; + color: var(--uui-color-text); + margin-bottom: 10px; + display: block; + } + `, + ]; + + @property({ type: Object }) + manifest?: ManifestHealthCheck; + + @state() + private _checkResponse? = []; + + private _healthCheckContext?: UmbHealthCheckContext; + + render() { + return html` + ${this.manifest?.meta.label} + `; + } +} + +export default UmbHealthCheckOverviewGroupElement; +declare global { + interface HTMLElementTagNameMap { + 'umb-health-check-overview-group': UmbHealthCheckOverviewGroupElement; + } +} 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 new file mode 100644 index 0000000000..3f66d45bc9 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/health-check.context.ts @@ -0,0 +1,29 @@ +import { HealthCheckResource } from '@umbraco-cms/backend-api'; +import { UmbControllerHostInterface } from 'src/core/controller/controller-host.mixin'; + +export class UmbHealthCheckContext { + host = null; + constructor(host: any) { + this.host = host; + } + async checkGroup(name: string) { + const response = await HealthCheckResource.getHealthCheckGroupByName({ name }); + + const results = response.checks?.map((check) => { + return { + key: check.key, + results: check.results, + }; + }); + + if (response) return results; + } + + async getGroupChecks(name: string) { + const response = await HealthCheckResource.getHealthCheckGroupByName({ name }); + response.checks?.forEach((check) => { + delete check.results; + }); + if (response) return response.checks; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/manifests.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/manifests.ts index 4d16387a78..1c6435790a 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/manifests.ts @@ -1,5 +1,30 @@ +import { HealthCheckGroup, HealthCheckResource } from '@umbraco-cms/backend-api'; import type { ManifestHealthCheck } from '@umbraco-cms/models'; +const _getAllGroups = async () => { + const response = await HealthCheckResource.getHealthCheckGroup({ skip: 0, take: 9999 }); + return response.items; +}; +const groups: HealthCheckGroup[] = await _getAllGroups(); + +const _createManifests = (groups: HealthCheckGroup[]) => { + return groups.map((group) => { + return { + type: 'healthCheck', + alias: `Umb.HealthCheck.${group.name}`, + name: `${group.name} Health Check`, + weight: 500, + meta: { + label: group.name, + checks: [], + }, + }; + }); +}; + +const healthChecks = _createManifests(groups); + +/* const healthchecks: Array = [ { type: 'healthCheck', @@ -76,6 +101,6 @@ const healthchecks: Array = [ ], }, }, -]; +];*/ -export const manifests = [...healthchecks]; +export const manifests = [...healthChecks]; diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-group.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-group.ts index d9ce7ca8b4..f8f207a702 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-group.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-group.ts @@ -15,6 +15,7 @@ import { import { UmbLitElement } from '@umbraco-cms/element'; import { tryExecuteAndNotify } from '@umbraco-cms/resources'; +import { UmbHealthCheckContext } from '../health-check.context'; @customElement('umb-dashboard-health-check-group') export class UmbDashboardHealthCheckGroupElement extends UmbLitElement { @@ -108,9 +109,13 @@ export class UmbDashboardHealthCheckGroupElement extends UmbLitElement { @state() private _group?: HealthCheckGroupWithResult; - constructor() { - super(); - } + private _healthCheckContext = new UmbHealthCheckContext(this); + + @state() + private _checks?: HealthCheckWithResult[] | null; + + @state() + private _keyResults?: any; connectedCallback(): void { super.connectedCallback(); @@ -118,18 +123,13 @@ export class UmbDashboardHealthCheckGroupElement extends UmbLitElement { } private async _getGroup(name: string) { - const { data } = await tryExecuteAndNotify(this, HealthCheckResource.getHealthCheckGroupByName({ name })); - if (data) this._group = data; + this._checks = await this._healthCheckContext.getGroupChecks(name); + this._group = { name: this.groupName, checks: this._checks }; } private async _buttonHandler() { this._buttonState = 'waiting'; - this._getChecks(decodeURI(this.groupName)); - } - private async _getChecks(name: string) { - await new Promise((resolve) => setTimeout(resolve, (Math.random() + 1) * 1000)); - const { data } = await tryExecuteAndNotify(this, HealthCheckResource.getHealthCheckGroupByName({ name })); - if (data) this._group = data; + this._keyResults = await this._healthCheckContext.checkGroup(decodeURI(this.groupName)); this._buttonState = 'success'; } @@ -147,7 +147,7 @@ export class UmbDashboardHealthCheckGroupElement extends UmbLitElement { ${this._group.checks?.map((check) => { return html`

${check.description}

- ${check.results ? this.renderCheckResults(check.results) : nothing} + ${check.key ? this.renderCheckResults(check.key) : nothing}
`; })} @@ -156,14 +156,14 @@ export class UmbDashboardHealthCheckGroupElement extends UmbLitElement { } else return nothing; } - renderCheckResults(results: HealthCheckResult[]) { + renderCheckResults(key: string) { + const checkResults = this._keyResults?.find((result: any) => result.key === key); return html`
- ${results.map((result) => { + ${checkResults?.results.map((result: any) => { return html`

${this.renderIcon(result.resultType)} ${result.message}

${result.readMoreLink ? html`Read more` : nothing} - ${result.actions ? this.renderActions(result.actions) : nothing}
`; })}
diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-overview.ts b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-overview.ts index 21364486ce..23342e7036 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-overview.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/settings/dashboards/health-check/views/health-check-overview.ts @@ -10,7 +10,7 @@ import { tryExecuteAndNotify } from '@umbraco-cms/resources'; import { HealthCheckGroup, HealthCheckGroupWithResult, HealthCheckResource } from '@umbraco-cms/backend-api'; -import '../health-check-group-two.element'; +import '../health-check-overview-group.element'; @customElement('umb-dashboard-health-check-overview') export class UmbDashboardHealthCheckOverviewElement extends UmbLitElement { @@ -92,18 +92,6 @@ export class UmbDashboardHealthCheckOverviewElement extends UmbLitElement { }); } - connectedCallback() { - super.connectedCallback(); - this._getAllGroups(); - } - - private async _getAllGroups() { - const { data } = await tryExecuteAndNotify(this, HealthCheckResource.getHealthCheckGroup({ skip: 0, take: 9999 })); - if (data) { - this._groups = data.items; - } - } - private async _onHealthCheckHandler() { this._groups?.forEach((group) => { group.name ? this._getGroup(group.name) : nothing; @@ -130,18 +118,9 @@ export class UmbDashboardHealthCheckOverviewElement extends UmbLitElement { Check all groups -
- ${this._groups?.map((group) => { - if (group.name) - return html` - ${group.name} ${this.renderChecks(group.name)} - `; - else return nothing; - })} -
+ + -
- `; } diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/extension-slot/extension-slot.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/extension-slot/extension-slot.element.ts index f1644b1944..ee51afbc83 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/extension-slot/extension-slot.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/shared/components/extension-slot/extension-slot.element.ts @@ -58,7 +58,7 @@ export class UmbExtensionSlotElement extends UmbLitElement { }; this._extensions.push(extensionObject); let component; - if (extension.type === 'healthCheck') debugger; + if (isManifestElementableType(extension)) { component = await createExtensionElement(extension); } else {