urls.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 (
  51. organization.features.includes('discover-query') &&
  52. !organization.features.includes('discover-query-builder-as-landing-page')
  53. ) {
  54. return getDiscoverQueriesUrl(organization);
  55. }
  56. return `/organizations/${organization.slug}/discover/results/`;
  57. }
  58. export function getDiscoverQueriesUrl(organization: OrganizationSummary): string {
  59. return `/organizations/${organization.slug}/discover/queries/`;
  60. }