widgetToQuery.tsx 979 B

1234567891011121314151617181920212223242526272829
  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,
  7. isQueryOnly = false,
  8. metricsNewInputs = false,
  9. }: {
  10. metricsNewInputs: boolean;
  11. widget: MetricsWidget;
  12. isQueryOnly?: boolean;
  13. }): MetricsQueryApiQueryParams {
  14. return isMetricsEquationWidget(widget)
  15. ? {
  16. name: getEquationSymbol(widget.id, metricsNewInputs),
  17. formula: widget.formula,
  18. }
  19. : {
  20. name: getQuerySymbol(widget.id, metricsNewInputs),
  21. mri: widget.mri,
  22. aggregation: widget.aggregation,
  23. condition: widget.condition,
  24. groupBy: widget.groupBy,
  25. query: widget.query,
  26. isQueryOnly: isQueryOnly || widget.isHidden,
  27. };
  28. }