transactionCell.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import * as qs from 'query-string';
  2. import Link from 'sentry/components/links/link';
  3. import {useLocation} from 'sentry/utils/useLocation';
  4. import {OverflowEllipsisTextContainer} from 'sentry/views/insights/common/components/textAlign';
  5. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  6. interface Props {
  7. domain?: string;
  8. project?: string;
  9. transaction?: string;
  10. transactionMethod?: string;
  11. }
  12. export function TransactionCell({
  13. domain,
  14. project,
  15. transaction,
  16. transactionMethod,
  17. }: Props) {
  18. const moduleURL = useModuleURL('http');
  19. const location = useLocation();
  20. if (!transaction) {
  21. return NULL_DESCRIPTION;
  22. }
  23. // TODO: This checks if the transaction name starts with the request method so we don't end up with labels like `GET GET /users` but any transaction name with an HTTP method prefix is incorrect, so it's not clear that we should cater to this
  24. const label =
  25. transactionMethod && !transaction.startsWith(transactionMethod)
  26. ? `${transactionMethod} ${transaction}`
  27. : transaction;
  28. const pathname = `${moduleURL}/domains/`;
  29. const query = {
  30. ...location.query,
  31. domain,
  32. project,
  33. transaction,
  34. transactionMethod,
  35. };
  36. return (
  37. <OverflowEllipsisTextContainer>
  38. <Link to={`${pathname}?${qs.stringify(query)}`}>{label}</Link>
  39. </OverflowEllipsisTextContainer>
  40. );
  41. }
  42. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;