Files
2024-02-15 17:01:50 +00:00

39 lines
1.0 KiB
TypeScript

import type {EventSpanData} from 'sentry/views/performance/transactionSummary/transactionReplays/useReplaysFromTransaction';
import type {ReplayListRecord} from 'sentry/views/replays/types';
type Opts = {
events: EventSpanData[];
replays: undefined | ReplayListRecord[];
};
export type ReplayListRecordWithTx = ReplayListRecord & {
txEvent: {[x: string]: any};
};
type Return = undefined | ReplayListRecordWithTx[];
function useReplaysWithTxData({events, replays}: Opts): Return {
const replaysWithTx = replays?.map<ReplayListRecordWithTx>(replay => {
const slowestEvent = events.reduce((slowest, event) => {
if (event.replayId !== replay.id) {
return slowest;
}
if (!slowest['transaction.duration']) {
return event;
}
return event['transaction.duration'] > slowest['transaction.duration']
? event
: slowest;
}, {});
return {
...replay,
txEvent: slowestEvent ?? {},
};
});
return replaysWithTx;
}
export default useReplaysWithTxData;