diff --git a/frontend/app/types/session/session.ts b/frontend/app/types/session/session.ts index 6e6fe5aaa..239871600 100644 --- a/frontend/app/types/session/session.ts +++ b/frontend/app/types/session/session.ts @@ -9,7 +9,7 @@ import { toJS } from 'mobx'; const HASH_MOD = 1610612741; const HASH_P = 53; -function mergeEventLists(arr1: any[], arr2: any[]) { +function mergeEventLists, Y extends Record>(arr1: T[], arr2: Y[]): Array { let merged = []; let index1 = 0; let index2 = 0; @@ -33,6 +33,12 @@ function mergeEventLists(arr1: any[], arr2: any[]) { return merged; } +function sortEvents(a: Record, b: Record) { + const aTs = a.timestamp || a.time; + const bTs = b.timestamp || b.time; + + return aTs - bTs; +} function hashString(s: string): number { let mul = 1; @@ -259,19 +265,12 @@ export default class Session { ) const frustrationIssues = issuesList.filter(i => i.type === issueTypes.MOUSE_THRASHING) - const frustrationList = [...frustrationEvents, ...frustrationIssues].sort((a, b) => { - // @ts-ignore - const aTs = a.timestamp || a.time; - // @ts-ignore - const bTs = b.timestamp || b.time; - - return aTs - bTs; - }) || []; + const frustrationList = [...frustrationEvents, ...frustrationIssues].sort(sortEvents) || []; const mixedEventsWithIssues = mergeEventLists( mergeEventLists(rawEvents, rawNotes), frustrationIssues - ) + ).sort(sortEvents) Object.assign(this, { ...session, @@ -303,11 +302,9 @@ export default class Session { domURL, devtoolsURL, notes, - notesWithEvents: notesWithEvents, - }); notesWithEvents: mixedEventsWithIssues, frustrations: frustrationList, - }) + }); } addEvents( @@ -347,14 +344,32 @@ export default class Session { }); } + const frustrationEvents = events.filter(ev => { + if (ev.type === TYPES.CLICK || ev.type === TYPES.INPUT) { + // @ts-ignore + return ev.hesitation > 1000 + } + return ev.type === TYPES.CLICKRAGE + } + ) + const frustrationIssues = issuesList.filter(i => i.type === issueTypes.MOUSE_THRASHING) + const frustrationList = [...frustrationEvents, ...frustrationIssues].sort(sortEvents) || []; + + const mixedEventsWithIssues = mergeEventLists( + rawEvents, + frustrationIssues + ).sort(sortEvents) + this.events = events; // @ts-ignore - this.notesWithEvents = rawEvents; + this.notesWithEvents = mixedEventsWithIssues; this.errors = exceptions; this.issues = issuesList; // @ts-ignore legacy code? no idea this.resources = resources; this.stackEvents = stackEventsList; + // @ts-ignore + this.frustrations = frustrationList; return this; } @@ -365,7 +380,7 @@ export default class Session { [...this.notesWithEvents, ...sessionNotes].sort((a, b) => { // @ts-ignore just in case const aTs = a.timestamp || a.time; - // @ts-ignore + // @ts-ignore supporting old code... const bTs = b.timestamp || b.time; return aTs - bTs;