utils.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import styled from '@emotion/styled';
  2. import {LocationDescriptor, Query} from 'history';
  3. import space from 'sentry/styles/space';
  4. import {Organization} from 'sentry/types';
  5. import {TableDataRow} from 'sentry/utils/discover/discoverQuery';
  6. import {generateEventSlug} from 'sentry/utils/discover/urls';
  7. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  8. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  9. import {getTraceDetailsUrl} from 'sentry/views/performance/traceDetails/utils';
  10. import {DisplayModes} from './transactionOverview/charts';
  11. export enum TransactionFilterOptions {
  12. FASTEST = 'fastest',
  13. SLOW = 'slow',
  14. OUTLIER = 'outlier',
  15. RECENT = 'recent',
  16. }
  17. export function generateTransactionSummaryRoute({orgSlug}: {orgSlug: String}): string {
  18. return `/organizations/${orgSlug}/performance/summary/`;
  19. }
  20. // normalizes search conditions by removing any redundant search conditions before presenting them in:
  21. // - query strings
  22. // - search UI
  23. export function normalizeSearchConditions(query: string): MutableSearch {
  24. const filterParams = normalizeSearchConditionsWithTransactionName(query);
  25. // no need to include transaction as its already in the query params
  26. filterParams.removeFilter('transaction');
  27. return filterParams;
  28. }
  29. // normalizes search conditions by removing any redundant search conditions, but retains any transaction name
  30. export function normalizeSearchConditionsWithTransactionName(
  31. query: string
  32. ): MutableSearch {
  33. const filterParams = new MutableSearch(query);
  34. // remove any event.type queries since it is implied to apply to only transactions
  35. filterParams.removeFilter('event.type');
  36. return filterParams;
  37. }
  38. export function transactionSummaryRouteWithQuery({
  39. orgSlug,
  40. transaction,
  41. projectID,
  42. query,
  43. unselectedSeries = 'p100()',
  44. display,
  45. trendFunction,
  46. trendColumn,
  47. showTransactions,
  48. additionalQuery,
  49. }: {
  50. orgSlug: string;
  51. query: Query;
  52. transaction: string;
  53. additionalQuery?: Record<string, string>;
  54. display?: DisplayModes;
  55. projectID?: string | string[];
  56. showTransactions?: TransactionFilterOptions;
  57. trendColumn?: string;
  58. trendFunction?: string;
  59. unselectedSeries?: string | string[];
  60. }) {
  61. const pathname = generateTransactionSummaryRoute({
  62. orgSlug,
  63. });
  64. let searchFilter: typeof query.query;
  65. if (typeof query.query === 'string') {
  66. searchFilter = normalizeSearchConditions(query.query).formatString();
  67. } else {
  68. searchFilter = query.query;
  69. }
  70. return {
  71. pathname,
  72. query: {
  73. transaction,
  74. project: projectID,
  75. environment: query.environment,
  76. statsPeriod: query.statsPeriod,
  77. start: query.start,
  78. end: query.end,
  79. query: searchFilter,
  80. unselectedSeries,
  81. showTransactions,
  82. display,
  83. trendFunction,
  84. trendColumn,
  85. ...additionalQuery,
  86. },
  87. };
  88. }
  89. export function generateTraceLink(dateSelection) {
  90. return (
  91. organization: Organization,
  92. tableRow: TableDataRow,
  93. _query: Query
  94. ): LocationDescriptor => {
  95. const traceId = `${tableRow.trace}`;
  96. if (!traceId) {
  97. return {};
  98. }
  99. return getTraceDetailsUrl(organization, traceId, dateSelection, {});
  100. };
  101. }
  102. export function generateTransactionLink(transactionName: string) {
  103. return (
  104. organization: Organization,
  105. tableRow: TableDataRow,
  106. query: Query,
  107. spanId?: string
  108. ): LocationDescriptor => {
  109. const eventSlug = generateEventSlug(tableRow);
  110. return getTransactionDetailsUrl(
  111. organization.slug,
  112. eventSlug,
  113. transactionName,
  114. query,
  115. spanId
  116. );
  117. };
  118. }
  119. export const SidebarSpacer = styled('div')`
  120. margin-top: ${space(3)};
  121. `;