sortableWidget.tsx 1.7 KB

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