utils.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import {Location} from 'history';
  2. import {Organization} from 'sentry/types';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {AggregationKeyWithAlias, QueryFieldValue} from 'sentry/utils/discover/fields';
  5. import {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  6. import {MetricsEnhancedPerformanceDataContext} from 'sentry/utils/performance/contexts/metricsEnhancedPerformanceDataContext';
  7. import {
  8. canUseMetricsData,
  9. MetricsEnhancedSettingContext,
  10. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  11. import {decodeScalar} from 'sentry/utils/queryString';
  12. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  13. import {getMEPQueryParams} from 'sentry/views/performance/landing/widgets/utils';
  14. export function canUseTransactionMetricsData(
  15. organization: Organization,
  16. mepDataContext: MetricsEnhancedPerformanceDataContext
  17. ) {
  18. const isUsingMetrics = canUseMetricsData(organization);
  19. if (!isUsingMetrics) {
  20. return false;
  21. }
  22. if (mepDataContext.isMetricsData === false) {
  23. return false;
  24. }
  25. return true;
  26. }
  27. export function getTransactionMEPParamsIfApplicable(
  28. mepSetting: MetricsEnhancedSettingContext,
  29. mepCardinality: MetricsCardinalityContext,
  30. organization: Organization
  31. ) {
  32. if (!canUseMetricsData(organization)) {
  33. return undefined;
  34. }
  35. if (mepCardinality.outcome?.forceTransactionsOnly) {
  36. return undefined;
  37. }
  38. return getMEPQueryParams(mepSetting, true);
  39. }
  40. export function getUnfilteredTotalsEventView(
  41. eventView: EventView,
  42. location: Location,
  43. fields: AggregationKeyWithAlias[]
  44. ): EventView {
  45. const totalsColumns: QueryFieldValue[] = fields.map(field => ({
  46. kind: 'function',
  47. function: [field, '', undefined, undefined],
  48. }));
  49. const transactionName = decodeScalar(location.query.transaction);
  50. const conditions = new MutableSearch('');
  51. conditions.setFilterValues('event.type', ['transaction']);
  52. if (transactionName) {
  53. conditions.setFilterValues('transaction', [transactionName]);
  54. }
  55. const unfilteredEventView = eventView.withColumns([...totalsColumns]);
  56. unfilteredEventView.query = conditions.formatString();
  57. return unfilteredEventView;
  58. }