widgetPreview.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import PanelAlert from 'sentry/components/panels/panelAlert';
  2. import {useLocation} from 'sentry/utils/useLocation';
  3. import useOrganization from 'sentry/utils/useOrganization';
  4. import usePageFilters from 'sentry/utils/usePageFilters';
  5. import useRouter from 'sentry/utils/useRouter';
  6. import {
  7. type DashboardDetails,
  8. type DashboardFilters,
  9. DisplayType,
  10. } from 'sentry/views/dashboards/types';
  11. import {useWidgetBuilderContext} from 'sentry/views/dashboards/widgetBuilder/contexts/widgetBuilderContext';
  12. import {convertBuilderStateToWidget} from 'sentry/views/dashboards/widgetBuilder/utils/convertBuilderStateToWidget';
  13. import WidgetCard from 'sentry/views/dashboards/widgetCard';
  14. import WidgetLegendNameEncoderDecoder from 'sentry/views/dashboards/widgetLegendNameEncoderDecoder';
  15. import WidgetLegendSelectionState from 'sentry/views/dashboards/widgetLegendSelectionState';
  16. interface WidgetPreviewProps {
  17. dashboard: DashboardDetails;
  18. dashboardFilters: DashboardFilters;
  19. isWidgetInvalid?: boolean;
  20. }
  21. function WidgetPreview({
  22. dashboard,
  23. dashboardFilters,
  24. isWidgetInvalid,
  25. }: WidgetPreviewProps) {
  26. const organization = useOrganization();
  27. const location = useLocation();
  28. const router = useRouter();
  29. const pageFilters = usePageFilters();
  30. const {state} = useWidgetBuilderContext();
  31. const widget = convertBuilderStateToWidget(state);
  32. const widgetLegendState = new WidgetLegendSelectionState({
  33. location,
  34. organization,
  35. dashboard,
  36. router,
  37. });
  38. // TODO: The way we create the widget here does not propagate a widget ID
  39. // to pass to the legend encoder decoder.
  40. const unselectedReleasesForCharts = {
  41. [WidgetLegendNameEncoderDecoder.encodeSeriesNameForLegend('Releases', undefined)]:
  42. false,
  43. };
  44. return (
  45. <WidgetCard
  46. disableFullscreen
  47. borderless
  48. isWidgetInvalid={isWidgetInvalid}
  49. shouldResize={state.displayType !== DisplayType.TABLE}
  50. organization={organization}
  51. selection={pageFilters.selection}
  52. widget={widget}
  53. dashboardFilters={dashboardFilters}
  54. isEditingDashboard={false}
  55. widgetLimitReached={false}
  56. showContextMenu={false}
  57. renderErrorMessage={errorMessage =>
  58. typeof errorMessage === 'string' && (
  59. <PanelAlert type="error">{errorMessage}</PanelAlert>
  60. )
  61. }
  62. onLegendSelectChanged={() => {}}
  63. legendOptions={
  64. widgetLegendState.widgetRequiresLegendUnselection(widget)
  65. ? {selected: unselectedReleasesForCharts}
  66. : undefined
  67. }
  68. widgetLegendState={widgetLegendState}
  69. // TODO: This will be filled in once we start supporting thresholds
  70. onDataFetched={() => {}}
  71. // onDataFetched={onDataFetched}
  72. // TODO: This requires the current widget ID and a helper to update the
  73. // dashboard state to be added
  74. onWidgetSplitDecision={() => {}}
  75. // onWidgetSplitDecision={onWidgetSplitDecision}
  76. />
  77. );
  78. }
  79. export default WidgetPreview;