useReplaysWithTxData.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  18. if (!slowest['transaction.duration']) {
  19. return event;
  20. }
  21. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  22. return event['transaction.duration'] > slowest['transaction.duration']
  23. ? event
  24. : slowest;
  25. }, {});
  26. return {
  27. ...replay,
  28. txEvent: slowestEvent ?? {},
  29. };
  30. });
  31. return replaysWithTx;
  32. }
  33. export default useReplaysWithTxData;