-
Notifications
You must be signed in to change notification settings - Fork 29
[ENG-9758] Change settings page to default to correct notifications #761
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
Merged
brianjgeiger
merged 7 commits into
CenterForOpenScience:feature/notifications-refactor
from
Johnetordoff:fix/notification-prefs
Nov 14, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
537bf24
fix(notifications): change settings page to default to correct notif
Johnetordoff 46b1787
fix(tests): add new tests and changes for existing behavior
Johnetordoff 171177b
fix(nofitifcations): Move constants for notifications into constants …
Johnetordoff f4d5ca4
fix(test): test behavior change issue
Johnetordoff 9284252
Merge branch 'develop' of https://github.com/CenterForOpenScience/ang…
Johnetordoff df7e911
Merge branch 'feature/notifications-refactor' of https://github.com/C…
Johnetordoff c9f9671
Update src/app/features/settings/notifications/notifications.componen…
Johnetordoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,13 +77,25 @@ export class NotificationsComponent implements OnInit { | |
| notificationSubscriptionsForm = this.fb.group( | ||
| SUBSCRIPTION_EVENTS.reduce( | ||
| (control, { event }) => { | ||
| control[event] = this.fb.control<SubscriptionFrequency>(SubscriptionFrequency.Never, { nonNullable: true }); | ||
| control[event as string] = this.fb.control<SubscriptionFrequency>(SubscriptionFrequency.Never, { | ||
| nonNullable: true, | ||
| }); | ||
| return control; | ||
| }, | ||
| {} as Record<string, FormControl<SubscriptionFrequency>> | ||
| ) | ||
| ); | ||
|
|
||
| private readonly API_EVENT_TO_FORM_EVENT: Record<string, string> = { | ||
| new_pending_submissions: 'global_reviews', | ||
| files_updated: 'global_file_updated', | ||
| }; | ||
|
|
||
| private readonly FORM_EVENT_TO_API_EVENT: Record<string, string> = { | ||
| global_reviews: 'new_pending_submissions', | ||
| global_file_updated: 'files_updated', | ||
| }; | ||
|
|
||
| constructor() { | ||
| effect(() => { | ||
| if (this.emailPreferences()) { | ||
|
|
@@ -125,7 +137,24 @@ export class NotificationsComponent implements OnInit { | |
| onSubscriptionChange(event: SubscriptionEvent, frequency: SubscriptionFrequency) { | ||
| const user = this.currentUser(); | ||
| if (!user) return; | ||
| const id = `${user.id}_${event}`; | ||
|
|
||
| const eventKey = event as unknown as string; | ||
|
Johnetordoff marked this conversation as resolved.
Outdated
|
||
|
|
||
| const apiEventName = this.FORM_EVENT_TO_API_EVENT[eventKey] ?? eventKey; | ||
|
|
||
| let id: string | undefined; | ||
|
|
||
| if (event === SubscriptionEvent.GlobalReviews) { | ||
| const subs = this.notificationSubscriptions(); | ||
| const match = subs.find((s) => (s.event as string) === 'new_pending_submissions'); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. provider id should |
||
| if (match) { | ||
| id = match.id; | ||
| } else { | ||
| return; | ||
| } | ||
| } else { | ||
| id = `${user.id}_${apiEventName}`; | ||
| } | ||
|
Johnetordoff marked this conversation as resolved.
|
||
|
|
||
| this.loaderService.show(); | ||
| this.actions.updateNotificationSubscription({ id, frequency }).subscribe(() => { | ||
|
|
@@ -142,10 +171,24 @@ export class NotificationsComponent implements OnInit { | |
| } | ||
|
|
||
| private updateNotificationSubscriptionsForm() { | ||
| const subs = this.notificationSubscriptions(); | ||
| if (!subs?.length) { | ||
| return; | ||
| } | ||
|
|
||
| const patch: Record<string, SubscriptionFrequency> = {}; | ||
|
|
||
| for (const sub of this.notificationSubscriptions()) { | ||
| patch[sub.event] = sub.frequency; | ||
| for (const sub of subs) { | ||
| const apiEvent = sub.event as string | null; | ||
| if (!apiEvent) { | ||
| continue; | ||
| } | ||
|
|
||
| const formEventKey = this.API_EVENT_TO_FORM_EVENT[apiEvent]; | ||
|
|
||
| if (formEventKey) { | ||
| patch[formEventKey] = sub.frequency; | ||
| } | ||
| } | ||
|
|
||
| this.notificationSubscriptionsForm.patchValue(patch); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.