spanDescriptionLink.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {Link} from 'react-router';
  2. import * as qs from 'query-string';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import {OverflowEllipsisTextContainer} from 'sentry/views/starfish/components/textAlign';
  5. import {SpanFunction} from 'sentry/views/starfish/types';
  6. import {extractRoute} from 'sentry/views/starfish/utils/extractRoute';
  7. import {useRoutingContext} from 'sentry/views/starfish/utils/routingContext';
  8. import {QueryParameterNames} from 'sentry/views/starfish/views/queryParameters';
  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 routingContext = useRoutingContext();
  25. const queryString = {
  26. ...location.query,
  27. project: projectId,
  28. endpoint,
  29. endpointMethod,
  30. };
  31. const sort: string | undefined = queryString[QueryParameterNames.SPANS_SORT];
  32. // the spans page uses time_spent_percentage(local), so to persist the sort upon navigation we need to replace
  33. if (sort?.includes(`${SpanFunction.TIME_SPENT_PERCENTAGE}()`)) {
  34. queryString[QueryParameterNames.SPANS_SORT] = sort.replace(
  35. `${SpanFunction.TIME_SPENT_PERCENTAGE}()`,
  36. `${SpanFunction.TIME_SPENT_PERCENTAGE}(local)`
  37. );
  38. }
  39. return (
  40. <OverflowEllipsisTextContainer>
  41. {group ? (
  42. <Link
  43. to={`${routingContext.baseURL}/${
  44. extractRoute(location) ?? 'spans'
  45. }/span/${group}?${qs.stringify(queryString)}`}
  46. >
  47. {description}
  48. </Link>
  49. ) : (
  50. description
  51. )}
  52. </OverflowEllipsisTextContainer>
  53. );
  54. }