Skip to content

Commit 2463ab0

Browse files
committed
fixed prop in new announcement banner, trigger notification on change status, navigate to root on edit complete
Signed-off-by: Mattia <[email protected]>
1 parent 688f03d commit 2463ab0

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@backstage-community/plugin-announcements-backend': minor
3+
'@backstage-community/plugin-announcements': minor
4+
---
5+
6+
Fixed handling of `active` prop in NewAnnouncementBanner
7+
Extended signal and notification on update when the annoucencement is activated
8+
Updated `EditAnnoucementPage` to navigate to root path as the announcement creation page

workspaces/announcements/plugins/announcements-backend/src/router.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type GetAnnouncementsQueryParams = {
6262
category?: string;
6363
page?: number;
6464
max?: number;
65-
active?: boolean;
65+
active?: string;
6666
sortby?: 'created_at' | 'start_at';
6767
order?: 'asc' | 'desc';
6868
current?: boolean;
@@ -133,7 +133,7 @@ export async function createRouter(
133133
category,
134134
max,
135135
offset: page ? (page - 1) * (max ?? 10) : undefined,
136-
active,
136+
active: active === 'true',
137137
sortBy: ['created_at', 'start_at'].includes(sortby)
138138
? sortby
139139
: 'created_at',
@@ -314,6 +314,15 @@ export async function createRouter(
314314
});
315315
}
316316

317+
if (!initialAnnouncement.active && active) {
318+
await signalAnnouncement(announcement, signals);
319+
const announcementNotificationsEnabled =
320+
req.body?.sendNotification === true;
321+
if (announcementNotificationsEnabled) {
322+
await sendAnnouncementNotification(announcement, notifications);
323+
}
324+
}
325+
317326
return res.status(200).json(announcement);
318327
},
319328
);

workspaces/announcements/plugins/announcements/src/components/EditAnnouncementPage/EditAnnouncementPage.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Page, Header, Content, Progress } from '@backstage/core-components';
2020
import {
2121
alertApiRef,
2222
useApi,
23+
useRouteRef,
2324
useRouteRefParams,
2425
} from '@backstage/core-plugin-api';
2526
import { AnnouncementForm } from '../AnnouncementForm';
@@ -31,6 +32,8 @@ import {
3132
useCategories,
3233
} from '@backstage-community/plugin-announcements-react';
3334
import { Alert } from '@material-ui/lab';
35+
import { rootRouteRef } from '../../routes';
36+
import { useNavigate } from 'react-router-dom';
3437

3538
type EditAnnouncementPageProps = {
3639
themeId: string;
@@ -47,6 +50,8 @@ export const EditAnnouncementPage = (props: EditAnnouncementPageProps) => {
4750
);
4851
const { categories } = useCategories();
4952
const { t } = useAnnouncementsTranslation();
53+
const navigate = useNavigate();
54+
const rootPage = useRouteRef(rootRouteRef);
5055

5156
let title = props.title;
5257
let content: ReactNode = <Progress />;
@@ -77,6 +82,7 @@ export const EditAnnouncementPage = (props: EditAnnouncementPageProps) => {
7782

7883
await announcementsApi.updateAnnouncement(id, request);
7984
alertApi.post({ message: updateMsg, severity: 'success' });
85+
navigate(rootPage());
8086
} catch (err) {
8187
alertApi.post({ message: (err as Error).message, severity: 'error' });
8288
}

workspaces/announcements/plugins/announcements/src/components/NewAnnouncementBanner/NewAnnouncementBanner.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export const NewAnnouncementBanner = (props: NewAnnouncementBannerProps) => {
166166
active,
167167
current,
168168
});
169+
169170
const lastSeen = announcementsApi.lastSeenDate();
170171

171172
const { lastSignal } = useSignal<AnnouncementSignal>(

0 commit comments

Comments
 (0)