Skip to content

Commit 7d703cc

Browse files
committed
peek error modal
1 parent 6f9e66d commit 7d703cc

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

src/Umbraco.Web.UI.Client/src/packages/core/notification/controllers/peek-error/peek-error-notification.element.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class UmbPeekErrorNotificationElement extends UmbLitElement {
1515
async #onClick() {
1616
const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT);
1717

18-
modalManager.open(this, UMB_ERROR_VIEWER_MODAL, { data: this.data });
18+
modalManager.open(this, UMB_ERROR_VIEWER_MODAL, { data: this.data?.details });
1919

2020
this.notificationHandler.close();
2121
}
@@ -24,7 +24,12 @@ export class UmbPeekErrorNotificationElement extends UmbLitElement {
2424
return this.data
2525
? html`<uui-toast-notification-layout headline=${ifDefined(this.data.headline)}
2626
>${this.data.message}${this.data.details
27-
? html`<uui-button slot="action" look="primary" color="danger" @click=${this.#onClick}></uui-button>`
27+
? html`<uui-button
28+
slot="actions"
29+
look="primary"
30+
color="danger"
31+
label=${this.localize.term('defaultdialogs_seeErrorAction')}
32+
@click=${this.#onClick}></uui-button>`
2833
: nothing}</uui-toast-notification-layout
2934
>`
3035
: nothing;

src/Umbraco.Web.UI.Client/src/packages/core/notification/modals/error-viewer/error-viewer-modal.element.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import type { UmbErrorViewerModalData, UmbErrorViewerModalValue } from './error-viewer-modal.token.js';
2-
import { css, customElement, html, nothing } from '@umbraco-cms/backoffice/external/lit';
2+
import { css, customElement, html, nothing, state } from '@umbraco-cms/backoffice/external/lit';
33
import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal';
44

55
@customElement('umb-error-viewer-modal')
66
export class UmbErrorViewerModalElement extends UmbModalBaseElement<UmbErrorViewerModalData, UmbErrorViewerModalValue> {
7+
@state()
8+
_displayError?: string;
9+
10+
@state()
11+
_displayLang?: string;
12+
713
// Code adapted from https://stackoverflow.com/a/57668208/12787
814
// Licensed under the permissions of the CC BY-SA 4.0 DEED
915
#stringify(obj: any): string {
@@ -24,12 +30,26 @@ export class UmbErrorViewerModalElement extends UmbModalBaseElement<UmbErrorView
2430
return output + '\n}';
2531
}
2632

33+
public override set data(value: UmbErrorViewerModalData | undefined) {
34+
super.data = value;
35+
console.log(value, typeof value);
36+
// is JSON:
37+
if (typeof value === 'string') {
38+
this._displayLang = 'String';
39+
this._displayError = value;
40+
} else {
41+
this._displayLang = 'JSON';
42+
this._displayError = this.#stringify(value);
43+
}
44+
}
45+
public override get data(): UmbErrorViewerModalData | undefined {
46+
return super.data;
47+
}
48+
2749
override render() {
2850
return html`
29-
<umb-body-layout headline=${this.localize.term('general_manifest')} main-no-padding>
30-
${this.data
31-
? html`<umb-code-block language="JSON" copy>${this.#stringify(this.data)}</umb-code-block>`
32-
: nothing}
51+
<umb-body-layout headline=${this.localize.term('defaultdialogs_seeErrorDialogHeadline')} main-no-padding>
52+
${this.data ? html`<umb-code-block language=${this._displayLang} copy>${this.data}</umb-code-block>` : nothing}
3353
<div slot="actions">
3454
<uui-button label=${this.localize.term('general_close')} @click=${this._rejectModal}></uui-button>
3555
</div>

src/Umbraco.Web.UI.Client/src/packages/core/resources/resource.controller.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@ import { isApiError, isCancelError, isCancelablePromise } from './apiTypeValidat
44
import type { XhrRequestOptions } from './types.js';
55
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
66
import { UmbControllerBase } from '@umbraco-cms/backoffice/class-api';
7-
import { UmbContextConsumerController } from '@umbraco-cms/backoffice/context-api';
8-
import {
9-
UMB_NOTIFICATION_CONTEXT,
10-
umbPeekError,
11-
type UmbNotificationOptions,
12-
} from '@umbraco-cms/backoffice/notification';
7+
import { umbPeekError, type UmbNotificationOptions } from '@umbraco-cms/backoffice/notification';
138
import type { UmbDataSourceResponse } from '@umbraco-cms/backoffice/repository';
149
import {
1510
ApiError,
@@ -122,21 +117,17 @@ export class UmbResourceController extends UmbControllerBase {
122117
'The Umbraco object cache is corrupt, but your action may still have been executed. Please restart the server to reset the cache. This is a work in progress.';
123118
}
124119

125-
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
126-
notificationContext.peek('danger', {
127-
data: {
128-
headline,
129-
message,
130-
},
131-
...options,
120+
umbPeekError(this, {
121+
headline: headline,
122+
message: message,
123+
details: problemDetails?.errors ?? problemDetails?.detail,
132124
});
133125
}
134126
break;
135127
default:
136128
// Other errors
137129
if (!isCancelledByNotification) {
138130
/*
139-
140131
const notificationContext = await this.getContext(UMB_NOTIFICATION_CONTEXT);
141132
notificationContext.peek('danger', {
142133
data: {
@@ -151,9 +142,8 @@ export class UmbResourceController extends UmbControllerBase {
151142
*/
152143
const headline = problemDetails?.title ?? error.name ?? 'Server Error';
153144
umbPeekError(this, {
154-
headline: problemDetails?.detail ? headline : undefined,
155-
message: problemDetails?.detail ?? headline,
156-
details: problemDetails?.errors,
145+
message: headline,
146+
details: problemDetails?.errors ?? problemDetails?.detail,
157147
});
158148
}
159149
}

0 commit comments

Comments
 (0)