@@ -2,11 +2,13 @@ import React, { useState, useCallback } from 'react';
2
2
3
3
import { Cluster } from './cluster' ;
4
4
import {
5
+ Chip ,
5
6
FormControl ,
7
+ FormControlLabel ,
6
8
InputLabel ,
7
9
MenuItem ,
8
- TextField ,
9
- Chip
10
+ Switch ,
11
+ TextField
10
12
} from '@mui/material' ;
11
13
import { ICreateJobModel } from '../model' ;
12
14
import Select , { SelectChangeEvent } from '@mui/material/Select' ;
@@ -30,6 +32,21 @@ export function NotificationPicker({
30
32
const [ selectedEvents , setSelectedEvents ] = useState < string [ ] > (
31
33
model . notification ?. selectedEvents || [ ]
32
34
) ;
35
+ const [ enableNotification , setEnableNotification ] = useState < boolean > (
36
+ model . notification ?. enableNotification ?? true
37
+ ) ;
38
+
39
+ const enableNotificationChange = ( e : React . ChangeEvent < HTMLInputElement > ) => {
40
+ const updatedEnableNotification = e . target . checked ;
41
+ setEnableNotification ( updatedEnableNotification ) ;
42
+ modelChange ( {
43
+ ...model ,
44
+ notification : {
45
+ ...model . notification ,
46
+ enableNotification : updatedEnableNotification
47
+ }
48
+ } ) ;
49
+ } ;
33
50
34
51
const selectChange = useCallback (
35
52
( e : SelectChangeEvent < string > ) => {
@@ -79,23 +96,36 @@ export function NotificationPicker({
79
96
return (
80
97
< Stack size = { 2 } >
81
98
< InputLabel > { trans . __ ( 'Notifications' ) } </ InputLabel >
99
+ < FormControlLabel
100
+ control = {
101
+ < Switch
102
+ checked = { enableNotification }
103
+ onChange = { enableNotificationChange }
104
+ />
105
+ }
106
+ label = { trans . __ ( 'Enable Notifications' ) }
107
+ />
108
+
82
109
< TextField
83
110
label = { trans . __ ( 'Send To' ) }
84
111
value = { model . notification ?. sendTo || '' }
85
112
name = "sendTo"
86
113
variant = "outlined"
87
114
onChange = { sendToChange }
115
+ disabled = { ! enableNotification }
88
116
/>
89
117
< NotificationEventsSelect
90
118
id = { id }
91
119
availableEvents = { notificationEvents . filter (
92
120
e => ! selectedEvents . includes ( e )
93
121
) }
94
122
selectChange = { selectChange }
123
+ disabled = { ! enableNotification }
95
124
/>
96
125
< SelectedEventsChips
97
126
selectedEvents = { selectedEvents }
98
127
deleteSelectedEvent = { deleteSelectedEvent }
128
+ disabled = { ! enableNotification }
99
129
/>
100
130
</ Stack >
101
131
) ;
@@ -105,19 +135,23 @@ const NotificationEventsSelect: React.FC<{
105
135
id : string ;
106
136
availableEvents : string [ ] ;
107
137
selectChange : ( e : SelectChangeEvent < string > ) => void ;
108
- } > = ( { id, availableEvents, selectChange : handleSelectChange } ) => {
138
+ disabled : boolean ;
139
+ } > = ( { id, availableEvents, selectChange, disabled } ) => {
109
140
const trans = useTranslator ( 'jupyterlab' ) ;
110
141
const label = trans . __ ( 'Notification Events' ) ;
111
142
const labelId = `${ id } -label` ;
112
143
113
144
return (
114
145
< FormControl >
115
- < InputLabel id = { labelId } > { label } </ InputLabel >
146
+ < InputLabel id = { labelId } disabled = { disabled } >
147
+ { label }
148
+ </ InputLabel >
116
149
< Select
117
150
labelId = { labelId }
118
151
id = { id }
119
152
label = { label }
120
- onChange = { handleSelectChange }
153
+ onChange = { selectChange }
154
+ disabled = { disabled }
121
155
>
122
156
{ availableEvents . map ( e => (
123
157
< MenuItem key = { e } value = { e } >
@@ -132,14 +166,16 @@ const NotificationEventsSelect: React.FC<{
132
166
const SelectedEventsChips : React . FC < {
133
167
selectedEvents : string [ ] ;
134
168
deleteSelectedEvent : ( eventToDelete : string ) => ( ) => void ;
135
- } > = ( { selectedEvents, deleteSelectedEvent } ) => (
169
+ disabled : boolean ;
170
+ } > = ( { selectedEvents, deleteSelectedEvent, disabled } ) => (
136
171
< Cluster gap = { 3 } justifyContent = "flex-start" >
137
172
{ selectedEvents . map ( e => (
138
173
< Chip
139
174
key = { e }
140
175
label = { e }
141
176
variant = "outlined"
142
177
onDelete = { deleteSelectedEvent ( e ) }
178
+ disabled = { disabled }
143
179
/>
144
180
) ) }
145
181
</ Cluster >
0 commit comments