hydrateA11yRecord.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. export interface A11yIssue {
  2. elements: A11yIssueElement[];
  3. help: string;
  4. help_url: string;
  5. id: string;
  6. timestamp: number;
  7. impact?: 'minor' | 'moderate' | 'serious' | 'critical';
  8. }
  9. interface A11yIssueElement {
  10. alternatives: A11yIssueElementAlternative[];
  11. element: string;
  12. target: string[];
  13. }
  14. interface A11yIssueElementAlternative {
  15. id: string;
  16. message: string;
  17. }
  18. type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
  19. export type HydratedA11yIssue = Overwrite<
  20. A11yIssue,
  21. {
  22. /**
  23. * The difference in timestamp and replay.started_at, in millieseconds
  24. */
  25. offsetMs: number;
  26. /**
  27. * The Date when the breadcrumb happened
  28. */
  29. timestamp: Date;
  30. /**
  31. * Alias of timestamp, in milliseconds
  32. */
  33. timestampMs: number;
  34. }
  35. >;
  36. export default function hydrateA11yIssue(
  37. raw: A11yIssue,
  38. startTimestampMs: number
  39. ): HydratedA11yIssue {
  40. const timestamp = new Date(raw.timestamp);
  41. return {
  42. ...raw,
  43. offsetMs: 0,
  44. timestamp,
  45. timestampMs: Math.abs(timestamp.getTime() - startTimestampMs),
  46. };
  47. }