1
1
import React , { FunctionComponent , useState } from 'react' ;
2
- import { NotificationsLines_data$data } from '@components/profile/notifications/__generated__/NotificationsLines_data.graphql' ;
3
- import { notificationLineFragment } from '@components/profile/notifications/NotificationLine' ;
4
2
import { Badge , Tooltip } from '@mui/material' ;
5
3
import Chip from '@mui/material/Chip' ;
6
4
import { deepPurple , green , indigo , red } from '@mui/material/colors' ;
7
5
import { BellCogOutline , BellOutline , BellPlusOutline , BellRemoveOutline , FileTableBoxMultipleOutline } from 'mdi-material-ui' ;
8
- import { NotificationLine_node$data } from '@components/profile/notifications/__generated__/NotificationLine_node.graphql' ;
9
6
import IconButton from '@mui/material/IconButton' ;
10
7
import { CheckCircleOutlined , DeleteOutlined , UnpublishedOutlined } from '@mui/icons-material' ;
11
8
import { graphql } from 'react-relay' ;
@@ -14,10 +11,11 @@ import DialogContent from '@mui/material/DialogContent';
14
11
import DialogContentText from '@mui/material/DialogContentText' ;
15
12
import Button from '@mui/material/Button' ;
16
13
import DialogActions from '@mui/material/DialogActions' ;
14
+ import { NotificationsLine_node$data } from '@components/profile/__generated__/NotificationsLine_node.graphql' ;
15
+ import { NotificationsLinesPaginationQuery , NotificationsLinesPaginationQuery$variables } from '@components/profile/__generated__/NotificationsLinesPaginationQuery.graphql' ;
16
+ import { NotificationsLines_data$data } from '@components/profile/__generated__/NotificationsLines_data.graphql' ;
17
17
import { usePaginationLocalStorage } from '../../../utils/hooks/useLocalStorage' ;
18
18
import useQueryLoading from '../../../utils/hooks/useQueryLoading' ;
19
- import { notificationsLinesFragment , notificationsLinesQuery } from './notifications/NotificationsLines' ;
20
- import { NotificationsLinesPaginationQuery , NotificationsLinesPaginationQuery$variables } from './notifications/__generated__/NotificationsLinesPaginationQuery.graphql' ;
21
19
import useAuth from '../../../utils/hooks/useAuth' ;
22
20
import { emptyFilterGroup , isFilterGroupNotEmpty , useGetDefaultFilterObject , useRemoveIdAndIncorrectKeysFromFilterGroupObject } from '../../../utils/filters/filtersUtils' ;
23
21
import Breadcrumbs from '../../../components/Breadcrumbs' ;
@@ -34,13 +32,87 @@ import { deleteNode } from '../../../utils/store';
34
32
35
33
export const LOCAL_STORAGE_KEY = 'notifiers' ;
36
34
35
+ const notificationsLineFragment = graphql `
36
+ fragment NotificationsLine_node on Notification {
37
+ id
38
+ entity_type
39
+ name
40
+ created
41
+ notification_type
42
+ is_read
43
+ notification_content {
44
+ title
45
+ events {
46
+ message
47
+ operation
48
+ instance_id
49
+ }
50
+ }
51
+ }
52
+ ` ;
53
+
54
+ const notificationsLinesQuery = graphql `
55
+ query NotificationsLinesPaginationQuery(
56
+ $search: String
57
+ $count: Int!
58
+ $cursor: ID
59
+ $orderBy: NotificationsOrdering
60
+ $orderMode: OrderingMode
61
+ $filters: FilterGroup
62
+ ) {
63
+ ...NotificationsLines_data
64
+ @arguments(
65
+ search: $search
66
+ count: $count
67
+ cursor: $cursor
68
+ orderBy: $orderBy
69
+ orderMode: $orderMode
70
+ filters: $filters
71
+ )
72
+ }
73
+ ` ;
74
+
75
+ const notificationsLinesFragment = graphql `
76
+ fragment NotificationsLines_data on Query
77
+ @argumentDefinitions(
78
+ search: { type: "String" }
79
+ count: { type: "Int", defaultValue: 25 }
80
+ cursor: { type: "ID" }
81
+ orderBy: { type: "NotificationsOrdering", defaultValue: created }
82
+ orderMode: { type: "OrderingMode", defaultValue: asc }
83
+ filters: { type: "FilterGroup" }
84
+ )
85
+ @refetchable(queryName: "NotificationsLinesRefetchQuery") {
86
+ myNotifications(
87
+ search: $search
88
+ first: $count
89
+ after: $cursor
90
+ orderBy: $orderBy
91
+ orderMode: $orderMode
92
+ filters: $filters
93
+ ) @connection(key: "Pagination_myNotifications") {
94
+ edges {
95
+ node {
96
+ id
97
+ ...NotificationsLine_node
98
+ }
99
+ }
100
+ pageInfo {
101
+ endCursor
102
+ hasNextPage
103
+ globalCount
104
+ }
105
+ }
106
+ }
107
+ ` ;
108
+
37
109
export const notificationLineNotificationMarkReadMutation = graphql `
38
110
mutation NotificationsNotificationMarkReadMutation(
39
111
$id: ID!
40
112
$read: Boolean!
41
113
) {
42
114
notificationMarkRead(id: $id, read: $read) {
43
- ...NotificationLine_node
115
+ ...NotificationsLine_node
44
116
}
45
117
}
46
118
` ;
@@ -61,7 +133,7 @@ const Notifications: FunctionComponent = () => {
61
133
const [ commitDelete ] = useApiMutation (
62
134
notificationLineNotificationDeleteMutation ,
63
135
) ;
64
- const [ notificationToDelete , setNotificationToDelete ] = useState < NotificationLine_node $data> ( ) ;
136
+ const [ notificationToDelete , setNotificationToDelete ] = useState < NotificationsLine_node $data> ( ) ;
65
137
66
138
setTitle ( t_i18n ( 'Notifications' ) ) ;
67
139
@@ -137,13 +209,13 @@ const Notifications: FunctionComponent = () => {
137
209
delete : red [ 500 ] ,
138
210
multiple : indigo [ 500 ] ,
139
211
} ;
140
- const getFirstOperation = ( { notification_content, notification_type } : Pick < NotificationLine_node $data, 'notification_content' | 'notification_type' > ) => {
212
+ const getFirstOperation = ( { notification_content, notification_type } : Pick < NotificationsLine_node $data, 'notification_content' | 'notification_type' > ) => {
141
213
const events = notification_content . map ( ( n ) => n . events ) . flat ( ) ;
142
214
const firstEvent = events . at ( 0 ) ;
143
215
const isDigest = notification_type === 'digest' ;
144
216
return isDigest ? 'multiple' : ( firstEvent ?. operation ?? 'none' ) ;
145
217
} ;
146
- const iconSelector = ( notification : NotificationLine_node $data) => {
218
+ const iconSelector = ( notification : NotificationsLine_node $data) => {
147
219
const operation = getFirstOperation ( notification ) ;
148
220
switch ( operation ) {
149
221
case 'create' :
@@ -166,7 +238,7 @@ const Notifications: FunctionComponent = () => {
166
238
label : 'Operation' ,
167
239
percentWidth : 10 ,
168
240
isSortable : isRuntimeSort ,
169
- render : ( { notification_content, notification_type } : NotificationLine_node $data) => {
241
+ render : ( { notification_content, notification_type } : NotificationsLine_node $data) => {
170
242
const firstOperation = getFirstOperation ( { notification_content, notification_type } ) ;
171
243
const events = notification_content . map ( ( n ) => n . events ) . flat ( ) ;
172
244
const eventTypes : Record < string , string > = {
@@ -200,7 +272,7 @@ const Notifications: FunctionComponent = () => {
200
272
label : 'Message' ,
201
273
percentWidth : 48 ,
202
274
isSortable : isRuntimeSort ,
203
- render : ( { notification_content } : NotificationLine_node $data) => {
275
+ render : ( { notification_content } : NotificationsLine_node $data) => {
204
276
const events = notification_content . map ( ( n ) => n . events ) . flat ( ) ;
205
277
const firstEvent = events . at ( 0 ) ;
206
278
@@ -276,7 +348,7 @@ const Notifications: FunctionComponent = () => {
276
348
setNumberOfElements : helpers . handleSetNumberOfElements ,
277
349
} as UsePreloadedPaginationFragment < NotificationsLinesPaginationQuery > ;
278
350
279
- const renderActions = ( data : NotificationLine_node $data) => {
351
+ const renderActions = ( data : NotificationsLine_node $data) => {
280
352
const [ updating , setUpdating ] = useState < boolean > ( false ) ;
281
353
282
354
const handleRead = ( id : string , read : boolean ) => {
@@ -345,11 +417,13 @@ const Notifications: FunctionComponent = () => {
345
417
{ iconSelector ( data ) }
346
418
</ Badge >
347
419
) }
348
- lineFragment = { notificationLineFragment }
420
+ taskScope = { 'USER' }
421
+ lineFragment = { notificationsLineFragment }
349
422
toolbarFilters = { contextFilters }
350
423
exportContext = { { entity_type : 'Notification' } }
351
424
availableEntityTypes = { [ 'Notification' ] }
352
425
actions = { renderActions }
426
+ markAsReadEnabled = { true }
353
427
/>
354
428
) }
355
429
{ notificationToDelete && (
0 commit comments