spanGroupDetailsLink.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import * as qs from 'query-string';
  2. import Link from 'sentry/components/links/link';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  5. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  6. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  7. import {type ModuleName, SpanMetricsField} from 'sentry/views/insights/types';
  8. const {SPAN_OP} = SpanMetricsField;
  9. interface Props {
  10. description: React.ReactNode;
  11. moduleName: ModuleName.DB | ModuleName.RESOURCE;
  12. projectId: number;
  13. group?: string;
  14. spanOp?: string;
  15. }
  16. export function SpanGroupDetailsLink({
  17. moduleName,
  18. group,
  19. projectId,
  20. spanOp,
  21. description,
  22. }: Props) {
  23. const location = useLocation();
  24. const moduleURL = useModuleURL(moduleName);
  25. const queryString = {
  26. ...location.query,
  27. project: projectId,
  28. ...(spanOp ? {[SPAN_OP]: spanOp} : {}),
  29. };
  30. return (
  31. <OverflowEllipsisTextContainer>
  32. {group ? (
  33. <Link
  34. to={normalizeUrl(
  35. `${moduleURL}/spans/span/${group}/?${qs.stringify(queryString)}`
  36. )}
  37. >
  38. {description}
  39. </Link>
  40. ) : (
  41. description
  42. )}
  43. </OverflowEllipsisTextContainer>
  44. );
  45. }