useReplaysWithTxData.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import type {EventSpanData} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysFromTransaction';
  2. import type {ReplayListRecord} from 'sentry/views/replays/types';
  3. type Opts = {
  4. events: EventSpanData[];
  5. replays: undefined | ReplayListRecord[];
  6. };
  7. export type ReplayListRecordWithTx = ReplayListRecord & {
  8. txEvent: {[x: string]: any};
  9. };
  10. type Return = undefined | ReplayListRecordWithTx[];
  11. function useReplaysWithTxData({events, replays}: Opts): Return {
  12. const replaysWithTx = replays?.map<ReplayListRecordWithTx>(replay => {
  13. const slowestEvent = events.reduce((slowest, event) => {
  14. if (event.replayId !== replay.id) {
  15. return slowest;
  16. }
  17. if (!slowest['transaction.duration']) {
  18. return event;
  19. }
  20. return event['transaction.duration'] > slowest['transaction.duration']
  21. ? event
  22. : slowest;
  23. }, {});
  24. return {
  25. ...replay,
  26. txEvent: slowestEvent ?? {},
  27. };
  28. });
  29. return replaysWithTx;
  30. }
  31. export default useReplaysWithTxData;