Merge pull request #31531 from drodil/notification_settings_display
fix(notifications): show default settings before first notification
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
---
|
||||
'@backstage/plugin-notifications-backend': patch
|
||||
---
|
||||
|
||||
Show default settings for notifications even before receiving first notification.
|
||||
|
||||
Previously, it was not possible for the users to see or modify their notification settings until they had received at
|
||||
least one notification from specific origin or topic.
|
||||
This update ensures that default settings are displayed from the outset,
|
||||
allowing users to customize their preferences immediately.
|
||||
@@ -68,6 +68,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
id: 'external:test-service2',
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
id: 'external:test-service3',
|
||||
enabled: true,
|
||||
topics: [
|
||||
{
|
||||
id: 'test-topic3',
|
||||
enabled: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
@@ -829,6 +839,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
id: 'external:test-service2',
|
||||
topics: [{ enabled: false, id: 'test-topic2' }],
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
id: 'external:test-service3',
|
||||
topics: [
|
||||
{
|
||||
enabled: false,
|
||||
id: 'test-topic3',
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
],
|
||||
@@ -863,6 +883,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
id: 'external:test-service2',
|
||||
topics: [{ enabled: false, id: 'test-topic2' }],
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
id: 'external:test-service3',
|
||||
topics: [
|
||||
{
|
||||
enabled: false,
|
||||
id: 'test-topic3',
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
],
|
||||
@@ -887,6 +917,16 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
id: 'external:test-service2',
|
||||
topics: [{ enabled: false, id: 'test-topic2' }],
|
||||
},
|
||||
{
|
||||
enabled: true,
|
||||
id: 'external:test-service3',
|
||||
topics: [
|
||||
{
|
||||
enabled: false,
|
||||
id: 'test-topic3',
|
||||
},
|
||||
],
|
||||
},
|
||||
]),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -207,6 +207,27 @@ export async function createRouter(
|
||||
const settings = await store.getNotificationSettings({ user });
|
||||
const channels = getNotificationChannels();
|
||||
|
||||
// Merge existing channels/origins/topics with configured settings
|
||||
for (const channel of defaultNotificationSettings?.channels ?? []) {
|
||||
if (!channels.includes(channel.id)) {
|
||||
channels.push(channel.id);
|
||||
}
|
||||
|
||||
for (const origin of channel.origins) {
|
||||
if (!origins.includes(origin.id)) {
|
||||
origins.push(origin.id);
|
||||
}
|
||||
|
||||
for (const topic of origin.topics ?? []) {
|
||||
if (
|
||||
!topics.some(t => t.origin === origin.id && t.topic === topic.id)
|
||||
) {
|
||||
topics.push({ origin: origin.id, topic: topic.id });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
channels: channels.map(channelId =>
|
||||
getChannelSettings(channelId, settings, origins, topics),
|
||||
|
||||
Reference in New Issue
Block a user