urls.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. }: {
  32. eventSlug: string;
  33. eventView: EventView;
  34. orgSlug: string;
  35. }) {
  36. const pathname = eventDetailsRoute({
  37. orgSlug,
  38. eventSlug,
  39. });
  40. return {
  41. pathname,
  42. query: eventView.generateQueryStringObject(),
  43. };
  44. }
  45. /**
  46. * Get the URL for the discover entry page which changes based on organization
  47. * feature flags.
  48. */
  49. export function getDiscoverLandingUrl(organization: OrganizationSummary): string {
  50. if (organization.features.includes('discover-query')) {
  51. return `/organizations/${organization.slug}/discover/queries/`;
  52. }
  53. return `/organizations/${organization.slug}/discover/results/`;
  54. }