transactionCell.tsx 1.5 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. interface Props {
  8. domain?: string;
  9. project?: string;
  10. transaction?: string;
  11. transactionMethod?: string;
  12. }
  13. export function TransactionCell({
  14. domain,
  15. project,
  16. transaction,
  17. transactionMethod,
  18. }: Props) {
  19. const location = useLocation();
  20. const organization = useOrganization();
  21. if (!domain || !transaction) {
  22. return NULL_DESCRIPTION;
  23. }
  24. // 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
  25. const label =
  26. transactionMethod && !transaction.startsWith(transactionMethod)
  27. ? `${transactionMethod} ${transaction}`
  28. : transaction;
  29. const pathname = normalizeUrl(
  30. `/organizations/${organization.slug}/performance/http/domains/`
  31. );
  32. const query = {
  33. ...location.query,
  34. domain,
  35. project,
  36. transaction,
  37. transactionMethod,
  38. };
  39. return (
  40. <OverflowEllipsisTextContainer>
  41. <Link to={`${pathname}?${qs.stringify(query)}`}>{label}</Link>
  42. </OverflowEllipsisTextContainer>
  43. );
  44. }
  45. const NULL_DESCRIPTION = <span>&lt;null&gt;</span>;