@@ -21,6 +21,9 @@ import {
21
21
import ClosedFolder from '../icons/ClosedFolder' ;
22
22
import OpenFolder from '../icons/OpenFolder' ;
23
23
import { ListenerUpdateRequest , Selector } from '../../shared/pb/api' ;
24
+ import ConfirmationDialog , {
25
+ ConfirmationDialogProps ,
26
+ } from './ConfirmationDialog' ;
24
27
25
28
type FolderProps = {
26
29
folderName : string ;
@@ -37,6 +40,8 @@ const TagFolderRow: React.FC<FolderProps> = ({
37
40
children,
38
41
} : PropsWithChildren < FolderProps > ) : JSX . Element => {
39
42
const [ open , setOpen ] = React . useState < boolean > ( false ) ;
43
+ const [ confirmation , setConfirmation ] =
44
+ React . useState < ConfirmationDialogProps | null > ( null ) ;
40
45
41
46
const toggleOpen = ( ) => {
42
47
setOpen ( ! open ) ;
@@ -76,74 +81,94 @@ const TagFolderRow: React.FC<FolderProps> = ({
76
81
} ;
77
82
78
83
return (
79
- < Grid container >
80
- < Grid container item xs = { 12 } alignItems = "center" >
81
- < Grid item xs = { 1 } >
82
- < IconButton
83
- key = { 'menuButton' + folderName }
84
- aria-label = { 'toggle listeners for ' + folderName }
85
- component = "span"
86
- onClick = { toggleOpen }
87
- >
88
- { open ? < OpenFolder /> : < ClosedFolder /> }
89
- </ IconButton >
90
- </ Grid >
91
- < Grid item xs = { 3 } >
92
- < Typography variant = "h6" > { folderName } </ Typography >
93
- </ Grid >
94
- < Grid item xs = { 5 } />
95
- < Grid container item xs = { 2 } justifyContent = "flex-end" >
96
- < Typography variant = "subtitle2" >
97
- { connectedListeners } of { totalListeners } listening
98
- </ Typography >
99
- </ Grid >
100
- < Grid container item xs = { 1 } justifyContent = "center" >
101
- < IconButton
102
- aria-controls = "folder-menu"
103
- aria-haspopup = "true"
104
- onClick = { toggleMenu }
105
- aria-label = { 'Menu for folder: ' + folderName }
106
- >
107
- < MoreVertical />
108
- </ IconButton >
109
- < Menu
110
- id = { 'folder-menu' + folderName }
111
- anchorEl = { menuAnchor }
112
- keepMounted
113
- open = { Boolean ( menuAnchor ) }
114
- onClose = { handleMenuClose }
115
- >
116
- < MenuItem
117
- key = { CONNECT_ALL }
118
- onClick = { ( ) => handleMenuClick ( CONNECT_ALL ) }
84
+ < >
85
+ { confirmation && (
86
+ < ConfirmationDialog
87
+ title = { confirmation . title }
88
+ text = { confirmation . text }
89
+ onConfirm = { confirmation . onConfirm }
90
+ onClose = { confirmation . onClose }
91
+ />
92
+ ) }
93
+ < Grid container >
94
+ < Grid container item xs = { 12 } alignItems = "center" >
95
+ < Grid item xs = { 1 } >
96
+ < IconButton
97
+ key = { 'menuButton' + folderName }
98
+ aria-label = { 'toggle listeners for ' + folderName }
99
+ component = "span"
100
+ onClick = { toggleOpen }
119
101
>
120
- Connect All
121
- </ MenuItem >
122
- < MenuItem
123
- key = { DISCONNECT_ALL }
124
- onClick = { ( ) => handleMenuClick ( DISCONNECT_ALL ) }
102
+ { open ? < OpenFolder /> : < ClosedFolder /> }
103
+ </ IconButton >
104
+ </ Grid >
105
+ < Grid item xs = { 3 } >
106
+ < Typography variant = "h6" > { folderName } </ Typography >
107
+ </ Grid >
108
+ < Grid item xs = { 5 } />
109
+ < Grid container item xs = { 2 } justifyContent = "flex-end" >
110
+ < Typography variant = "subtitle2" >
111
+ { connectedListeners } of { totalListeners } listening
112
+ </ Typography >
113
+ </ Grid >
114
+ < Grid container item xs = { 1 } justifyContent = "center" >
115
+ < IconButton
116
+ aria-controls = "folder-menu"
117
+ aria-haspopup = "true"
118
+ onClick = { toggleMenu }
119
+ aria-label = { 'Menu for folder: ' + folderName }
125
120
>
126
- Disconnect All
127
- </ MenuItem >
128
- < MenuItem key = { EXPORT } onClick = { ( ) => handleMenuClick ( EXPORT ) } >
129
- Export
130
- </ MenuItem >
131
- < MenuItem
132
- key = { DELETE_ALL }
133
- onClick = { ( ) => handleMenuClick ( DELETE_ALL ) }
121
+ < MoreVertical />
122
+ </ IconButton >
123
+ < Menu
124
+ id = { 'folder-menu' + folderName }
125
+ anchorEl = { menuAnchor }
126
+ keepMounted
127
+ open = { Boolean ( menuAnchor ) }
128
+ onClose = { handleMenuClose }
134
129
>
135
- Delete
136
- </ MenuItem >
137
- </ Menu >
130
+ < MenuItem
131
+ key = { CONNECT_ALL }
132
+ onClick = { ( ) => handleMenuClick ( CONNECT_ALL ) }
133
+ >
134
+ Connect All
135
+ </ MenuItem >
136
+ < MenuItem
137
+ key = { DISCONNECT_ALL }
138
+ onClick = { ( ) => handleMenuClick ( DISCONNECT_ALL ) }
139
+ >
140
+ Disconnect All
141
+ </ MenuItem >
142
+ < MenuItem key = { EXPORT } onClick = { ( ) => handleMenuClick ( EXPORT ) } >
143
+ Export
144
+ </ MenuItem >
145
+ < MenuItem
146
+ key = { DELETE_ALL }
147
+ onClick = { ( ) => {
148
+ setConfirmation ( {
149
+ title : 'Delete connections?' ,
150
+ text : `All connections with tag ${ folderName } will be deleted:` ,
151
+ onClose : ( ) => setConfirmation ( null ) ,
152
+ onConfirm : ( ) => {
153
+ setConfirmation ( null ) ;
154
+ handleMenuClick ( DELETE_ALL ) ;
155
+ } ,
156
+ } ) ;
157
+ } }
158
+ >
159
+ Delete
160
+ </ MenuItem >
161
+ </ Menu >
162
+ </ Grid >
138
163
</ Grid >
139
- </ Grid >
140
- < Grid container item xs = { 12 } >
141
- < Grid item xs = { 12 } >
142
- < Divider / >
164
+ < Grid container item xs = { 12 } >
165
+ < Grid item xs = { 12 } >
166
+ < Divider / >
167
+ </ Grid >
143
168
</ Grid >
169
+ { open && children }
144
170
</ Grid >
145
- { open && children }
146
- </ Grid >
171
+ </ >
147
172
) ;
148
173
} ;
149
174
0 commit comments