sortableWidget.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type {ComponentProps} from 'react';
  2. import styled from '@emotion/styled';
  3. import PanelAlert from 'sentry/components/panels/panelAlert';
  4. import WidgetCard from 'sentry/views/dashboards/widgetCard';
  5. import type {DashboardFilters, Widget} from './types';
  6. import type WidgetLegendSelectionState from './widgetLegendSelectionState';
  7. const TABLE_ITEM_LIMIT = 20;
  8. type Props = {
  9. index: string;
  10. isEditingDashboard: boolean;
  11. onDelete: () => void;
  12. onDuplicate: () => void;
  13. onEdit: () => void;
  14. widget: Widget;
  15. widgetLegendState: WidgetLegendSelectionState;
  16. widgetLimitReached: boolean;
  17. dashboardFilters?: DashboardFilters;
  18. isMobile?: boolean;
  19. isPreview?: boolean;
  20. windowWidth?: number;
  21. };
  22. function SortableWidget(props: Props) {
  23. const {
  24. widget,
  25. isEditingDashboard,
  26. widgetLimitReached,
  27. onDelete,
  28. onEdit,
  29. onDuplicate,
  30. isPreview,
  31. isMobile,
  32. windowWidth,
  33. index,
  34. dashboardFilters,
  35. widgetLegendState,
  36. } = props;
  37. const widgetProps: ComponentProps<typeof WidgetCard> = {
  38. widget,
  39. isEditingDashboard,
  40. widgetLimitReached,
  41. onDelete,
  42. onEdit,
  43. onDuplicate,
  44. showContextMenu: true,
  45. isPreview,
  46. index,
  47. dashboardFilters,
  48. widgetLegendState,
  49. renderErrorMessage: errorMessage => {
  50. return (
  51. typeof errorMessage === 'string' && (
  52. <PanelAlert type="error">{errorMessage}</PanelAlert>
  53. )
  54. );
  55. },
  56. isMobile,
  57. windowWidth,
  58. tableItemLimit: TABLE_ITEM_LIMIT,
  59. };
  60. return (
  61. <GridWidgetWrapper>
  62. <WidgetCard {...widgetProps} />
  63. </GridWidgetWrapper>
  64. );
  65. }
  66. export default SortableWidget;
  67. const GridWidgetWrapper = styled('div')`
  68. height: 100%;
  69. `;