Skip to content

Commit 056ebe0

Browse files
committed
refactor: make config signal
1 parent ee641b0 commit 056ebe0

File tree

3 files changed

+25
-24
lines changed

3 files changed

+25
-24
lines changed

projects/wc/src/app/components/error/error.component.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
@if (config.scene) {
1+
@let configVM = config();
2+
@if (configVM.scene) {
23
<div class="page">
34
<div class="container">
4-
<ui5-illustrated-message [name]="config.scene">
5-
<ui5-title slot="title" level="H1">{{config.illustratedMessageTitle}}</ui5-title>
5+
<ui5-illustrated-message [name]="configVM.scene">
6+
<ui5-title slot="title" level="H1">{{configVM.illustratedMessageTitle}}</ui5-title>
67
<div slot="subtitle">
7-
<p>{{config.illustratedMessageText}}</p>
8+
<p>{{configVM.illustratedMessageText}}</p>
89
</div>
910
<div>
10-
@for (button of config.buttons; track button.url) {
11+
@for (button of configVM.buttons; track button.url) {
1112
<ui5-button
1213
design="Transparent"
1314
(click)="goTo(button)"

projects/wc/src/app/components/error/error.component.spec.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ describe('ErrorComponent', () => {
7979
fixture.componentRef.setInput('context', testContext);
8080

8181
await component.ngOnInit();
82-
expect(component.config.scene).toBe('NoEntries');
83-
expect(component.config.illustratedMessageTitle).toBe('translated text');
84-
expect(component.config.illustratedMessageText).toBe('translated text');
85-
expect(component.config.buttons).toBeDefined();
82+
expect(component.config().scene).toBe('NoEntries');
83+
expect(component.config().illustratedMessageTitle).toBe('translated text');
84+
expect(component.config().illustratedMessageText).toBe('translated text');
85+
expect(component.config().buttons).toBeDefined();
8686
});
8787

8888
it('should set 403 config', async () => {
@@ -94,11 +94,11 @@ describe('ErrorComponent', () => {
9494
fixture.componentRef.setInput('context', testContext);
9595

9696
await component.ngOnInit();
97-
expect(component.config.scene).toBe('tnt/UnsuccessfulAuth');
98-
expect(component.config.illustratedMessageTitle).toBe('');
99-
expect(component.config.illustratedMessageText).toBe('translated text');
100-
expect(component.config.buttons).toBeDefined();
101-
expect(component.config.buttons?.length).toBe(2);
97+
expect(component.config().scene).toBe('tnt/UnsuccessfulAuth');
98+
expect(component.config().illustratedMessageTitle).toBe('');
99+
expect(component.config().illustratedMessageText).toBe('translated text');
100+
expect(component.config().buttons).toBeDefined();
101+
expect(component.config().buttons?.length).toBe(2);
102102
});
103103

104104
it('should set default error config for unknown error code', async () => {
@@ -110,11 +110,10 @@ describe('ErrorComponent', () => {
110110
fixture.componentRef.setInput('context', testContext);
111111

112112
await component.ngOnInit();
113-
expect(component.config.scene).toBe('UnableToLoad');
114-
expect(component.config.illustratedMessageTitle).toBe('translated text');
115-
expect(component.config.illustratedMessageText).toBe('');
116-
expect(component.config.buttons).toBeDefined();
117-
expect(component.config.buttons?.length).toBe(0);
113+
expect(component.config().scene).toBe('UnableToLoad');
114+
expect(component.config().illustratedMessageTitle).toBe('translated text');
115+
expect(component.config().illustratedMessageText).toBe('');
116+
expect(component.config().buttons).toBeDefined();
118117
});
119118
});
120119
});

projects/wc/src/app/components/error/error.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ViewEncapsulation,
88
inject,
99
input,
10+
signal,
1011
} from '@angular/core';
1112
import { I18nService, LuigiCoreService } from '@openmfp/portal-ui-lib';
1213
import '@ui5/webcomponents-fiori/dist/illustrations/NoEntries.js';
@@ -33,12 +34,12 @@ export class ErrorComponent implements OnInit {
3334

3435
public context = input.required<any>();
3536

36-
config: ErrorConfig = {
37+
config = signal<ErrorConfig>({
3738
scene: 'UnableToLoad',
3839
illustratedMessageTitle: '',
3940
illustratedMessageText: '',
4041
buttons: [],
41-
};
42+
});
4243

4344
async ngOnInit() {
4445
await this.setSceneConfig();
@@ -56,15 +57,15 @@ export class ErrorComponent implements OnInit {
5657
const nodeContext = this.context();
5758
switch (+nodeContext.id) {
5859
case 403: {
59-
this.config = await this.getError403Config();
60+
this.config.set(await this.getError403Config());
6061
break;
6162
}
6263
case 404: {
63-
this.config = await this.getError404Config();
64+
this.config.set(await this.getError404Config());
6465
break;
6566
}
6667
default: {
67-
this.config = await this.getErrorDefaultConfig();
68+
this.config.set(await this.getErrorDefaultConfig());
6869
}
6970
}
7071

0 commit comments

Comments
 (0)