Skip to content

Commit d569217

Browse files
committed
add enable notifications toggle
1 parent 9cb0965 commit d569217

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

src/components/notification-picker.tsx

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ import React, { useState, useCallback } from 'react';
22

33
import { Cluster } from './cluster';
44
import {
5+
Chip,
56
FormControl,
7+
FormControlLabel,
68
InputLabel,
79
MenuItem,
8-
TextField,
9-
Chip
10+
Switch,
11+
TextField
1012
} from '@mui/material';
1113
import { ICreateJobModel } from '../model';
1214
import Select, { SelectChangeEvent } from '@mui/material/Select';
@@ -30,6 +32,21 @@ export function NotificationPicker({
3032
const [selectedEvents, setSelectedEvents] = useState<string[]>(
3133
model.notification?.selectedEvents || []
3234
);
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+
};
3350

3451
const selectChange = useCallback(
3552
(e: SelectChangeEvent<string>) => {
@@ -79,23 +96,36 @@ export function NotificationPicker({
7996
return (
8097
<Stack size={2}>
8198
<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+
82109
<TextField
83110
label={trans.__('Send To')}
84111
value={model.notification?.sendTo || ''}
85112
name="sendTo"
86113
variant="outlined"
87114
onChange={sendToChange}
115+
disabled={!enableNotification}
88116
/>
89117
<NotificationEventsSelect
90118
id={id}
91119
availableEvents={notificationEvents.filter(
92120
e => !selectedEvents.includes(e)
93121
)}
94122
selectChange={selectChange}
123+
disabled={!enableNotification}
95124
/>
96125
<SelectedEventsChips
97126
selectedEvents={selectedEvents}
98127
deleteSelectedEvent={deleteSelectedEvent}
128+
disabled={!enableNotification}
99129
/>
100130
</Stack>
101131
);
@@ -105,19 +135,23 @@ const NotificationEventsSelect: React.FC<{
105135
id: string;
106136
availableEvents: string[];
107137
selectChange: (e: SelectChangeEvent<string>) => void;
108-
}> = ({ id, availableEvents, selectChange: handleSelectChange }) => {
138+
disabled: boolean;
139+
}> = ({ id, availableEvents, selectChange, disabled }) => {
109140
const trans = useTranslator('jupyterlab');
110141
const label = trans.__('Notification Events');
111142
const labelId = `${id}-label`;
112143

113144
return (
114145
<FormControl>
115-
<InputLabel id={labelId}>{label}</InputLabel>
146+
<InputLabel id={labelId} disabled={disabled}>
147+
{label}
148+
</InputLabel>
116149
<Select
117150
labelId={labelId}
118151
id={id}
119152
label={label}
120-
onChange={handleSelectChange}
153+
onChange={selectChange}
154+
disabled={disabled}
121155
>
122156
{availableEvents.map(e => (
123157
<MenuItem key={e} value={e}>
@@ -132,14 +166,16 @@ const NotificationEventsSelect: React.FC<{
132166
const SelectedEventsChips: React.FC<{
133167
selectedEvents: string[];
134168
deleteSelectedEvent: (eventToDelete: string) => () => void;
135-
}> = ({ selectedEvents, deleteSelectedEvent }) => (
169+
disabled: boolean;
170+
}> = ({ selectedEvents, deleteSelectedEvent, disabled }) => (
136171
<Cluster gap={3} justifyContent="flex-start">
137172
{selectedEvents.map(e => (
138173
<Chip
139174
key={e}
140175
label={e}
141176
variant="outlined"
142177
onDelete={deleteSelectedEvent(e)}
178+
disabled={disabled}
143179
/>
144180
))}
145181
</Cluster>

0 commit comments

Comments
 (0)