convertWidgetToBuilderStateParams.ts 751 B

12345678910111213141516171819202122
  1. import {DisplayType, type Widget, WidgetType} from 'sentry/views/dashboards/types';
  2. import type {WidgetBuilderStateQueryParams} from 'sentry/views/dashboards/widgetBuilder/hooks/useWidgetBuilderState';
  3. /**
  4. * Converts a widget to a set of query params that can be used to
  5. * restore the widget builder state.
  6. */
  7. export function convertWidgetToBuilderStateParams(
  8. widget: Widget
  9. ): WidgetBuilderStateQueryParams {
  10. const yAxis = widget.queries.flatMap(q => q.aggregates);
  11. const field = widget.queries.flatMap(q => q.fields);
  12. return {
  13. title: widget.title,
  14. description: widget.description ?? '',
  15. dataset: widget.widgetType ?? WidgetType.ERRORS,
  16. displayType: widget.displayType ?? DisplayType.TABLE,
  17. field,
  18. yAxis,
  19. };
  20. }