replayHighlight.tsx 948 B

1234567891011121314151617181920212223242526272829303132
  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 pagesVisited = urls.length;
  13. const pagesVisitedOverTime = pagesVisited / (duration || 1);
  14. score = (countErrors * 25 + pagesVisited * 5 + pagesVisitedOverTime) / 10;
  15. // negatively score sub 5 second replays
  16. if (duration <= 5) {
  17. score = score - 10 / (duration || 1);
  18. }
  19. score = Math.floor(Math.min(10, Math.max(1, score)));
  20. }
  21. return <ScoreBar size={20} score={score} palette={palette} radius={0} />;
  22. }
  23. export default ReplayHighlight;