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/616 notification refactoring #1135

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -114,10 +114,9 @@ <h3 class="flex items-center">

<mat-card-content>
<app-notifications-tab
[notificationType]="NotificationType.ALERT"
[notificationsView$]="alertsCreated$"
[translationContext]="'commonAlert'"
[tableType]="TableType.RECEIVED_ALERT"
[tableType]="TableType.RECEIVED_NOTIFICATION"
[labelId]="'dashboard-alerts-created'"
[hasPagination]="false"
[optionalColumns]="['targetDate', 'severity', 'createdBy', 'type']"
Expand Down Expand Up @@ -155,13 +154,12 @@ <h3 class="flex items-center">

<mat-card-content>
<app-notifications-tab
[notificationType]="NotificationType.ALERT"
[notificationsView$]="alertsReceived$"
[translationContext]="'commonAlert'"
[labelId]="'dashboard-alerts-received'"
[hasPagination]="false"
[optionalColumns]="['targetDate', 'severity', 'createdBy', 'type']"
[tableType]="TableType.RECEIVED_ALERT"
[tableType]="TableType.RECEIVED_NOTIFICATION"
(selected)="onAlertSelected($event)"
></app-notifications-tab>
</mat-card-content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@

import { Component, OnDestroy, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { NOTIFICATION_BASE_ROUTE, getRoute } from '@core/known-route';
import { getRoute, NOTIFICATION_BASE_ROUTE } from '@core/known-route';
import { DashboardStats } from '@page/dashboard/model/dashboard.model';
import { MetricData } from '@page/dashboard/presentation/dashboard.model';
import { TableType } from '@shared/components/multi-select-autocomplete/table-type.model';
import {
Notification,
Notifications,
NotificationStatusGroup,
NotificationType,
} from '@shared/model/notification.model';
import { Notification, Notifications, NotificationStatusGroup } from '@shared/model/notification.model';
import { View } from '@shared/model/view.model';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
Expand Down Expand Up @@ -134,6 +129,5 @@ export class DashboardComponent implements OnInit, OnDestroy {
this.router.navigate([ `/${ link }/${ notification.id }` ]).then();
}

protected readonly NotificationType = NotificationType;
protected readonly TableType = TableType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@
(confirmActionCompleted)="handleConfirmActionCompletedEvent()"
[helperService]="helperService"
[selectedNotification]="selectedNotification"
[translationContext]="TranslationContext.COMMONALERT"
></app-notification-common-modal>

<div class="detail--wrapper">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export class NotificationDetailComponent implements AfterViewInit, OnDestroy {
.subscribe();
}

protected readonly TranslationContext = TranslationContext;
protected readonly NotificationType = NotificationType;
protected readonly NotificationAction = NotificationAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@
<app-notification-common-modal
(confirmActionCompleted)="handleConfirmActionCompletedEvent()"
[helperService]="helperService"
[translationContext]="TranslationContext.COMMONALERT"
></app-notification-common-modal>

<app-notification
[notificationType]="NotificationType.ALERT"
[queuedAndRequestedNotifications$]="notificationsQueuedAndRequested$"
[receivedNotifications$]="notificationsReceived$"
[isInvestigation]="isInvestigation"
[translationContext]="TranslationContext.COMMONALERT"
[receivedOptionalColumns]="['severity', 'createdBy', 'createdByName', 'type']"
[receivedMultiSortList]="notificationReceivedSortList"
Expand All @@ -37,7 +34,7 @@
[queuedAndRequestedMultiSortList]="notificationQueuedAndRequestedSortList"
(onReceivedTableConfigChanged)="onReceivedTableConfigChange($event)"
(onQueuedAndRequestedTableConfigChanged)="onQueuedAndRequestedTableConfigChange($event)"
(alertFilterChanged)="filterNotifications($event)"
(notificationsFilterChanged)="filterNotifications($event)"
(selected)="openDetailPage($event)"
[menuActionsConfig]="menuActionsConfig"
></app-notification>
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import {Owner} from '@page/parts/model/owner.enum';
import { Owner } from '@page/parts/model/owner.enum';
import {
channelOfNotification,
getOwnerOfTable,
isAsBuilt,
} from '@shared/components/multi-select-autocomplete/autocomplete-strategy';
import {NotificationChannel, TableType} from '@shared/components/multi-select-autocomplete/table-type.model';
import { NotificationChannel, TableType } from '@shared/components/multi-select-autocomplete/table-type.model';

describe('Autocomplete Strategies', () => {

Expand All @@ -46,9 +46,7 @@ describe('Autocomplete Strategies', () => {
});

it('should determine channel of notification', async () => {
expect(channelOfNotification(TableType.CREATED_INVESTIGATION)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.CREATED_ALERT)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.RECEIVED_INVESTIGATION)).toBe(NotificationChannel.RECEIVER);
expect(channelOfNotification(TableType.RECEIVED_INVESTIGATION)).toBe(NotificationChannel.RECEIVER);
expect(channelOfNotification(TableType.SENT_NOTIFICATION)).toBe(NotificationChannel.SENDER);
expect(channelOfNotification(TableType.RECEIVED_NOTIFICATION)).toBe(NotificationChannel.RECEIVER);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,29 +53,7 @@ export class PartsStrategy extends AutocompleteStrategy {
@Injectable({
providedIn: 'any',
})
export class InvestigationStrategy extends AutocompleteStrategy {
notificationService: NotificationService;

constructor(notificationService: NotificationService) {
super();
this.notificationService = notificationService;
}

retrieveSuggestionValues(tableType: TableType, filterColumns: string, searchElement: string): any {
const notificationChannel = channelOfNotification(tableType);
return this.notificationService.getDistinctFilterValues(
notificationChannel,
filterColumns,
searchElement,
true,
);
}
}

@Injectable({
providedIn: 'any',
})
export class AlertStrategy extends AutocompleteStrategy {
export class NotificationStrategy extends AutocompleteStrategy {
notificationService: NotificationService;

constructor(notificationService: NotificationService) {
Expand Down Expand Up @@ -120,11 +98,9 @@ export const AutocompleteStrategyMap = new Map<TableType, any>([
[ TableType.AS_PLANNED_OWN, PartsStrategy ],
[ TableType.AS_PLANNED_CUSTOMER, PartsStrategy ],
[ TableType.AS_PLANNED_SUPPLIER, PartsStrategy ],
[ TableType.RECEIVED_INVESTIGATION, InvestigationStrategy ],
[ TableType.CREATED_INVESTIGATION, InvestigationStrategy ],
[ TableType.RECEIVED_ALERT, AlertStrategy ],
[ TableType.CREATED_ALERT, AlertStrategy ],
[ TableType.CONTRACTS, ContractsStrategy]
[ TableType.RECEIVED_NOTIFICATION, NotificationStrategy ],
[ TableType.SENT_NOTIFICATION, NotificationStrategy ],
[ TableType.CONTRACTS, ContractsStrategy ],
]);

export function getOwnerOfTable(tableType: TableType): Owner {
Expand All @@ -145,14 +121,10 @@ export function isAsBuilt(tableType: TableType): boolean {
}

export function channelOfNotification(tableType: TableType): NotificationChannel {
if (tableType === TableType.CREATED_ALERT || tableType === TableType.CREATED_INVESTIGATION) {
if (tableType === TableType.SENT_NOTIFICATION) {
return NotificationChannel.SENDER;
} else {
return NotificationChannel.RECEIVER;
}

}

export function isInvestigation(tableType: TableType): boolean {
return [ TableType.RECEIVED_INVESTIGATION, TableType.CREATED_INVESTIGATION ].includes(tableType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ export enum TableType {
AS_BUILT_CUSTOMER = 'AS_BUILT_CUSTOMER',
AS_PLANNED_SUPPLIER = 'AS_PLANNED_SUPPLIER',
AS_PLANNED_CUSTOMER = 'AS_PLANNED_CUSTOMER',
RECEIVED_INVESTIGATION = 'RECEIVED_INVESTIGATION',
CREATED_INVESTIGATION = 'CREATED_INVESTIGATION',
RECEIVED_ALERT = 'RECEIVED_ALERT',
CREATED_ALERT = 'CREATED_ALERT',
RECEIVED_NOTIFICATION = 'RECEIVED_NOTIFICATION',
SENT_NOTIFICATION = 'SENT_NOTIFICATION',
CONTRACTS='CONTRACTS'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,27 @@
<app-approve-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[approveCall]="this.helperService.approve.bind(this)"
[translationContext]="this.translationContext"
></app-approve-notification-modal>
<app-cancel-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[cancelCall]="helperService.cancel.bind(this)"
[translationContext]="this.translationContext"
></app-cancel-notification-modal>
<app-close-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[closeCall]="helperService.close.bind(this)"
[translationContext]="this.translationContext"
></app-close-notification-modal>

<app-acknowledge-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[acknowledgeCall]="helperService.acknowledge.bind(this)"
[translationContext]="this.translationContext"
></app-acknowledge-notification-modal>

<app-accept-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[acceptCall]="helperService.accept.bind(this)"
[translationContext]="this.translationContext"
></app-accept-notification-modal>

<app-decline-notification-modal
(confirmActionCompleted)="handleModalConfirmActionCompletedEvent()"
[declineCall]="helperService.decline.bind(this)"
[translationContext]="this.translationContext"
></app-decline-notification-modal>
Original file line number Diff line number Diff line change
Expand Up @@ -16,79 +16,87 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import { Component, EventEmitter, Input, Optional, Output, ViewChild } from '@angular/core';
import { NotificationHelperService } from '@page/notifications/core/notification-helper.service';
import { NotificationsFacade } from '@page/notifications/core/notifications.facade';
import { Notification } from '@shared/model/notification.model';
import { TranslationContext } from '@shared/model/translation-context.model';
import { AcceptNotificationModalComponent } from '@shared/modules/notification/modal/accept/accept-notification-modal.component';
import { AcknowledgeNotificationModalComponent } from '@shared/modules/notification/modal/acknowledge/acknowledge-notification-modal.component';
import { ApproveNotificationModalComponent } from '@shared/modules/notification/modal/approve/approve-notification-modal.component';
import { CancelNotificationModalComponent } from '@shared/modules/notification/modal/cancel/cancel-notification-modal.component';
import { CloseNotificationModalComponent } from '@shared/modules/notification/modal/close/close-notification-modal.component';
import { DeclineNotificationModalComponent } from '@shared/modules/notification/modal/decline/decline-notification-modal.component';
import {Component, EventEmitter, Input, Optional, Output, ViewChild} from '@angular/core';
import {NotificationHelperService} from '@page/notifications/core/notification-helper.service';
import {NotificationsFacade} from '@page/notifications/core/notifications.facade';
import {Notification} from '@shared/model/notification.model';
import {
AcceptNotificationModalComponent
} from '@shared/modules/notification/modal/accept/accept-notification-modal.component';
import {
AcknowledgeNotificationModalComponent
} from '@shared/modules/notification/modal/acknowledge/acknowledge-notification-modal.component';
import {
ApproveNotificationModalComponent
} from '@shared/modules/notification/modal/approve/approve-notification-modal.component';
import {
CancelNotificationModalComponent
} from '@shared/modules/notification/modal/cancel/cancel-notification-modal.component';
import {
CloseNotificationModalComponent
} from '@shared/modules/notification/modal/close/close-notification-modal.component';
import {
DeclineNotificationModalComponent
} from '@shared/modules/notification/modal/decline/decline-notification-modal.component';

@Component({
selector: 'app-notification-common-modal',
templateUrl: './notification-common-modal.component.html',
selector: 'app-notification-common-modal',
templateUrl: './notification-common-modal.component.html',
})

export class NotificationCommonModalComponent {
@Input() selectedNotification: Notification;
@Input() translationContext: TranslationContext;
@Input() helperService: NotificationHelperService;
@Output() confirmActionCompleted = new EventEmitter<void>();
@Input() selectedNotification: Notification;
@Input() helperService: NotificationHelperService;
@Output() confirmActionCompleted = new EventEmitter<void>();


@ViewChild(ApproveNotificationModalComponent) approveModal: ApproveNotificationModalComponent;
@ViewChild(CloseNotificationModalComponent) closeModal: CloseNotificationModalComponent;
@ViewChild(CancelNotificationModalComponent) cancelModal: CancelNotificationModalComponent;
@ViewChild(ApproveNotificationModalComponent) approveModal: ApproveNotificationModalComponent;
@ViewChild(CloseNotificationModalComponent) closeModal: CloseNotificationModalComponent;
@ViewChild(CancelNotificationModalComponent) cancelModal: CancelNotificationModalComponent;

@ViewChild(AcceptNotificationModalComponent) acceptModal: AcceptNotificationModalComponent;
@ViewChild(AcknowledgeNotificationModalComponent) acknowledgeModal: AcknowledgeNotificationModalComponent;
@ViewChild(DeclineNotificationModalComponent) declineModal: DeclineNotificationModalComponent;
@ViewChild(AcceptNotificationModalComponent) acceptModal: AcceptNotificationModalComponent;
@ViewChild(AcknowledgeNotificationModalComponent) acknowledgeModal: AcknowledgeNotificationModalComponent;
@ViewChild(DeclineNotificationModalComponent) declineModal: DeclineNotificationModalComponent;

// TODO do not delete the facade here. This will lead to a nullpointer exception within the modal call.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a TODO or just a hint?

public constructor(
@Optional() private readonly notificationsFacade: NotificationsFacade,
) {
}

public constructor(
@Optional() private readonly notificationsFacade: NotificationsFacade,
) {
}

public handleModalConfirmActionCompletedEvent(): void {
this.confirmActionCompleted.emit();
}

public show(modalContext: string, notification?: Notification) {
let notificationToShow = notification || this.selectedNotification;
switch (modalContext) {
case 'approve': {
this.approveModal.show(notificationToShow);
break;
}
case 'close': {
this.closeModal.show(notificationToShow);
break;
}
case 'cancel': {
this.cancelModal.show(notificationToShow);
break;
}
case 'accept': {
this.acceptModal.show(notificationToShow);
break;
}
case 'acknowledge': {
this.acknowledgeModal.show(notificationToShow);
break;
}
case 'decline': {
this.declineModal.show(notificationToShow);
break;
}
public handleModalConfirmActionCompletedEvent(): void {
this.confirmActionCompleted.emit();
}
}

public show(modalContext: string, notification?: Notification) {
let notificationToShow = notification || this.selectedNotification;
switch (modalContext) {
case 'approve': {
this.approveModal.show(notificationToShow);
break;
}
case 'close': {
this.closeModal.show(notificationToShow);
break;
}
case 'cancel': {
this.cancelModal.show(notificationToShow);
break;
}
case 'accept': {
this.acceptModal.show(notificationToShow);
break;
}
case 'acknowledge': {
this.acknowledgeModal.show(notificationToShow);
break;
}
case 'decline': {
this.declineModal.show(notificationToShow);
break;
}
}
}

protected readonly TranslationContext = TranslationContext;
}
11 changes: 10 additions & 1 deletion frontend/src/app/modules/shared/helper/notification-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
import { NotificationDeeplinkFilter } from '@shared/model/notification.model';
import {Notification, NotificationDeeplinkFilter, NotificationType} from '@shared/model/notification.model';
import {TranslationContext} from "@shared/model/translation-context.model";

export interface DeeplinkNotificationFilter {
receivedFilter: NotificationDeeplinkFilter,
Expand All @@ -38,3 +39,11 @@ export function createDeeplinkNotificationFilter(params: any): DeeplinkNotificat
return { receivedFilter, sentFilter };
}
}

export function getTranslationContext(notification: Notification):TranslationContext{
if (notification?.type === NotificationType.ALERT.valueOf()){
return TranslationContext.COMMONALERT
} else {
return TranslationContext.COMMONINVESTIGATION;
}
}
Loading