sortableWidget.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. const TABLE_ITEM_LIMIT = 20;
  7. type Props = {
  8. index: string;
  9. isEditingDashboard: boolean;
  10. isEditingWidget: boolean;
  11. onDelete: () => void;
  12. onDuplicate: () => void;
  13. onEdit: () => void;
  14. onUpdate: (widget: Widget | null) => void;
  15. widget: Widget;
  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. isEditingWidget,
  27. widgetLimitReached,
  28. onDelete,
  29. onEdit,
  30. onUpdate,
  31. onDuplicate,
  32. isPreview,
  33. isMobile,
  34. windowWidth,
  35. index,
  36. dashboardFilters,
  37. } = props;
  38. const widgetProps: ComponentProps<typeof WidgetCard> = {
  39. widget,
  40. isEditingDashboard,
  41. isEditingWidget,
  42. widgetLimitReached,
  43. onDelete,
  44. onEdit,
  45. onDuplicate,
  46. onUpdate,
  47. showContextMenu: true,
  48. isPreview,
  49. index,
  50. dashboardFilters,
  51. renderErrorMessage: errorMessage => {
  52. return (
  53. typeof errorMessage === 'string' && (
  54. <PanelAlert type="error">{errorMessage}</PanelAlert>
  55. )
  56. );
  57. },
  58. isMobile,
  59. windowWidth,
  60. tableItemLimit: TABLE_ITEM_LIMIT,
  61. };
  62. return (
  63. <GridWidgetWrapper>
  64. <WidgetCard {...widgetProps} />
  65. </GridWidgetWrapper>
  66. );
  67. }
  68. export default SortableWidget;
  69. const GridWidgetWrapper = styled('div')`
  70. height: 100%;
  71. `;