PlaylistTableRow.tsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import { css, cx } from '@emotion/css';
  2. import React, { FC, MouseEvent } from 'react';
  3. import { GrafanaTheme } from '@grafana/data';
  4. import { selectors } from '@grafana/e2e-selectors';
  5. import { Icon, IconButton, useStyles } from '@grafana/ui';
  6. import { TagBadge } from '../../core/components/TagFilter/TagBadge';
  7. import { PlaylistItem } from './types';
  8. interface PlaylistTableRowProps {
  9. first: boolean;
  10. last: boolean;
  11. item: PlaylistItem;
  12. onMoveUp: (item: PlaylistItem) => void;
  13. onMoveDown: (item: PlaylistItem) => void;
  14. onDelete: (item: PlaylistItem) => void;
  15. }
  16. export const PlaylistTableRow: FC<PlaylistTableRowProps> = ({ item, onDelete, onMoveDown, onMoveUp, first, last }) => {
  17. const styles = useStyles(getStyles);
  18. const onDeleteClick = (event: MouseEvent) => {
  19. event.preventDefault();
  20. onDelete(item);
  21. };
  22. const onMoveDownClick = (event: MouseEvent) => {
  23. event.preventDefault();
  24. onMoveDown(item);
  25. };
  26. const onMoveUpClick = (event: MouseEvent) => {
  27. event.preventDefault();
  28. onMoveUp(item);
  29. };
  30. return (
  31. <tr aria-label={selectors.pages.PlaylistForm.itemRow} key={item.title}>
  32. {item.type === 'dashboard_by_id' ? (
  33. <td className={cx(styles.td, styles.item)}>
  34. <Icon name="apps" aria-label={selectors.pages.PlaylistForm.itemIdType} />
  35. <span>{item.title}</span>
  36. </td>
  37. ) : null}
  38. {item.type === 'dashboard_by_tag' ? (
  39. <td className={cx(styles.td, styles.item)}>
  40. <Icon name="tag-alt" aria-label={selectors.pages.PlaylistForm.itemTagType} />
  41. <TagBadge key={item.id} label={item.title} removeIcon={false} count={0} />
  42. </td>
  43. ) : null}
  44. <td className={cx(styles.td, styles.settings)}>
  45. {!first ? (
  46. <IconButton
  47. name="arrow-up"
  48. size="md"
  49. onClick={onMoveUpClick}
  50. aria-label={selectors.pages.PlaylistForm.itemMoveUp}
  51. type="button"
  52. />
  53. ) : null}
  54. {!last ? (
  55. <IconButton
  56. name="arrow-down"
  57. size="md"
  58. onClick={onMoveDownClick}
  59. aria-label={selectors.pages.PlaylistForm.itemMoveDown}
  60. type="button"
  61. />
  62. ) : null}
  63. <IconButton
  64. name="times"
  65. size="md"
  66. onClick={onDeleteClick}
  67. aria-label={selectors.pages.PlaylistForm.itemDelete}
  68. type="button"
  69. />
  70. </td>
  71. </tr>
  72. );
  73. };
  74. function getStyles(theme: GrafanaTheme) {
  75. return {
  76. td: css`
  77. label: td;
  78. line-height: 28px;
  79. max-width: 335px;
  80. white-space: nowrap;
  81. text-overflow: ellipsis;
  82. overflow: hidden;
  83. `,
  84. item: css`
  85. label: item;
  86. span {
  87. margin-left: ${theme.spacing.xs};
  88. }
  89. `,
  90. settings: css`
  91. label: settings;
  92. text-align: right;
  93. `,
  94. };
  95. }