widgetToQuery.tsx 843 B

123456789101112131415161718192021222324
  1. import {getEquationSymbol} from 'sentry/components/metrics/equationSymbol';
  2. import {getQuerySymbol} from 'sentry/components/metrics/querySymbol';
  3. import {isMetricsEquationWidget, type MetricsWidget} from 'sentry/utils/metrics/types';
  4. import type {MetricsQueryApiQueryParams} from 'sentry/utils/metrics/useMetricsQuery';
  5. export function widgetToQuery(
  6. widget: MetricsWidget,
  7. isQueryOnly = false
  8. ): MetricsQueryApiQueryParams {
  9. return isMetricsEquationWidget(widget)
  10. ? {
  11. name: getEquationSymbol(widget.id),
  12. formula: widget.formula,
  13. }
  14. : {
  15. name: getQuerySymbol(widget.id),
  16. mri: widget.mri,
  17. aggregation: widget.aggregation,
  18. condition: widget.condition,
  19. groupBy: widget.groupBy,
  20. query: widget.query,
  21. isQueryOnly: isQueryOnly || widget.isHidden,
  22. };
  23. }