sortableWidget.tsx 2.3 KB

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