PlaylistPageList.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { css } from '@emotion/css';
  2. import React from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { Button, Card, LinkButton, ModalsController, useStyles2 } from '@grafana/ui';
  5. import { contextSrv } from 'app/core/services/context_srv';
  6. import { DashNavButton } from '../dashboard/components/DashNav/DashNavButton';
  7. import { ShareModal } from './ShareModal';
  8. import { PlaylistDTO } from './types';
  9. interface Props {
  10. setStartPlaylist: (playlistItem: PlaylistDTO) => void;
  11. setPlaylistToDelete: (playlistItem: PlaylistDTO) => void;
  12. playlists: PlaylistDTO[] | undefined;
  13. }
  14. export const PlaylistPageList = ({ playlists, setStartPlaylist, setPlaylistToDelete }: Props) => {
  15. const styles = useStyles2(getStyles);
  16. return (
  17. <ul className={styles.list}>
  18. {playlists!.map((playlist: PlaylistDTO) => (
  19. <li className={styles.listItem} key={playlist.uid}>
  20. <Card>
  21. <Card.Heading>
  22. {playlist.name}
  23. <ModalsController key="button-share">
  24. {({ showModal, hideModal }) => (
  25. <DashNavButton
  26. tooltip="Share playlist"
  27. icon="share-alt"
  28. iconSize="lg"
  29. onClick={() => {
  30. showModal(ShareModal, {
  31. playlistUid: playlist.uid,
  32. onDismiss: hideModal,
  33. });
  34. }}
  35. />
  36. )}
  37. </ModalsController>
  38. </Card.Heading>
  39. <Card.Actions>
  40. <Button variant="secondary" icon="play" onClick={() => setStartPlaylist(playlist)}>
  41. Start playlist
  42. </Button>
  43. {contextSrv.isEditor && (
  44. <>
  45. <LinkButton key="edit" variant="secondary" href={`/playlists/edit/${playlist.uid}`} icon="cog">
  46. Edit playlist
  47. </LinkButton>
  48. <Button
  49. disabled={false}
  50. onClick={() => setPlaylistToDelete({ id: playlist.id, uid: playlist.uid, name: playlist.name })}
  51. icon="trash-alt"
  52. variant="destructive"
  53. >
  54. Delete playlist
  55. </Button>
  56. </>
  57. )}
  58. </Card.Actions>
  59. </Card>
  60. </li>
  61. ))}
  62. </ul>
  63. );
  64. };
  65. function getStyles(theme: GrafanaTheme2) {
  66. return {
  67. list: css({
  68. display: 'grid',
  69. }),
  70. listItem: css({
  71. listStyle: 'none',
  72. }),
  73. };
  74. }