-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathNotificationSettings.tsx
More file actions
427 lines (395 loc) · 14.7 KB
/
NotificationSettings.tsx
File metadata and controls
427 lines (395 loc) · 14.7 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
import { type FC, type MouseEvent, useEffect, useState } from 'react';
import {
BellIcon,
CheckIcon,
CommentIcon,
DashIcon,
GitPullRequestIcon,
IssueOpenedIcon,
MilestoneIcon,
PlusIcon,
SmileyIcon,
SyncIcon,
TagIcon,
} from '@primer/octicons-react';
import { Button, ButtonGroup, IconButton, Stack, Text } from '@primer/react';
import { formatDuration, millisecondsToMinutes } from 'date-fns';
import { APPLICATION } from '../../../shared/constants';
import { Constants } from '../../constants';
import { useAppContext } from '../../hooks/useAppContext';
import { Checkbox } from '../fields/Checkbox';
import { FieldLabel } from '../fields/FieldLabel';
import { RadioGroup } from '../fields/RadioGroup';
import { Title } from '../primitives/Title';
import { FetchType, GroupBy, Size } from '../../types';
import { openGitHubParticipatingDocs } from '../../utils/links';
export const NotificationSettings: FC = () => {
const { settings, updateSetting } = useAppContext();
const [fetchInterval, setFetchInterval] = useState<number>(
settings.fetchInterval,
);
useEffect(() => {
setFetchInterval(settings.fetchInterval);
}, [settings.fetchInterval]);
return (
<fieldset>
<Title icon={BellIcon}>Notifications</Title>
<Stack direction="vertical" gap="condensed">
<RadioGroup
label="Group by:"
name="groupBy"
onChange={(evt) => {
updateSetting('groupBy', evt.target.value as GroupBy);
}}
options={[
{ label: 'Repository', value: GroupBy.REPOSITORY },
{ label: 'Date', value: GroupBy.DATE },
]}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Choose how notifications are displayed in the list.</Text>
<Text>
<Text as="strong">Repository</Text> groups notifications by
their repository full name.
</Text>
<Text>
<Text as="strong">Date</Text> shows notifications in
chronological order.
</Text>
</Stack>
}
value={settings.groupBy}
/>
<RadioGroup
label="Fetch type:"
name="fetchType"
onChange={(evt) => {
updateSetting('fetchType', evt.target.value as FetchType);
}}
options={[
{ label: 'Interval', value: FetchType.INTERVAL },
{ label: 'Inactivity', value: FetchType.INACTIVITY },
]}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Controls how new notifications are fetched.</Text>
<Text>
<Text as="strong">Interval</Text> will check for new
notifications on a regular scheduled interval.
</Text>
<Text>
<Text as="strong">Inactivity</Text> will check for new
notifications only when there has been no user activity within{' '}
{APPLICATION.NAME} for a specified period of time.
</Text>
</Stack>
}
value={settings.fetchType}
/>
<Stack
align="center"
className="text-sm"
direction="horizontal"
gap="condensed"
>
<FieldLabel label="Fetch interval:" name="fetchInterval" />
<ButtonGroup className="ml-2">
<IconButton
aria-label="Decrease fetch interval"
data-testid="settings-fetch-interval-decrease"
icon={DashIcon}
onClick={() => {
const newInterval = Math.max(
fetchInterval -
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
Constants.MIN_FETCH_NOTIFICATIONS_INTERVAL_MS,
);
if (newInterval !== fetchInterval) {
setFetchInterval(newInterval);
updateSetting('fetchInterval', newInterval);
}
}}
size="small"
unsafeDisableTooltip={true}
/>
<Button aria-label="Fetch interval" disabled size="small">
{formatDuration({
minutes: millisecondsToMinutes(fetchInterval),
})}
</Button>
<IconButton
aria-label="Increase fetch interval"
data-testid="settings-fetch-interval-increase"
icon={PlusIcon}
onClick={() => {
const newInterval = Math.min(
fetchInterval +
Constants.FETCH_NOTIFICATIONS_INTERVAL_STEP_MS,
Constants.MAX_FETCH_NOTIFICATIONS_INTERVAL_MS,
);
if (newInterval !== fetchInterval) {
setFetchInterval(newInterval);
updateSetting('fetchInterval', newInterval);
}
}}
size="small"
unsafeDisableTooltip={true}
/>
<IconButton
aria-label="Reset fetch interval"
data-testid="settings-fetch-interval-reset"
icon={SyncIcon}
onClick={() => {
setFetchInterval(
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
);
updateSetting(
'fetchInterval',
Constants.DEFAULT_FETCH_NOTIFICATIONS_INTERVAL_MS,
);
}}
size="small"
unsafeDisableTooltip={true}
variant="danger"
/>
</ButtonGroup>
</Stack>
<Checkbox
checked={settings.fetchAllNotifications}
label="Fetch all notifications"
name="fetchAllNotifications"
onChange={() =>
updateSetting(
'fetchAllNotifications',
!settings.fetchAllNotifications,
)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
When <Text as="u">checked</Text>, {APPLICATION.NAME} will fetch{' '}
<Text as="strong">all</Text> notifications from your inbox.
</Text>
<Text>
When <Text as="u">unchecked</Text>, {APPLICATION.NAME} will
fetch the first page of notifications (max 50 records per GitHub
account)
</Text>
</Stack>
}
/>
<Checkbox
checked={settings.detailedNotifications}
label="Fetch detailed notifications"
name="detailedNotifications"
onChange={() =>
updateSetting(
'detailedNotifications',
!settings.detailedNotifications,
)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
When <Text as="u">checked</Text>, {APPLICATION.NAME} will enrich
notifications with detailed user and state information. You may
also choose to display{' '}
<Text as="strong">notification metric pills</Text> or{' '}
<Text as="strong">notification reference numbers</Text>.
</Text>
<Text>
When <Text as="u">unchecked</Text>, {APPLICATION.NAME} will only
fetch basic notification details.
</Text>
<Text className="text-gitify-caution">
⚠️ Users with a large number of unread notifications <i>may</i>{' '}
experience rate limiting under certain circumstances. Please
disable this setting if you experience this.
</Text>
</Stack>
}
/>
<div className="pl-6" hidden={!settings.detailedNotifications}>
<Stack direction="vertical" gap="condensed">
<Checkbox
checked={settings.showPills}
label="Show notification metric pills"
name="showPills"
onChange={() => updateSetting('showPills', !settings.showPills)}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Show notification metric pills for:</Text>
<div className="pl-2">
<Stack direction="vertical" gap="none">
<Stack direction="horizontal" gap="condensed">
<IssueOpenedIcon size={Size.SMALL} />
linked issues
</Stack>
<Stack direction="horizontal" gap="condensed">
<SmileyIcon size={Size.SMALL} />
reactions
</Stack>
<Stack direction="horizontal" gap="condensed">
<CheckIcon size={Size.SMALL} />
pr reviews
</Stack>
<Stack direction="horizontal" gap="condensed">
<CommentIcon size={Size.SMALL} />
comments
</Stack>
<Stack direction="horizontal" gap="condensed">
<TagIcon size={Size.SMALL} />
labels
</Stack>
<Stack direction="horizontal" gap="condensed">
<MilestoneIcon size={Size.SMALL} />
milestones
</Stack>
</Stack>
</div>
</Stack>
}
/>
<Checkbox
checked={settings.showNumber}
label="Show GitHub number"
name="showNumber"
onChange={() => updateSetting('showNumber', !settings.showNumber)}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Show GitHub number for:</Text>
<div className="pl-2">
<Stack direction="vertical" gap="none">
<Stack direction="horizontal" gap="condensed">
<CommentIcon size={Size.SMALL} />
Discussion
</Stack>
<Stack direction="horizontal" gap="condensed">
<IssueOpenedIcon size={Size.SMALL} />
Issue
</Stack>
<Stack direction="horizontal" gap="condensed">
<GitPullRequestIcon size={Size.SMALL} />
Pull Request
</Stack>
</Stack>
</div>
</Stack>
}
/>
</Stack>
</div>
<Checkbox
checked={settings.participating}
label="Fetch only participating"
name="showOnlyParticipating"
onChange={() =>
updateSetting('participating', !settings.participating)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>
When <Text as="u">checked</Text>, {APPLICATION.NAME} will fetch
only participating notifications.
</Text>
<Text>
When <Text as="u">unchecked</Text>, {APPLICATION.NAME} will
fetch participating and watching notifications.
</Text>
<Text>
See{' '}
<button
className="text-gitify-link cursor-pointer"
onClick={(event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
event.stopPropagation();
openGitHubParticipatingDocs();
}}
title="Open GitHub documentation for participating and watching notifications"
type="button"
>
official docs
</button>{' '}
for more details.
</Text>
</Stack>
}
/>
<Checkbox
checked={settings.fetchReadNotifications}
label="Fetch read & done notifications"
name="fetchReadNotifications"
onChange={() =>
updateSetting(
'fetchReadNotifications',
!settings.fetchReadNotifications,
)
}
tooltip={
<Stack direction="vertical" gap="condensed">
<Text>Fetch all notifications including read and done.</Text>
<Text className="text-gitify-caution">
⚠️ GitHub's API does not distinguish between read and done
states, so 'Mark as done' actions will be unavailable when this
setting is enabled.
</Text>
<Text className="text-gitify-caution">
⚠️ Enabling this setting will increase API usage and may cause
rate limiting for users with many notifications.
</Text>
</Stack>
}
/>
<Checkbox
checked={settings.markAsDoneOnOpen}
label="Mark as done on open"
name="markAsDoneOnOpen"
onChange={() =>
updateSetting('markAsDoneOnOpen', !settings.markAsDoneOnOpen)
}
tooltip={
<Text>
<Text as="strong">Mark as done</Text> feature is supported in
GitHub Cloud and GitHub Enterprise Server 3.13 or later.
</Text>
}
/>
<Checkbox
checked={settings.markAsDoneOnUnsubscribe}
label="Mark as done on unsubscribe"
name="markAsDoneOnUnsubscribe"
onChange={() =>
updateSetting(
'markAsDoneOnUnsubscribe',
!settings.markAsDoneOnUnsubscribe,
)
}
tooltip={
<Text>
<Text as="strong">Mark as done</Text> feature is supported in
GitHub Cloud and GitHub Enterprise Server 3.13 or later.
</Text>
}
/>
<Checkbox
checked={settings.delayNotificationState}
label="Delay notification state"
name="delayNotificationState"
onChange={() =>
updateSetting(
'delayNotificationState',
!settings.delayNotificationState,
)
}
tooltip={
<Text>
Keep the notification within {APPLICATION.NAME} upon interaction
(ie: open notification, mark as read, mark as done) until the next
refresh window (scheduled or user initiated).
</Text>
}
/>
</Stack>
</fieldset>
);
};