getSelectedTransaction.tsx 965 B

1234567891011121314151617181920212223242526272829303132
  1. import type {Location} from 'history';
  2. import {decodeScalar} from 'sentry/utils/queryString';
  3. import type {
  4. NormalizedTrendsTransaction,
  5. TrendChangeType,
  6. } from 'sentry/views/performance/trends/types';
  7. import getSelectedQueryKey from 'sentry/views/performance/trends/utils/getSelectedQueryKey';
  8. export function getSelectedTransaction(
  9. location: Location,
  10. trendChangeType: TrendChangeType,
  11. transactions?: NormalizedTrendsTransaction[]
  12. ): NormalizedTrendsTransaction | undefined {
  13. const queryKey = getSelectedQueryKey(trendChangeType);
  14. const selectedTransactionName = decodeScalar(location.query[queryKey]);
  15. if (!transactions) {
  16. return undefined;
  17. }
  18. const selectedTransaction = transactions.find(
  19. transaction =>
  20. `${transaction.transaction}-${transaction.project}` === selectedTransactionName
  21. );
  22. if (selectedTransaction) {
  23. return selectedTransaction;
  24. }
  25. return transactions.length > 0 ? transactions[0] : undefined;
  26. }