-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathtypes.ts
94 lines (84 loc) · 2.45 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { Provider } from 'shared/api/helpers'
import { loginProviderToName } from 'shared/utils/loginProviders'
//
// Add new events to the the Event union type below!
//
// Adding event types in this way provides type safety for names and event
// properties.
// E.g., every 'Button Clicked' event must have the buttonName property.
//
// Guidelines:
// - Event names should:
// - be of the form "[Noun] [Past-tense verb]",
// - have each word capitalized,
// - describe an action taken by the user.
// - Keep the values of `type` very generic as we have a limited number of
// them. Instead, add more detail in `properties` where possible.
// - Try to keep event property names unique to the event type to avoid
// accidental correlation of unrelated events.
// - Never include names, only use ids. E.g., use repoid instead of repo name.
//
//
// If this union type grows too unwieldy, we can split each event out into its
// own type.
//
export type Event =
| {
type: 'Button Clicked'
properties: {
buttonName: ButtonName
buttonLocation?: string
loginProvider?: ReturnType<typeof loginProviderToName> // for login buttons only
}
}
| {
type: 'Page Viewed'
properties: {
pageName: PageName
}
}
export type Identity = {
userOwnerId: number
provider: Provider
}
// Describes the context to be attached to events. We can extend this as needs
// arise in the future.
export type EventContext = {
// owner the event is being performed ON, not BY.
ownerid?: number
repoid?: number
repoIsPrivate?: boolean
path?: string
}
export abstract class EventTracker {
// Identifies the user this session belongs to.
identify(_identity: Identity): void {
throw new Error(
'EventTracker is abstract. Method identify must be implemented.'
)
}
// Tracks an event
track(_event: Event): void {
throw new Error(
'EventTracker is abstract. Method track must be implemented.'
)
}
// Sets the current EventContext - see useEventContext hook in hooks.tsx
setContext(_context: EventContext): void {
throw new Error(
'EventTracker is abstract. Method setContext must be implemented.'
)
}
}
//
// String union types to make the above Event type easier to visually parse.
// Extend as needed.
//
type ButtonName =
| 'Install GitHub App'
| 'Configure Repo'
| 'Open App Install Modal'
| 'Continue'
| 'Login'
| 'Sync'
type PageName = 'Owner Page'