arch(sprint1): add unknown widget fallback diagnostics
This commit is contained in:
16
src/app/core/runtime/runtime-diagnostics.service.ts
Normal file
16
src/app/core/runtime/runtime-diagnostics.service.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
export interface UnknownWidgetDiagnostic {
|
||||||
|
tenant: string;
|
||||||
|
page: string;
|
||||||
|
section: string;
|
||||||
|
widget: string;
|
||||||
|
reason: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Injectable({ providedIn: 'root' })
|
||||||
|
export class RuntimeDiagnosticsService {
|
||||||
|
logUnknownWidget(event: UnknownWidgetDiagnostic): void {
|
||||||
|
console.warn('[PlatformRuntime][UnknownWidget]', event);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@ import { NgComponentOutlet } from '@angular/common';
|
|||||||
import { PageRenderModel } from '../../dynamic-renderer/page-renderer/page-renderer.model';
|
import { PageRenderModel } from '../../dynamic-renderer/page-renderer/page-renderer.model';
|
||||||
import { WidgetRenderNode } from '../../dynamic-renderer/widget-host/widget-host.model';
|
import { WidgetRenderNode } from '../../dynamic-renderer/widget-host/widget-host.model';
|
||||||
import { WidgetHostService } from '../../dynamic-renderer/widget-host/widget-host.service';
|
import { WidgetHostService } from '../../dynamic-renderer/widget-host/widget-host.service';
|
||||||
|
import { RuntimeDiagnosticsService } from '../../core/runtime/runtime-diagnostics.service';
|
||||||
|
import { UnknownWidgetComponent } from '../../widgets/ui';
|
||||||
|
import { ConfigService } from '../../core/config/config.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-dynamic-page-layout',
|
selector: 'app-dynamic-page-layout',
|
||||||
@@ -16,7 +19,7 @@ import { WidgetHostService } from '../../dynamic-renderer/widget-host/widget-hos
|
|||||||
<section class="dynamic-section" [attr.data-section-type]="section.type">
|
<section class="dynamic-section" [attr.data-section-type]="section.type">
|
||||||
@for (widget of section.widgets; track widget.id) {
|
@for (widget of section.widgets; track widget.id) {
|
||||||
<div class="dynamic-widget" [attr.data-widget-type]="widget.type">
|
<div class="dynamic-widget" [attr.data-widget-type]="widget.type">
|
||||||
@if (resolveWidget(widget); as resolved) {
|
@if (resolveWidget(widget, section.id); as resolved) {
|
||||||
<ng-container *ngComponentOutlet="resolved.component; inputs: resolved.props"></ng-container>
|
<ng-container *ngComponentOutlet="resolved.component; inputs: resolved.props"></ng-container>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
@@ -36,10 +39,42 @@ import { WidgetHostService } from '../../dynamic-renderer/widget-host/widget-hos
|
|||||||
})
|
})
|
||||||
export class DynamicPageLayoutComponent {
|
export class DynamicPageLayoutComponent {
|
||||||
@Input() model: PageRenderModel | null = null;
|
@Input() model: PageRenderModel | null = null;
|
||||||
|
private readonly loggedUnknownWidgets = new Set<string>();
|
||||||
|
|
||||||
constructor(private readonly widgetHost: WidgetHostService) {}
|
constructor(
|
||||||
|
private readonly widgetHost: WidgetHostService,
|
||||||
|
private readonly diagnostics: RuntimeDiagnosticsService,
|
||||||
|
private readonly configService: ConfigService
|
||||||
|
) {}
|
||||||
|
|
||||||
resolveWidget(widget: WidgetRenderNode) {
|
resolveWidget(widget: WidgetRenderNode, sectionId?: string) {
|
||||||
return this.widgetHost.resolveWidget(widget.source);
|
const resolved = this.widgetHost.resolveWidget(widget.source);
|
||||||
|
if (resolved) {
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
const diagnosticKey = `${this.model?.id ?? 'unknown'}:${sectionId ?? 'unknown'}:${widget.id}`;
|
||||||
|
if (!this.loggedUnknownWidgets.has(diagnosticKey)) {
|
||||||
|
this.loggedUnknownWidgets.add(diagnosticKey);
|
||||||
|
|
||||||
|
const tenantId = this.configService.getBootstrapSnapshot()?.tenant.id ?? 'unknown';
|
||||||
|
this.diagnostics.logUnknownWidget({
|
||||||
|
tenant: tenantId,
|
||||||
|
page: this.model?.key ?? 'unknown',
|
||||||
|
section: sectionId ?? 'unknown',
|
||||||
|
widget: `${widget.type}@${widget.version}`,
|
||||||
|
reason: 'not_registered_in_widget_registry'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: widget.type,
|
||||||
|
version: widget.version,
|
||||||
|
component: UnknownWidgetComponent,
|
||||||
|
props: {
|
||||||
|
widgetType: widget.type,
|
||||||
|
widgetVersion: widget.version
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
export * from './footer-navigation-widget.component';
|
export * from './footer-navigation-widget.component';
|
||||||
export * from './hero-widget.component';
|
export * from './hero-widget.component';
|
||||||
export * from './product-carousel-widget.component';
|
export * from './product-carousel-widget.component';
|
||||||
|
export * from './unknown-widget.component';
|
||||||
|
|||||||
38
src/app/widgets/ui/unknown-widget.component.ts
Normal file
38
src/app/widgets/ui/unknown-widget.component.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'app-unknown-widget',
|
||||||
|
standalone: true,
|
||||||
|
template: `
|
||||||
|
<section class="unknown-widget" role="status" aria-live="polite">
|
||||||
|
<strong>Widget unavailable</strong>
|
||||||
|
<p>{{ widgetType }}@{{ widgetVersion }}</p>
|
||||||
|
</section>
|
||||||
|
`,
|
||||||
|
styles: [
|
||||||
|
`
|
||||||
|
.unknown-widget {
|
||||||
|
border: 1px dashed var(--border-color, #d3dad9);
|
||||||
|
border-radius: var(--radius-md, 12px);
|
||||||
|
padding: 0.75rem;
|
||||||
|
color: var(--text-secondary, #667a77);
|
||||||
|
background: var(--background-secondary, #f5f5f5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.unknown-widget strong {
|
||||||
|
display: block;
|
||||||
|
font-size: 0.9rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.unknown-widget p {
|
||||||
|
margin: 0.25rem 0 0;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
],
|
||||||
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
|
})
|
||||||
|
export class UnknownWidgetComponent {
|
||||||
|
@Input() widgetType: string = 'unknown';
|
||||||
|
@Input() widgetVersion: string = 'unknown';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user