spanDescriptionLink.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 {extractRoute} from 'sentry/views/starfish/utils/extractRoute';
  8. import {useRoutingContext} from 'sentry/views/starfish/utils/routingContext';
  9. interface Props {
  10. description: React.ReactNode;
  11. projectId: number;
  12. endpoint?: string;
  13. endpointMethod?: string;
  14. group?: string;
  15. }
  16. export function SpanDescriptionLink({
  17. group,
  18. projectId,
  19. endpoint,
  20. endpointMethod,
  21. description,
  22. }: Props) {
  23. const location = useLocation();
  24. const organization = useOrganization();
  25. const routingContext = useRoutingContext();
  26. const queryString = {
  27. ...location.query,
  28. project: projectId,
  29. endpoint,
  30. endpointMethod,
  31. };
  32. return (
  33. <OverflowEllipsisTextContainer>
  34. {group ? (
  35. <Link
  36. to={normalizeUrl(
  37. `/organizations/${organization.slug}${routingContext.baseURL}/${
  38. extractRoute(location) ?? 'spans'
  39. }/span/${group}?${qs.stringify(queryString)}`
  40. )}
  41. >
  42. {description}
  43. </Link>
  44. ) : (
  45. description
  46. )}
  47. </OverflowEllipsisTextContainer>
  48. );
  49. }