Skip to content

Commit

Permalink
Merge pull request #1218 from eclipse-tractusx/chore/#999-notificatio…
Browse files Browse the repository at this point in the history
…n-processing-feedback

chore(notifications): 999 fix bug
  • Loading branch information
ds-mmaul authored Jul 16, 2024
2 parents 934c56a + 7f7d53f commit edde1a7
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ export class NotificationDetailComponent implements AfterViewInit, OnDestroy {
} else if (result?.error) {
this.toastService.error(`requestNotification.failed${ formattedStatus }`, 15000, true);
}
this.notificationProcessingService.notificationIdsInLoadingState.delete(result?.context?.notificationId);
this.notificationProcessingService.deleteNotificationId(result?.context?.notificationId);
this.ngAfterViewInit();
},
});

this.notificationProcessingService.doneEmit.subscribe(() => {
this.ngAfterViewInit();
});

this.selected$ = this.notificationDetailFacade.selected$;

this.paramSubscription = this.route.queryParams.subscribe(params => {
Expand All @@ -107,9 +111,7 @@ export class NotificationDetailComponent implements AfterViewInit, OnDestroy {
}

public ngAfterViewInit(): void {
if (!this.notificationDetailFacade.selected?.data) {
this.selectedNotificationBasedOnUrl();
}
this.selectedNotificationBasedOnUrl();

this.subscription = this.selected$
.pipe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export class NotificationsComponent {
this.toastService.error(`requestNotification.failed${ formatted }`, 15000, true);
}
this.handleConfirmActionCompletedEvent();
this.notificationProcessingService.notificationIdsInLoadingState.delete(result?.context?.notificationId);
this.notificationProcessingService.deleteNotificationId(result?.context?.notificationId);
},
});
}
Expand All @@ -111,6 +111,10 @@ export class NotificationsComponent {
this.notificationsFacade.setReceivedNotifications(this.pagination.page, this.pagination.pageSize, this.notificationReceivedSortList, deeplinkNotificationFilter?.receivedFilter, this.receivedFilter);
this.notificationsFacade.setQueuedAndRequestedNotifications(this.pagination.page, this.pagination.pageSize, this.notificationQueuedAndRequestedSortList, deeplinkNotificationFilter?.sentFilter, this.requestedFilter);
});

this.notificationProcessingService.doneEmit.subscribe(() => {
this.ngOnInit();
});
}

public ngAfterViewInit(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class ToastService {
}

public emitClick(): void {
this.notificationProcessingService.notificationIdsInLoadingState.add(this.apiService.lastRequest?.context?.notificationId);
this.notificationProcessingService.addNotificationId(this.apiService.lastRequest?.context?.notificationId);
this.apiService.retryLastRequest()?.subscribe({
next: (next) => this.retryAction.emit({ success: next, context: this.apiService.lastRequest?.context }),
error: (err) => this.retryAction.emit({ error: err, context: this.apiService.lastRequest?.context }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,16 @@ export class NotificationActionModalComponent {
}
const onConfirm = (isConfirmed: boolean) => {
if (!isConfirmed) return;
this.notificationProcessingService.notificationIdsInLoadingState.add(notification.id);
this.notificationProcessingService.addNotificationId(notification.id);
const reason = this.formGroup.get('reason').value;
this.callback(desiredStatus, notification.id, reason).subscribe({
next: () => {
this.notificationProcessingService.notificationIdsInLoadingState.delete(notification.id);
this.notificationProcessingService.deleteNotificationId(notification.id);
this.toastService.success(modalData.successMessage);
this.confirmActionCompleted.emit();
},
error: () => {
this.notificationProcessingService.notificationIdsInLoadingState.delete(notification.id);
this.notificationProcessingService.deleteNotificationId(notification.id);
this.toastService.error(modalData.errorMessage, 15000, true);
this.confirmActionCompleted.emit();
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/********************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import { TestBed } from '@angular/core/testing';
import { NotificationProcessingService } from '@shared/service/notification-processing.service';

describe('NotificationProcessingService', () => {
let service: NotificationProcessingService;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [NotificationProcessingService],
});

service = TestBed.inject(NotificationProcessingService);
});

it('should set notificationIdsInLoadingState and call onNotificationIdsInLoadingStateRemoval', () => {
spyOn(service as any, 'onNotificationIdsInLoadingStateRemoval').and.callThrough();

const newIds = new Set(['id1', 'id2']);

service.notificationIdsInLoadingState = newIds;

expect(service.notificationIdsInLoadingState).toEqual(newIds);
expect((service as any).onNotificationIdsInLoadingStateRemoval).toHaveBeenCalled();
});

it('should emit doneEmit when notificationIdsInLoadingState is set', () => {
spyOn(service.doneEmit, 'emit');

const newIds = new Set(['id1', 'id2']);

service.notificationIdsInLoadingState = newIds;

expect(service.doneEmit.emit).toHaveBeenCalled();
});
});

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { EventEmitter, Injectable } from '@angular/core';
import { Notification } from '@shared/model/notification.model';

/********************************************************************************
Expand All @@ -23,9 +23,32 @@ import { Notification } from '@shared/model/notification.model';
providedIn: 'root',
})
export class NotificationProcessingService {
notificationIdsInLoadingState: Set<string> = new Set();
private _notificationIdsInLoadingState: Set<string> = new Set();
doneEmit = new EventEmitter<any>();

get notificationIdsInLoadingState(): Set<string> {
return this._notificationIdsInLoadingState;
}

set notificationIdsInLoadingState(ids: Set<string>) {
this._notificationIdsInLoadingState = ids;
this.onNotificationIdsInLoadingStateRemoval();
}

public addNotificationId(id: string): void {
this._notificationIdsInLoadingState.add(id);
}

public deleteNotificationId(id: string): void {
this._notificationIdsInLoadingState.delete(id);
this.onNotificationIdsInLoadingStateRemoval();
}

public isInLoadingProcess({ id } = {} as Notification): boolean {
return this.notificationIdsInLoadingState.has(id);
return this._notificationIdsInLoadingState.has(id);
}

private onNotificationIdsInLoadingStateRemoval(): void {
this.doneEmit.emit();
}
}

0 comments on commit edde1a7

Please sign in to comment.