utils.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type {Theme} from '@emotion/react';
  2. import type {Location, Query} from 'history';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import type {AnomalyConfidence} from 'sentry/utils/performance/anomalies/anomaliesQuery';
  5. import {decodeScalar} from 'sentry/utils/queryString';
  6. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  7. export function generateAnomaliesRoute({orgSlug}: {orgSlug: string}): string {
  8. return `/organizations/${orgSlug}/performance/summary/anomalies/`;
  9. }
  10. export const ANOMALY_FLAG = 'performance-anomaly-detection-ui';
  11. export function anomaliesRouteWithQuery({
  12. orgSlug,
  13. transaction,
  14. projectID,
  15. query,
  16. }: {
  17. orgSlug: string;
  18. query: Query;
  19. transaction: string;
  20. projectID?: string | string[];
  21. }) {
  22. const pathname = generateAnomaliesRoute({
  23. orgSlug,
  24. });
  25. return {
  26. pathname,
  27. query: {
  28. transaction,
  29. project: projectID,
  30. environment: query.environment,
  31. statsPeriod: query.statsPeriod,
  32. start: query.start,
  33. end: query.end,
  34. query: query.query,
  35. },
  36. };
  37. }
  38. export function anomalyToColor(anomalyConfidence: AnomalyConfidence, theme: Theme) {
  39. // Map inside function so it's reactive to theme.
  40. const map: Record<AnomalyConfidence, string> = {
  41. high: theme.red300,
  42. low: theme.yellow300,
  43. };
  44. return map[anomalyConfidence];
  45. }
  46. export function generateAnomaliesEventView({
  47. location,
  48. transactionName,
  49. }: {
  50. location: Location;
  51. transactionName: string;
  52. }): EventView {
  53. const query = decodeScalar(location.query.query, '');
  54. const conditions = new MutableSearch(query);
  55. conditions.setFilterValues('transaction', [transactionName]);
  56. const eventView = EventView.fromNewQueryWithLocation(
  57. {
  58. id: undefined,
  59. version: 2,
  60. name: transactionName,
  61. fields: ['tpm()'], // TODO(k-fish): Modify depending on api url later.
  62. query: conditions.formatString(),
  63. projects: [],
  64. },
  65. location
  66. );
  67. return eventView;
  68. }