replayHighlight.tsx 1003 B

123456789101112131415161718192021222324252627282930313233
  1. import ScoreBar from 'sentry/components/scoreBar';
  2. import CHART_PALETTE from 'sentry/constants/chartPalette';
  3. import type {ReplayListRecord} from 'sentry/views/replays/types';
  4. interface Props {
  5. replay: undefined | Pick<ReplayListRecord, 'countErrors' | 'duration' | 'urls'>;
  6. }
  7. const palette = new Array(10).fill([CHART_PALETTE[0][0]]);
  8. function ReplayHighlight({replay}: Props) {
  9. let score = 1;
  10. if (replay) {
  11. const {countErrors, duration, urls} = replay;
  12. const durationSec = duration.asSeconds();
  13. const pagesVisited = urls.length;
  14. const pagesVisitedOverTime = pagesVisited / (durationSec || 1);
  15. score = (countErrors * 25 + pagesVisited * 5 + pagesVisitedOverTime) / 10;
  16. // negatively score sub 5 second replays
  17. if (durationSec <= 5) {
  18. score = score - 10 / (durationSec || 1);
  19. }
  20. score = Math.floor(Math.min(10, Math.max(1, score)));
  21. }
  22. return <ScoreBar size={20} score={score} palette={palette} radius={0} />;
  23. }
  24. export default ReplayHighlight;