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

[Feat]: Notification entry navigates to the relevant view #2786

Merged
Merged
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
34 changes: 34 additions & 0 deletions src/app/features/notification/model/notification-event.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
import { Entity } from "../../../core/entity/model/entity";
import { DatabaseField } from "../../../core/entity/database-field.decorator";
import { DatabaseEntity } from "../../../core/entity/database-entity.decorator";
import { NotificationType } from "./notification-config";

/**
* This represents one specific notification event for one specific user,
* displayed in the UI through the notification indicator in the toolbar.
*/
@DatabaseEntity("NotificationEvent")
export class NotificationEvent extends Entity {
/*
* The title of the notification.
*/
@DatabaseField() title: string;

/*
* The body of the notification.
*/
@DatabaseField() body: string;

/*
* The URL to redirect the user to when the notification is clicked.
*/
@DatabaseField() actionURL: string;

/*
* The user ID for whom the notification is intended
*/
@DatabaseField() notificationFor: string;

/*
* The notification token to be used for the notification.
*/
@DatabaseField() notificationToken: string;

/*
* The type of notification.
*/
@DatabaseField() notificationType: NotificationType;

/*
* The entity type of the notification.
*/
@DatabaseField() entityType: string;

/*
* The status of the notification.
*/
@DatabaseField() readStatus: boolean;
}
28 changes: 26 additions & 2 deletions src/app/features/notification/notification.component.ts
Original file line number Diff line number Diff line change
@@ -135,15 +135,39 @@ export class NotificationComponent implements OnInit {
await this.entityMapper.remove(notification);
}

private generateNotificationActionURL(
notification: NotificationEvent,
): string {
const routes = this.router.config;
let actionURL = "";

const entityRoute = routes.find(
(route) => route.data?.config?.entityType === notification.entityType,
);

switch (notification.notificationType) {
case "entity_change":
if (entityRoute) {
actionURL = `/${entityRoute.path}`;
}
break;
default:
break;
Comment on lines +154 to +155
Copy link
Member

Choose a reason for hiding this comment

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

default: return notification.actionUrl?

}

return actionURL;
}

/**
* Updates the read status of a selected notification.
* Handles notification events by redirecting the user to the corresponding action URL.
* @param {NotificationEvent} notification - The notification event containing the action URL.
*/
async notificationClicked(notification: NotificationEvent) {
await this.updateReadStatus([notification], true);
if (!notification.actionURL) return;
await this.router.navigate([notification.actionURL]);
const actionURL = this.generateNotificationActionURL(notification);
if (!actionURL) return;
await this.router.navigate([actionURL]);
}

// TODO: remove test code before final merge

Unchanged files with check annotations Beta

# 'unsafe-eval' required for pouchdb https://github.com/pouchdb/pouchdb/issues/7853#issuecomment-535020600
# variables are inserted into the nginx config
CMD envsubst '$$PORT $$COUCHDB_URL $$QUERY_URL $$NOMINATIM_URL $$CSP $$CSP_REPORT_URI' < /etc/nginx/templates/default.conf > /etc/nginx/conf.d/default.conf &&\

Check warning on line 143 in build/Dockerfile

GitHub Actions / build (linux/amd64, ubuntu-latest)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/

Check warning on line 143 in build/Dockerfile

GitHub Actions / build (linux/arm64, self-hosted, Linux, ARM64)

JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals

JSONArgsRecommended: JSON arguments recommended for CMD to prevent unintended behavior related to OS signals More info: https://docs.docker.com/go/dockerfile/rule/json-args-recommended/
nginx -g 'daemon off;'