Skip to content

Commit 69d4055

Browse files
committed
fix: Error banner and snackbar issues
1 parent 7cdb7cb commit 69d4055

File tree

5 files changed

+66
-27
lines changed

5 files changed

+66
-27
lines changed

packages/angular-sdk-components/src/lib/_components/infra/Containers/flow-container/flow-container.component.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ export class FlowContainerComponent extends FlowContainerBaseComponent implement
119119
},
120120
'cancelPressed'
121121
);
122+
123+
PCore.getPubSubUtils().subscribe(
124+
'clearBannerMessages',
125+
() => {
126+
this.banners = [];
127+
},
128+
'CLEAR_BANNER_MESSAGES'
129+
);
122130
}
123131

124132
ngOnDestroy() {
@@ -129,6 +137,7 @@ export class FlowContainerComponent extends FlowContainerBaseComponent implement
129137
PCore.getPubSubUtils().unsubscribe(PCore.getConstants().PUB_SUB_EVENTS.EVENT_CANCEL, 'cancelAssignment');
130138

131139
PCore.getPubSubUtils().unsubscribe('cancelPressed', 'cancelPressed');
140+
PCore.getPubSubUtils().unsubscribe('clearBannerMessages', 'CLEAR_BANNER_MESSAGES');
132141
}
133142

134143
handleCancel() {
@@ -152,14 +161,15 @@ export class FlowContainerComponent extends FlowContainerBaseComponent implement
152161
const pConn = this.pConnectOfActiveContainerItem || this.pConn$;
153162
const caseViewModeFromProps = this.angularPConnect.getComponentProp(this, 'caseViewMode');
154163
const caseViewModeFromRedux = pConn.getValue('context_data.caseViewMode', '');
164+
const completeProps = this.angularPConnect.getCurrentCompleteProps(this) as FlowContainerProps;
155165

156166
// ONLY call updateSelf when the component should update
157167
// AND removing the "gate" that was put there since shouldComponentUpdate
158168
// should be the real "gate"
169+
// eslint-disable-next-line sonarjs/no-collapsible-if
159170
if (bUpdateSelf || caseViewModeFromProps !== caseViewModeFromRedux) {
160171
// don't want to redraw the flow container when there are page messages, because
161172
// the redraw causes us to loose the errors on the elements
162-
const completeProps = this.angularPConnect.getCurrentCompleteProps(this) as FlowContainerProps;
163173
if (!completeProps.pageMessages || completeProps.pageMessages.length == 0) {
164174
// with a cancel, need to timeout so todo will update correctly
165175
if (this.bHasCancel) {
@@ -170,10 +180,10 @@ export class FlowContainerComponent extends FlowContainerBaseComponent implement
170180
} else {
171181
this.updateSelf();
172182
}
173-
} else {
174-
this.showPageMessages(completeProps);
175183
}
176184
}
185+
186+
this.showPageMessages(completeProps);
177187
}
178188

179189
showPageMessages(completeProps: FlowContainerProps) {

packages/angular-sdk-components/src/lib/_components/infra/assignment/assignment.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<div><component-mapper name="AlertBanner" [props]="{ banners }" [parent]="this"></component-mapper></div>
2+
<div><component-mapper name="AlertBanner" [props]="{ banners: bannerService.banners }" [parent]="this"></component-mapper></div>
33
<div *ngIf="bHasNavigation$" class="psdk-stepper">
44
<component-mapper
55
name="MultiStep"

packages/angular-sdk-components/src/lib/_components/infra/assignment/assignment.component.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ErrorMessagesService } from '../../../_messages/error-messages.service'
88
import { ProgressSpinnerService } from '../../../_messages/progress-spinner.service';
99
import { ReferenceComponent } from '../../infra/reference/reference.component';
1010
import { ComponentMapperComponent } from '../../../_bridge/component-mapper/component-mapper.component';
11+
import { BannerService } from '../../../_services/banner.service';
1112

1213
function getRefreshProps(refreshConditions) {
1314
// refreshConditions cuurently supports only "Changes" event
@@ -37,7 +38,6 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
3738
@Input() isCreateStage$: boolean;
3839
@Input() updateToken$: number;
3940
@Input() isInModal$ = false;
40-
@Input() banners;
4141

4242
// For interaction with AngularPConnect
4343
angularPConnectData: AngularPConnectData = {};
@@ -75,12 +75,15 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
7575
localeCategory = 'Assignment';
7676
localeReference;
7777

78+
snackBarRef;
79+
7880
constructor(
7981
private angularPConnect: AngularPConnectService,
8082
private psService: ProgressSpinnerService,
8183
private erService: ErrorMessagesService,
8284
private ngZone: NgZone,
83-
private snackBar: MatSnackBar
85+
private snackBar: MatSnackBar,
86+
public bannerService: BannerService
8487
) {}
8588

8689
ngOnInit(): void {
@@ -111,6 +114,8 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
111114
// Should always check the bridge to see if the component should update itself (re-render)
112115
const bUpdateSelf = this.angularPConnect.shouldComponentUpdate(this);
113116

117+
this.bannerService.updateBanners(this.itemKey$);
118+
114119
// ONLY call updateSelf when the component should update
115120
// AND removing the "gate" that was put there since shouldComponentUpdate
116121
// should be the real "gate"
@@ -300,6 +305,10 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
300305
}
301306

302307
buttonClick(sAction, sButtonType) {
308+
this.snackBarRef?.dismiss();
309+
this.bannerService.clearBanners();
310+
// @ts-ignore
311+
PCore.getPubSubUtils().publish('clearBannerMessages');
303312
// right now, done on an individual basis, setting bReInit to true
304313
// upon the next flow container state change, will cause the flow container
305314
// to re-initialize
@@ -335,7 +344,7 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
335344
})
336345
.catch(() => {
337346
this.psService.sendMessage(false);
338-
this.snackBar.open(`${this.localizedVal('Navigation failed!', this.localeCategory)}`, 'Ok');
347+
this.snackBarRef = this.snackBar.open(`${this.localizedVal('Navigation failed!', this.localeCategory)}`, 'Ok');
339348
});
340349
}
341350
break;
@@ -354,7 +363,7 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
354363
})
355364
.catch(() => {
356365
this.psService.sendMessage(false);
357-
this.snackBar.open(`${this.localizedVal('Save failed', this.localeCategory)}`, 'Ok');
366+
this.snackBarRef = this.snackBar.open(`${this.localizedVal('Save failed', this.localeCategory)}`, 'Ok');
358367
});
359368

360369
break;
@@ -381,7 +390,7 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
381390
})
382391
.catch(() => {
383392
this.psService.sendMessage(false);
384-
this.snackBar.open(`${this.localizedVal('Cancel failed!', this.localeCategory)}`, 'Ok');
393+
this.snackBarRef = this.snackBar.open(`${this.localizedVal('Cancel failed!', this.localeCategory)}`, 'Ok');
385394
});
386395
} else {
387396
this.psService.sendMessage(true);
@@ -400,7 +409,7 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
400409
})
401410
.catch(() => {
402411
this.psService.sendMessage(false);
403-
this.snackBar.open(`${this.localizedVal('Cancel failed!', this.localeCategory)}`, 'Ok');
412+
this.snackBarRef = this.snackBar.open(`${this.localizedVal('Cancel failed!', this.localeCategory)}`, 'Ok');
404413
});
405414
}
406415
break;
@@ -413,23 +422,18 @@ export class AssignmentComponent implements OnInit, OnDestroy, OnChanges {
413422
switch (sAction) {
414423
case 'finishAssignment':
415424
this.erService.sendMessage('publish', '');
416-
if (this.formValid()) {
417-
this.bReInit = true;
418-
this.psService.sendMessage(true);
419-
const finishPromise = this.finishAssignment(this.itemKey$); // JA - was itemID but Nebula/Constellation uses itemKey
420-
finishPromise
421-
.then(() => {
422-
this.psService.sendMessage(false);
423-
this.updateChanges();
424-
})
425-
.catch(() => {
426-
this.psService.sendMessage(false);
427-
this.snackBar.open(`${this.localizedVal('Submit failed!', this.localeCategory)}`, 'Ok');
428-
});
429-
} else {
430-
// let snackBarRef = this.snackBar.open("Please fix errors on form.", "Ok");
431-
this.erService.sendMessage('show', this.localizedVal('Please fix errors on form.', this.localeCategory));
432-
}
425+
this.bReInit = true;
426+
this.psService.sendMessage(true);
427+
const finishPromise = this.finishAssignment(this.itemKey$); // JA - was itemID but Nebula/Constellation uses itemKey
428+
finishPromise
429+
.then(() => {
430+
this.psService.sendMessage(false);
431+
this.updateChanges();
432+
})
433+
.catch(() => {
434+
this.psService.sendMessage(false);
435+
this.snackBarRef = this.snackBar.open(`${this.localizedVal('Submit failed!', this.localeCategory)}`, 'Ok');
436+
});
433437
break;
434438
default:
435439
break;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable({
4+
providedIn: 'root'
5+
})
6+
export class BannerService {
7+
banners: any[] = [];
8+
localizedVal = PCore.getLocaleUtils().getLocaleValue;
9+
10+
clearBanners() {
11+
this.banners = [];
12+
}
13+
14+
updateBanners(itemKey) {
15+
let validationErrors = PCore.getMessageManager().getValidationErrorMessages(itemKey) || [];
16+
// const completeProps = this.angularPConnect.getCurrentCompleteProps(this) as FlowContainerProps;
17+
validationErrors = validationErrors.map(item => ({ message: typeof item === 'string' ? item : `${item.label}: ${item.description}` }));
18+
// this.showPageMessages(completeProps);
19+
20+
if (validationErrors.length) {
21+
this.banners = [{ messages: validationErrors?.map(msg => this.localizedVal(msg.message, 'Messages')), variant: 'urgent' }];
22+
}
23+
}
24+
}

packages/angular-sdk-components/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export * from './lib/_services/server-config.service';
124124
export * from './lib/_services/case.service';
125125
export * from './lib/_services/datapage.service';
126126
export * from './lib/_services/idle-detection.service';
127+
export * from './lib/_services/banner.service';
127128
export * from './lib/_services/endpoints';
128129

129130
export * from './lib/_helpers/case-utils';

0 commit comments

Comments
 (0)