spanDescriptionLink.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import {Link} from 'react-router';
  2. import * as qs from 'query-string';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import useOrganization from 'sentry/utils/useOrganization';
  5. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  6. import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
  7. import {SpanMetricsField} from 'sentry/views/starfish/types';
  8. import {extractRoute} from 'sentry/views/starfish/utils/extractRoute';
  9. import {useRoutingContext} from 'sentry/views/starfish/utils/routingContext';
  10. const {SPAN_OP} = SpanMetricsField;
  11. interface Props {
  12. description: React.ReactNode;
  13. projectId: number;
  14. endpoint?: string;
  15. endpointMethod?: string;
  16. group?: string;
  17. spanOp?: string;
  18. }
  19. export function SpanDescriptionLink({
  20. group,
  21. projectId,
  22. endpoint,
  23. endpointMethod,
  24. spanOp,
  25. description,
  26. }: Props) {
  27. const location = useLocation();
  28. const organization = useOrganization();
  29. const routingContext = useRoutingContext();
  30. const queryString = {
  31. ...location.query,
  32. project: projectId,
  33. endpoint,
  34. endpointMethod,
  35. ...(spanOp ? {[SPAN_OP]: spanOp} : {}),
  36. };
  37. return (
  38. <OverflowEllipsisTextContainer>
  39. {group ? (
  40. <Link
  41. to={normalizeUrl(
  42. `/organizations/${organization.slug}${routingContext.baseURL}/${
  43. extractRoute(location) ?? 'spans'
  44. }/span/${group}?${qs.stringify(queryString)}`
  45. )}
  46. >
  47. {description}
  48. </Link>
  49. ) : (
  50. description
  51. )}
  52. </OverflowEllipsisTextContainer>
  53. );
  54. }