fix: implement icon in backend and show icon in table if available
Signed-off-by: David Weber <david.weber@w3tec.ch> Signed-off-by: David Weber <david.weber.schenker@gmail.com>
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/plugin-notifications-backend': patch
|
||||
'@backstage/plugin-notifications': patch
|
||||
---
|
||||
|
||||
Implement icon in backend and show icon in table if available.
|
||||
@@ -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');
|
||||
});
|
||||
};
|
||||
@@ -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');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -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 <Icon />;
|
||||
}
|
||||
return <SeverityIcon severity={notification.payload.severity} />;
|
||||
};
|
||||
@@ -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<Notification>[] => {
|
||||
const showToolbar = notifications.length > 0;
|
||||
|
||||
return [
|
||||
{
|
||||
/* selection column */
|
||||
@@ -220,7 +218,7 @@ export const NotificationsTable = ({
|
||||
return (
|
||||
<Grid container>
|
||||
<Grid item className={classes.severityItem}>
|
||||
<SeverityIcon severity={notification.payload?.severity} />
|
||||
<NotificationIcon notification={notification} />
|
||||
</Grid>
|
||||
<Grid item xs={11}>
|
||||
<Box>
|
||||
|
||||
Reference in New Issue
Block a user