utils.tsx 1.9 KB

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