urls.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {OrganizationSummary} from 'sentry/types';
  2. import EventView, {EventData} from './eventView';
  3. /**
  4. * Create a slug that can be used with discover details views
  5. * or as a reference event for event-stats requests
  6. */
  7. export function generateEventSlug(eventData: EventData): string {
  8. const id = eventData.id || eventData.latest_event;
  9. const projectSlug = eventData.project || eventData['project.name'];
  10. return `${projectSlug}:${id}`;
  11. }
  12. /**
  13. * Create a URL to an event details view.
  14. */
  15. export function eventDetailsRoute({
  16. eventSlug,
  17. orgSlug,
  18. }: {
  19. eventSlug: string;
  20. orgSlug: string;
  21. }): string {
  22. return `/organizations/${orgSlug}/discover/${eventSlug}/`;
  23. }
  24. /**
  25. * Create a URL target to event details with an event view in the query string.
  26. */
  27. export function eventDetailsRouteWithEventView({
  28. orgSlug,
  29. eventSlug,
  30. eventView,
  31. isHomepage,
  32. }: {
  33. eventSlug: string;
  34. eventView: EventView;
  35. orgSlug: string;
  36. isHomepage?: boolean;
  37. }) {
  38. const pathname = eventDetailsRoute({
  39. orgSlug,
  40. eventSlug,
  41. });
  42. return {
  43. pathname,
  44. query: {...eventView.generateQueryStringObject(), homepage: isHomepage},
  45. };
  46. }
  47. /**
  48. * Get the URL for the discover entry page which changes based on organization
  49. * feature flags.
  50. */
  51. export function getDiscoverLandingUrl(organization: OrganizationSummary): string {
  52. if (organization.features.includes('discover-query')) {
  53. if (organization.features.includes('discover-query-builder-as-landing-page')) {
  54. return `/organizations/${organization.slug}/discover/homepage/`;
  55. }
  56. return getDiscoverQueriesUrl(organization);
  57. }
  58. return `/organizations/${organization.slug}/discover/results/`;
  59. }
  60. export function getDiscoverQueriesUrl(organization: OrganizationSummary): string {
  61. return `/organizations/${organization.slug}/discover/queries/`;
  62. }