@@ -3,4 +3,4 @@
|
||||
'@backstage/plugin-notifications-common': minor
|
||||
---
|
||||
|
||||
Add an optional generic object `attributes` field to `NotificationPayload`. Attributes can be used to store additional unstructured data for the notification, and are stored in the database.
|
||||
Add an optional generic object `metadata` field to `NotificationPayload`. Metadata can be used to store additional unstructured data for the notification, and are stored in the database.
|
||||
|
||||
+4
-4
@@ -16,18 +16,18 @@
|
||||
|
||||
exports.up = async function up(knex) {
|
||||
await knex.schema.alterTable('notification', table => {
|
||||
table.text('attributes').nullable();
|
||||
table.text('metadata').nullable();
|
||||
});
|
||||
await knex.schema.alterTable('broadcast', table => {
|
||||
table.text('attributes').nullable();
|
||||
table.text('metadata').nullable();
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = async function down(knex) {
|
||||
await knex.schema.alterTable('notification', table => {
|
||||
table.dropColumn('attributes');
|
||||
table.dropColumn('metadata');
|
||||
});
|
||||
await knex.schema.alterTable('broadcast', table => {
|
||||
table.dropColumn('attributes');
|
||||
table.dropColumn('metadata');
|
||||
});
|
||||
};
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
| Column | Type | Nullable | Max Length | Default |
|
||||
| ------------- | -------------------------- | -------- | ---------- | ------------------- |
|
||||
| `attributes` | `text` | true | - | - |
|
||||
| `created` | `timestamp with time zone` | false | - | `CURRENT_TIMESTAMP` |
|
||||
| `description` | `text` | true | - | - |
|
||||
| `icon` | `character varying` | true | 255 | - |
|
||||
| `id` | `uuid` | false | - | - |
|
||||
| `link` | `text` | true | - | - |
|
||||
| `metadata` | `text` | true | - | - |
|
||||
| `origin` | `character varying` | false | 255 | - |
|
||||
| `scope` | `character varying` | true | 255 | - |
|
||||
| `severity` | `character varying` | false | 8 | - |
|
||||
@@ -41,12 +41,12 @@
|
||||
|
||||
| Column | Type | Nullable | Max Length | Default |
|
||||
| ------------- | -------------------------- | -------- | ---------- | ------------------- |
|
||||
| `attributes` | `text` | true | - | - |
|
||||
| `created` | `timestamp with time zone` | false | - | `CURRENT_TIMESTAMP` |
|
||||
| `description` | `text` | true | - | - |
|
||||
| `icon` | `character varying` | true | 255 | - |
|
||||
| `id` | `uuid` | false | - | - |
|
||||
| `link` | `text` | true | - | - |
|
||||
| `metadata` | `text` | true | - | - |
|
||||
| `origin` | `character varying` | false | 255 | - |
|
||||
| `read` | `timestamp with time zone` | true | - | - |
|
||||
| `saved` | `timestamp with time zone` | true | - | - |
|
||||
|
||||
@@ -69,8 +69,8 @@ const testNotification1: Notification = {
|
||||
link: '/catalog',
|
||||
severity: 'critical',
|
||||
icon: 'docs',
|
||||
attributes: {
|
||||
attribute1: 'attributeValue',
|
||||
metadata: {
|
||||
attribute1: 'value1',
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -212,8 +212,8 @@ describe.each(databases.eachSupportedId())(
|
||||
expect(notification?.payload?.link).toBe('/catalog');
|
||||
expect(notification?.payload?.severity).toBe('critical');
|
||||
expect(notification?.payload?.icon).toBe('docs');
|
||||
expect(notification?.payload?.attributes).toEqual({
|
||||
attribute1: 'attributeValue',
|
||||
expect(notification?.payload?.metadata).toEqual({
|
||||
attribute1: 'value1',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ const NOTIFICATION_COLUMNS = [
|
||||
'user',
|
||||
'read',
|
||||
'saved',
|
||||
'attributes',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
type NotificationRowType = {
|
||||
@@ -165,7 +165,7 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
severity: row.severity,
|
||||
scope: row.scope,
|
||||
icon: row.icon,
|
||||
attributes: row.attributes ? JSON.parse(row.attributes) : undefined,
|
||||
metadata: row.metadata ? JSON.parse(row.metadata) : undefined,
|
||||
},
|
||||
}));
|
||||
};
|
||||
@@ -229,8 +229,8 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
icon: notification.payload?.icon,
|
||||
saved: notification.saved,
|
||||
read: notification.read,
|
||||
attributes: notification.payload?.attributes
|
||||
? JSON.stringify(notification.payload.attributes)
|
||||
metadata: notification.payload?.metadata
|
||||
? JSON.stringify(notification.payload.metadata)
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
@@ -247,8 +247,8 @@ export class DatabaseNotificationsStore implements NotificationsStore {
|
||||
severity: normalizeSeverity(notification.payload?.severity),
|
||||
icon: notification.payload.icon,
|
||||
scope: notification.payload?.scope,
|
||||
attributes: notification.payload?.attributes
|
||||
? JSON.stringify(notification.payload.attributes)
|
||||
metadata: notification.payload?.metadata
|
||||
? JSON.stringify(notification.payload.metadata)
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -529,8 +529,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
title: 'Test broadcast notification',
|
||||
created: new Date(),
|
||||
severity: 'high',
|
||||
attributes: {
|
||||
attr1: 'attrValue',
|
||||
metadata: {
|
||||
attr1: 'value1',
|
||||
},
|
||||
});
|
||||
await client('notification').insert({
|
||||
@@ -540,8 +540,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
title: 'Test notification',
|
||||
created: new Date(),
|
||||
severity: 'normal',
|
||||
attributes: {
|
||||
attr1: 'attrValue',
|
||||
metadata: {
|
||||
attr1: 'value1',
|
||||
},
|
||||
});
|
||||
|
||||
@@ -561,8 +561,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
severity: 'normal',
|
||||
title: 'Test notification',
|
||||
topic: null,
|
||||
attributes: {
|
||||
attr1: 'attrValue',
|
||||
metadata: {
|
||||
attr1: 'value1',
|
||||
},
|
||||
},
|
||||
read: null,
|
||||
@@ -582,8 +582,8 @@ describe.each(databases.eachSupportedId())('createRouter (%s)', databaseId => {
|
||||
severity: 'high',
|
||||
title: 'Test broadcast notification',
|
||||
topic: null,
|
||||
attributes: {
|
||||
attr1: 'attrValue',
|
||||
metadata: {
|
||||
attr1: 'value1',
|
||||
},
|
||||
},
|
||||
read: null,
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@backstage/config": "workspace:^",
|
||||
"@backstage/types": "workspace:^",
|
||||
"@material-ui/icons": "^4.9.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
```ts
|
||||
import { Config } from '@backstage/config';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
|
||||
// @public (undocumented)
|
||||
export type ChannelSetting = {
|
||||
@@ -31,9 +32,7 @@ export type NewNotificationSignal = {
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
type Notification_2<
|
||||
T extends Record<string, unknown> = Record<string, unknown>,
|
||||
> = {
|
||||
type Notification_2 = {
|
||||
id: string;
|
||||
user: string | null;
|
||||
created: Date;
|
||||
@@ -41,14 +40,12 @@ type Notification_2<
|
||||
read?: Date;
|
||||
updated?: Date;
|
||||
origin: string;
|
||||
payload: NotificationPayload<T>;
|
||||
payload: NotificationPayload;
|
||||
};
|
||||
export { Notification_2 as Notification };
|
||||
|
||||
// @public (undocumented)
|
||||
export type NotificationPayload<
|
||||
T extends Record<string, unknown> = Record<string, unknown>,
|
||||
> = {
|
||||
export type NotificationPayload = {
|
||||
title: string;
|
||||
description?: string;
|
||||
link?: string;
|
||||
@@ -56,7 +53,9 @@ export type NotificationPayload<
|
||||
topic?: string;
|
||||
scope?: string;
|
||||
icon?: string;
|
||||
attributes?: T;
|
||||
metadata?: {
|
||||
[KMetadataKey in string]?: JsonValue;
|
||||
};
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { JsonValue } from '@backstage/types';
|
||||
|
||||
/** @public */
|
||||
export type NotificationSeverity = 'critical' | 'high' | 'normal' | 'low';
|
||||
|
||||
/** @public */
|
||||
export type NotificationPayload<
|
||||
T extends Record<string, unknown> = Record<string, unknown>,
|
||||
> = {
|
||||
export type NotificationPayload = {
|
||||
/**
|
||||
* Notification title
|
||||
*/
|
||||
@@ -53,15 +53,13 @@ export type NotificationPayload<
|
||||
*/
|
||||
icon?: string;
|
||||
/**
|
||||
* Optional additional customizable attributes.
|
||||
* Optional additional customizable metadata.
|
||||
*/
|
||||
attributes?: T;
|
||||
metadata?: { [KMetadataKey in string]?: JsonValue };
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type Notification<
|
||||
T extends Record<string, unknown> = Record<string, unknown>,
|
||||
> = {
|
||||
export type Notification = {
|
||||
/**
|
||||
* Unique identifier for the notification
|
||||
*/
|
||||
@@ -95,7 +93,7 @@ export type Notification<
|
||||
/**
|
||||
* Actual notification payload
|
||||
*/
|
||||
payload: NotificationPayload<T>;
|
||||
payload: NotificationPayload;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user