diff --git a/.changeset/orange-shrimps-pull.md b/.changeset/orange-shrimps-pull.md new file mode 100644 index 0000000000..7d509a0e5d --- /dev/null +++ b/.changeset/orange-shrimps-pull.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-notifications-backend': patch +'@backstage/plugin-notifications': patch +--- + +Implement icon in backend and show icon in table if available. diff --git a/plugins/notifications-backend/migrations/20240902_addIcon.js b/plugins/notifications-backend/migrations/20240902_addIcon.js new file mode 100644 index 0000000000..a5327f8d73 --- /dev/null +++ b/plugins/notifications-backend/migrations/20240902_addIcon.js @@ -0,0 +1,33 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ + +exports.up = async function up(knex) { + await knex.schema.alterTable('notification', table => { + table.string('icon', 255).nullable(); + }); + await knex.schema.alterTable('broadcast', table => { + table.string('icon', 255).nullable(); + }); +}; + +exports.down = async function down(knex) { + await knex.schema.alterTable('notification', table => { + table.dropColumn('icon'); + }); + await knex.schema.alterTable('broadcast', table => { + table.dropColumn('icon'); + }); +}; diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts index d4e678c8f1..0c7193c1fc 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.test.ts @@ -68,6 +68,7 @@ const testNotification1: Notification = { topic: 'efgh-topic', link: '/catalog', severity: 'critical', + icon: 'docs', }, }; const testNotification2: Notification = { @@ -183,6 +184,7 @@ describe.each(databases.eachSupportedId())( expect(notification?.payload?.topic).toBe('efgh-topic'); expect(notification?.payload?.link).toBe('/catalog'); expect(notification?.payload?.severity).toBe('critical'); + expect(notification?.payload?.icon).toBe('docs'); }); }); diff --git a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts index b23f5254f4..40a76c7486 100644 --- a/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts +++ b/plugins/notifications-backend/src/database/DatabaseNotificationsStore.ts @@ -41,6 +41,7 @@ const NOTIFICATION_COLUMNS = [ 'origin', 'scope', 'topic', + 'icon', 'created', 'updated', 'user', @@ -119,6 +120,7 @@ export class DatabaseNotificationsStore implements NotificationsStore { description: notification.payload?.description, severity: normalizeSeverity(notification.payload?.severity), scope: notification.payload?.scope, + icon: notification.payload.icon, saved: notification.saved, read: notification.read, }; @@ -134,6 +136,7 @@ export class DatabaseNotificationsStore implements NotificationsStore { title: notification.payload?.title, description: notification.payload?.description, severity: normalizeSeverity(notification.payload?.severity), + icon: notification.payload.icon, scope: notification.payload?.scope, }; }; diff --git a/plugins/notifications/src/components/NotificationsTable/NotificationIcon.tsx b/plugins/notifications/src/components/NotificationsTable/NotificationIcon.tsx new file mode 100644 index 0000000000..c89f920249 --- /dev/null +++ b/plugins/notifications/src/components/NotificationsTable/NotificationIcon.tsx @@ -0,0 +1,34 @@ +/* + * Copyright 2024 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://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. + */ +import React from 'react'; +import { Notification } from '@backstage/plugin-notifications-common'; +import SvgIcon from '@material-ui/core/SvgIcon'; +import { useApp } from '@backstage/core-plugin-api'; +import { SeverityIcon } from './SeverityIcon'; + +export const NotificationIcon = ({ + notification, +}: { + notification: Notification; +}) => { + const app = useApp(); + + if (notification.payload.icon) { + const Icon = app.getSystemIcon(notification.payload.icon) ?? SvgIcon; + return ; + } + return ; +}; diff --git a/plugins/notifications/src/components/NotificationsTable/NotificationsTable.tsx b/plugins/notifications/src/components/NotificationsTable/NotificationsTable.tsx index 8a6cbd17d7..ee3e4e164d 100644 --- a/plugins/notifications/src/components/NotificationsTable/NotificationsTable.tsx +++ b/plugins/notifications/src/components/NotificationsTable/NotificationsTable.tsx @@ -34,10 +34,9 @@ import { } from '@backstage/core-components'; import { notificationsApiRef } from '../../api'; - -import { SeverityIcon } from './SeverityIcon'; import { SelectAll } from './SelectAll'; import { BulkActions } from './BulkActions'; +import { NotificationIcon } from './NotificationIcon'; const ThrottleDelayMs = 1000; @@ -184,7 +183,6 @@ export const NotificationsTable = ({ const compactColumns = React.useMemo((): TableColumn[] => { const showToolbar = notifications.length > 0; - return [ { /* selection column */ @@ -220,7 +218,7 @@ export const NotificationsTable = ({ return ( - +