Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(notifications): 999 fix bug #1218

Merged
merged 2 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading