spanGroupDetailsLink.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import * as qs from 'query-string';
  2. import Link from 'sentry/components/links/link';
  3. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  4. import {useLocation} from 'sentry/utils/useLocation';
  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. // extra query params to add to the link
  12. moduleName: ModuleName.DB | ModuleName.RESOURCE;
  13. projectId: number;
  14. extraLinkQueryParams?: Record<string, string>;
  15. group?: string;
  16. spanOp?: string;
  17. }
  18. export function SpanGroupDetailsLink({
  19. moduleName,
  20. group,
  21. projectId,
  22. spanOp,
  23. description,
  24. extraLinkQueryParams,
  25. }: Props) {
  26. const location = useLocation();
  27. const moduleURL = useModuleURL(moduleName);
  28. const queryString = {
  29. ...location.query,
  30. project: projectId,
  31. ...(spanOp ? {[SPAN_OP]: spanOp} : {}),
  32. ...(extraLinkQueryParams ? extraLinkQueryParams : {}),
  33. };
  34. return (
  35. <OverflowEllipsisTextContainer>
  36. {group ? (
  37. <Link
  38. to={normalizeUrl(
  39. `${moduleURL}/spans/span/${group}/?${qs.stringify(queryString)}`
  40. )}
  41. >
  42. {description}
  43. </Link>
  44. ) : (
  45. description
  46. )}
  47. </OverflowEllipsisTextContainer>
  48. );
  49. }