Skip to content

Commit

Permalink
Merge pull request backstage#18782 from AmbrishRamachandiran/master
Browse files Browse the repository at this point in the history
Displaying an alert popup everytime the Playlist is created or deleted
  • Loading branch information
benjdlambert authored Jul 25, 2023
2 parents 384d490 + e15359b commit 9050b5c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-keys-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage/plugin-playlist': patch
---

Displaying an alert popup each time the Playlist is created or deleted
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
* limitations under the License.
*/

import { errorApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api';
import {
errorApiRef,
useApi,
useRouteRef,
alertApiRef,
} from '@backstage/core-plugin-api';
import { BackstageTheme } from '@backstage/theme';
import { usePermission } from '@backstage/plugin-permission-react';
import {
Expand All @@ -34,6 +39,7 @@ import { useTitle } from '../../hooks';
export const CreatePlaylistButton = () => {
const navigate = useNavigate();
const errorApi = useApi(errorApiRef);
const alertApi = useApi(alertApiRef);
const playlistApi = useApi(playlistApiRef);
const playlistRoute = useRouteRef(playlistRouteRef);
const [openDialog, setOpenDialog] = useState(false);
Expand All @@ -49,11 +55,16 @@ export const CreatePlaylistButton = () => {
try {
const playlistId = await playlistApi.createPlaylist(playlist);
navigate(playlistRoute({ playlistId }));
alertApi.post({
message: `Added playlist '${playlist.name}'`,
severity: 'success',
display: 'transient',
});
} catch (e) {
errorApi.post(e);
}
},
[errorApi, navigate, playlistApi, playlistRoute],
[errorApi, navigate, playlistApi, playlistRoute, alertApi],
);

const singularTitle = useTitle({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ export const EntityPlaylistDialog = (props: EntityPlaylistDialogProps) => {
stringifyEntityRef(entity!),
]);
navigate(playlistRoute({ playlistId }));
alertApi.post({
message: `Added playlist '${playlist.name}'`,
severity: 'success',
display: 'transient',
});
} catch (e) {
alertApi.post({
message: `Failed to add entity to ${singularTitleLowerCase}: ${e}`,
Expand Down
20 changes: 18 additions & 2 deletions plugins/playlist/src/components/PlaylistPage/PlaylistHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
HeaderActionMenu,
HeaderLabel,
} from '@backstage/core-components';
import { errorApiRef, useApi, useRouteRef } from '@backstage/core-plugin-api';
import {
errorApiRef,
useApi,
useRouteRef,
alertApiRef,
} from '@backstage/core-plugin-api';
import { EntityRefLink } from '@backstage/plugin-catalog-react';
import { usePermission } from '@backstage/plugin-permission-react';
import {
Expand Down Expand Up @@ -72,6 +77,7 @@ export type PlaylistHeaderProps = {
export const PlaylistHeader = ({ playlist, onUpdate }: PlaylistHeaderProps) => {
const classes = useStyles();
const errorApi = useApi(errorApiRef);
const alertApi = useApi(alertApiRef);
const playlistApi = useApi(playlistApiRef);
const navigate = useNavigate();
const rootRoute = useRouteRef(rootRouteRef);
Expand All @@ -94,17 +100,27 @@ export const PlaylistHeader = ({ playlist, onUpdate }: PlaylistHeaderProps) => {
await playlistApi.updatePlaylist({ ...update, id: playlist.id });
setOpenEditDialog(false);
onUpdate();
alertApi.post({
message: `Updated playlist '${playlist.name}'`,
severity: 'success',
display: 'transient',
});
} catch (e) {
errorApi.post(e);
}
},
[errorApi, onUpdate, playlist, playlistApi],
[errorApi, onUpdate, playlist, playlistApi, alertApi],
);

const [deleting, deletePlaylist] = useAsyncFn(async () => {
try {
await playlistApi.deletePlaylist(playlist.id);
navigate(rootRoute());
alertApi.post({
message: `Deleted playlist '${playlist.name}'`,
severity: 'success',
display: 'transient',
});
} catch (e) {
errorApi.post(e);
}
Expand Down

0 comments on commit 9050b5c

Please sign in to comment.