feat: follow-up changes on BEP #22641
Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
import { createApiRef } from '@backstage/core-plugin-api';
|
||||
import {
|
||||
Notification,
|
||||
NotificationIds,
|
||||
NotificationStatus,
|
||||
NotificationType,
|
||||
} from '@backstage/plugin-notifications-common';
|
||||
@@ -34,21 +33,21 @@ export type GetNotificationsOptions = {
|
||||
search?: string;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type UpdateNotificationsOptions = {
|
||||
ids: string[];
|
||||
done?: boolean;
|
||||
read?: boolean;
|
||||
saved?: boolean;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export interface NotificationsApi {
|
||||
getNotifications(options?: GetNotificationsOptions): Promise<Notification[]>;
|
||||
|
||||
getStatus(): Promise<NotificationStatus>;
|
||||
|
||||
markDone(ids: string[]): Promise<NotificationIds>;
|
||||
|
||||
markUndone(ids: string[]): Promise<NotificationIds>;
|
||||
|
||||
markRead(ids: string[]): Promise<NotificationIds>;
|
||||
|
||||
markUnread(ids: string[]): Promise<NotificationIds>;
|
||||
|
||||
markSaved(ids: string[]): Promise<NotificationIds>;
|
||||
|
||||
markUnsaved(ids: string[]): Promise<NotificationIds>;
|
||||
updateNotifications(
|
||||
options: UpdateNotificationsOptions,
|
||||
): Promise<Notification[]>;
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { GetNotificationsOptions, NotificationsApi } from './NotificationsApi';
|
||||
import {
|
||||
GetNotificationsOptions,
|
||||
NotificationsApi,
|
||||
UpdateNotificationsOptions,
|
||||
} from './NotificationsApi';
|
||||
import { DiscoveryApi, FetchApi } from '@backstage/core-plugin-api';
|
||||
import { ResponseError } from '@backstage/errors';
|
||||
import {
|
||||
Notification,
|
||||
NotificationIds,
|
||||
NotificationStatus,
|
||||
} from '@backstage/plugin-notifications-common';
|
||||
|
||||
@@ -61,50 +64,12 @@ export class NotificationsClient implements NotificationsApi {
|
||||
return await this.request<NotificationStatus>('status');
|
||||
}
|
||||
|
||||
async markDone(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('done', {
|
||||
async updateNotifications(
|
||||
options: UpdateNotificationsOptions,
|
||||
): Promise<Notification[]> {
|
||||
return await this.request<Notification[]>('update', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
async markUndone(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('undone', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
async markRead(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('read', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
async markUnread(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('unread', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
async markSaved(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('save', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
async markUnsaved(ids: string[]): Promise<NotificationIds> {
|
||||
return await this.request<NotificationIds>('unsave', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ ids: ids }),
|
||||
body: JSON.stringify(options),
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ export const NotificationsTable = (props: {
|
||||
startIcon={<Inbox fontSize="small" />}
|
||||
onClick={() => {
|
||||
notificationsApi
|
||||
.markUndone(selected)
|
||||
.updateNotifications({ ids: selected, done: false })
|
||||
.then(() => props.onUpdate());
|
||||
setSelected([]);
|
||||
}}
|
||||
@@ -162,7 +162,7 @@ export const NotificationsTable = (props: {
|
||||
startIcon={<Check fontSize="small" />}
|
||||
onClick={() => {
|
||||
notificationsApi
|
||||
.markDone(selected)
|
||||
.updateNotifications({ ids: selected, done: true })
|
||||
.then(() => props.onUpdate());
|
||||
setSelected([]);
|
||||
}}
|
||||
@@ -197,16 +197,16 @@ export const NotificationsTable = (props: {
|
||||
<TableCell
|
||||
onClick={() =>
|
||||
notificationsApi
|
||||
.markRead([notification.id])
|
||||
.then(() => navigate(notification.link))
|
||||
.updateNotifications({ ids: [notification.id], read: true })
|
||||
.then(() => navigate(notification.payload.link))
|
||||
}
|
||||
style={{ paddingLeft: 0 }}
|
||||
>
|
||||
<Typography variant="subtitle2">
|
||||
{notification.title}
|
||||
{notification.payload.title}
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
{notification.description}
|
||||
{notification.payload.description}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell style={{ textAlign: 'right' }}>
|
||||
@@ -214,13 +214,16 @@ export const NotificationsTable = (props: {
|
||||
<RelativeTime value={notification.created} />
|
||||
</Box>
|
||||
<Box className="showOnHover">
|
||||
<Tooltip title={notification.link}>
|
||||
<Tooltip title={notification.payload.link}>
|
||||
<IconButton
|
||||
className={styles.actionButton}
|
||||
onClick={() =>
|
||||
notificationsApi
|
||||
.markRead([notification.id])
|
||||
.then(() => navigate(notification.link))
|
||||
.updateNotifications({
|
||||
ids: [notification.id],
|
||||
read: true,
|
||||
})
|
||||
.then(() => navigate(notification.payload.link))
|
||||
}
|
||||
>
|
||||
<ArrowForwardIcon />
|
||||
@@ -234,13 +237,19 @@ export const NotificationsTable = (props: {
|
||||
onClick={() => {
|
||||
if (notification.read) {
|
||||
notificationsApi
|
||||
.markUndone([notification.id])
|
||||
.updateNotifications({
|
||||
ids: [notification.id],
|
||||
done: false,
|
||||
})
|
||||
.then(() => {
|
||||
props.onUpdate();
|
||||
});
|
||||
} else {
|
||||
notificationsApi
|
||||
.markDone([notification.id])
|
||||
.updateNotifications({
|
||||
ids: [notification.id],
|
||||
done: true,
|
||||
})
|
||||
.then(() => {
|
||||
props.onUpdate();
|
||||
});
|
||||
@@ -262,13 +271,19 @@ export const NotificationsTable = (props: {
|
||||
onClick={() => {
|
||||
if (notification.saved) {
|
||||
notificationsApi
|
||||
.markUnsaved([notification.id])
|
||||
.updateNotifications({
|
||||
ids: [notification.id],
|
||||
saved: false,
|
||||
})
|
||||
.then(() => {
|
||||
props.onUpdate();
|
||||
});
|
||||
} else {
|
||||
notificationsApi
|
||||
.markSaved([notification.id])
|
||||
.updateNotifications({
|
||||
ids: [notification.id],
|
||||
saved: true,
|
||||
})
|
||||
.then(() => {
|
||||
props.onUpdate();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user