replayHighlight.tsx 976 B

12345678910111213141516171819202122232425262728293031323334
  1. import React from 'react';
  2. import ScoreBar from 'sentry/components/scoreBar';
  3. import CHART_PALETTE from 'sentry/constants/chartPalette';
  4. import type {ReplayListRecord} from 'sentry/views/replays/types';
  5. interface Props {
  6. replay: undefined | Pick<ReplayListRecord, 'countErrors' | 'duration' | 'urls'>;
  7. }
  8. const palette = new Array(10).fill([CHART_PALETTE[0][0]]);
  9. function ReplayHighlight({replay}: Props) {
  10. let score = 1;
  11. if (replay) {
  12. const {countErrors, duration, urls} = replay;
  13. const pagesVisited = urls.length;
  14. const pagesVisitedOverTime = pagesVisited / (duration || 1);
  15. score = (countErrors * 25 + pagesVisited * 5 + pagesVisitedOverTime) / 10;
  16. // negatively score sub 5 second replays
  17. if (duration <= 5) {
  18. score = score - 10 / (duration || 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;