Skip to content

Commit 747e4b1

Browse files
committed
rename "Notification" into "NotificationSettings"
1 parent 07113c5 commit 747e4b1

File tree

9 files changed

+81
-70
lines changed

9 files changed

+81
-70
lines changed

jupyter_scheduler/models.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class NotificationEvent(str, Enum):
2727
STOPPED = "Stopped"
2828

2929

30-
class Notification(BaseModel):
31-
"""Represents a notification.
30+
class NotificationsSettings(BaseModel):
31+
"""Represents settings for sending notifications.
3232
3333
Attributes:
3434
send_to (List[str]): A list of symbols (e.g., email addresses) to which notifications should be sent.
@@ -117,7 +117,7 @@ class CreateJob(BaseModel):
117117
name: str
118118
output_filename_template: Optional[str] = OUTPUT_FILENAME_TEMPLATE
119119
compute_type: Optional[str] = None
120-
notification: Optional[Notification] = None
120+
notifications_settings: Optional[NotificationsSettings] = None
121121

122122
@root_validator
123123
def compute_input_filename(cls, values) -> Dict:
@@ -178,7 +178,7 @@ class DescribeJob(BaseModel):
178178
status: Status = Status.CREATED
179179
status_message: Optional[str] = None
180180
downloaded: bool = False
181-
notification: Optional[Notification] = None
181+
notifications_settings: Optional[NotificationsSettings] = None
182182

183183
class Config:
184184
orm_mode = True
@@ -243,7 +243,7 @@ class CreateJobDefinition(BaseModel):
243243
compute_type: Optional[str] = None
244244
schedule: Optional[str] = None
245245
timezone: Optional[str] = None
246-
notification: Optional[Notification] = None
246+
notifications_settings: Optional[NotificationsSettings] = None
247247

248248
@root_validator
249249
def compute_input_filename(cls, values) -> Dict:
@@ -269,7 +269,7 @@ class DescribeJobDefinition(BaseModel):
269269
create_time: int
270270
update_time: int
271271
active: bool
272-
notification: Optional[Notification] = None
272+
notifications_settings: Optional[NotificationsSettings] = None
273273

274274
class Config:
275275
orm_mode = True
@@ -289,7 +289,7 @@ class UpdateJobDefinition(BaseModel):
289289
active: Optional[bool] = None
290290
compute_type: Optional[str] = None
291291
input_uri: Optional[str] = None
292-
notification: Optional[Notification] = None
292+
notifications_settings: Optional[NotificationsSettings] = None
293293

294294

295295
class ListJobDefinitionsQuery(BaseModel):

jupyter_scheduler/orm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class Job(CommonColumns, Base):
9898
url = Column(String(256), default=generate_jobs_url)
9999
pid = Column(Integer)
100100
idempotency_token = Column(String(256))
101-
notification = Column(JsonType(1024), nullable=True)
101+
notifications_settings = Column(JsonType(1024), nullable=True)
102102

103103

104104
class JobDefinition(CommonColumns, Base):
@@ -109,7 +109,7 @@ class JobDefinition(CommonColumns, Base):
109109
url = Column(String(256), default=generate_job_definitions_url)
110110
create_time = Column(Integer, default=get_utc_timestamp)
111111
active = Column(Boolean, default=True)
112-
notification = Column(JsonType(1024), nullable=True)
112+
notifications_settings = Column(JsonType(1024), nullable=True)
113113

114114

115115
def create_tables(db_url, drop_tables=False):

src/components/notification-detail.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import { useTranslator } from '../hooks';
55
import { Scheduler } from '../handler';
66
import { LabeledValue } from '../components/labeled-value';
77

8-
interface INotificationItemProps {
8+
interface INotificationsSettingsItemProps {
99
label: string;
1010
value: string | boolean;
1111
}
1212

13-
interface INotificationDetailsProps {
13+
interface INotificationsSettingsDetailsProps {
1414
notification: Scheduler.INotification;
1515
}
1616

17-
const NotificationItem: React.FC<INotificationItemProps> = ({
17+
const NotificationsSettingsItem: React.FC<INotificationsSettingsItemProps> = ({
1818
label,
1919
value
2020
}) => {
@@ -30,35 +30,37 @@ const NotificationItem: React.FC<INotificationItemProps> = ({
3030
);
3131
};
3232

33-
export const NotificationDetails: React.FC<INotificationDetailsProps> = ({
34-
notification
35-
}) => {
33+
export const NotificationsSettingsDetails: React.FC<
34+
INotificationsSettingsDetailsProps
35+
> = ({ notification }) => {
3636
const trans = useTranslator('jupyterlab');
3737

3838
return (
3939
<Card>
4040
<CardContent>
4141
<FormLabel component="legend" sx={{ mb: 2 }}>
42-
{trans.__('Notification')}
42+
{trans.__('Notifications Settings')}
4343
</FormLabel>
4444
<Stack spacing={2}>
4545
<FormLabel component="legend">{trans.__('Send To')}</FormLabel>
4646
{notification.send_to.map((email, idx) => (
47-
<NotificationItem
47+
<NotificationsSettingsItem
4848
key={idx}
4949
label={trans.__(`Send To ${idx + 1}`)}
5050
value={email}
5151
/>
5252
))}
53-
<FormLabel component="legend">{trans.__('Events')}</FormLabel>
53+
<FormLabel component="legend">
54+
{trans.__('Notification Events')}
55+
</FormLabel>
5456
{notification.events.map((event, idx) => (
55-
<NotificationItem
57+
<NotificationsSettingsItem
5658
key={idx}
5759
label={trans.__(`Event ${idx + 1}`)}
5860
value={event}
5961
/>
6062
))}
61-
<NotificationItem
63+
<NotificationsSettingsItem
6264
label={trans.__('Include Output')}
6365
value={notification.include_output}
6466
/>

src/components/notification-picker.tsx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,40 @@ import Select, { SelectChangeEvent } from '@mui/material/Select';
1616
import { Stack } from './stack';
1717
import { useTranslator } from '../hooks';
1818

19-
interface INotificationPickerProps {
19+
interface INotificationsSettingsProps {
2020
notificationEvents: string[];
2121
id: string;
2222
model: ICreateJobModel;
2323
handleModelChange: (model: ICreateJobModel) => void;
2424
}
2525

26-
export function NotificationPicker({
26+
export function NotificationsSettings({
2727
notificationEvents,
2828
id,
2929
model,
3030
handleModelChange: modelChange
31-
}: INotificationPickerProps): JSX.Element | null {
31+
}: INotificationsSettingsProps): JSX.Element | null {
3232
const trans = useTranslator('jupyterlab');
3333
const [selectedEvents, setSelectedEvents] = useState<string[]>(
34-
model.notification?.selectedEvents || []
34+
model.notificationsSettings?.selectedEvents || []
3535
);
3636
const [enableNotification, setEnableNotification] = useState<boolean>(
37-
model.notification?.enableNotification ?? true
37+
model.notificationsSettings?.enableNotification ?? true
3838
);
3939
const [sendToInput, setSendToInput] = useState<string>(
40-
model.notification?.sendTo?.join(', ') || ''
40+
model.notificationsSettings?.sendTo?.join(', ') || ''
4141
);
4242
const [includeOutput, setIncludeOutput] = useState<boolean>(
43-
model.notification?.includeOutput || false
43+
model.notificationsSettings?.includeOutput || false
4444
);
4545

4646
const enableNotificationChange = (e: React.ChangeEvent<HTMLInputElement>) => {
4747
const updatedEnableNotification = e.target.checked;
4848
setEnableNotification(updatedEnableNotification);
4949
modelChange({
5050
...model,
51-
notification: {
52-
...model.notification,
51+
notificationsSettings: {
52+
...model.notificationsSettings,
5353
enableNotification: updatedEnableNotification
5454
}
5555
});
@@ -63,8 +63,8 @@ export function NotificationPicker({
6363
setSelectedEvents(updatedEvents);
6464
modelChange({
6565
...model,
66-
notification: {
67-
...model.notification,
66+
notificationsSettings: {
67+
...model.notificationsSettings,
6868
selectedEvents: updatedEvents
6969
}
7070
});
@@ -82,8 +82,11 @@ export function NotificationPicker({
8282
.split(',')
8383
.map(email => email.trim())
8484
.filter(email => email);
85-
const updatedNotification = { ...model.notification, sendTo: emailArray };
86-
modelChange({ ...model, notification: updatedNotification });
85+
const updatedNotification = {
86+
...model.notificationsSettings,
87+
sendTo: emailArray
88+
};
89+
modelChange({ ...model, notificationsSettings: updatedNotification });
8790
}, [sendToInput, model, modelChange]);
8891

8992
const keyDown = useCallback(
@@ -101,8 +104,8 @@ export function NotificationPicker({
101104
setIncludeOutput(updatedValue);
102105
modelChange({
103106
...model,
104-
notification: {
105-
...model.notification,
107+
notificationsSettings: {
108+
...model.notificationsSettings,
106109
includeOutput: updatedValue
107110
}
108111
});
@@ -116,7 +119,10 @@ export function NotificationPicker({
116119
setSelectedEvents(updatedEvents);
117120
modelChange({
118121
...model,
119-
notifications: { ...model.notification, selectedEvents: updatedEvents }
122+
notifications: {
123+
...model.notificationsSettings,
124+
selectedEvents: updatedEvents
125+
}
120126
});
121127
},
122128
[selectedEvents, model, modelChange]
@@ -128,15 +134,15 @@ export function NotificationPicker({
128134

129135
return (
130136
<Stack size={2}>
131-
<InputLabel>{trans.__('Notification')}</InputLabel>
137+
<InputLabel>{trans.__('Notifications Settings')}</InputLabel>
132138
<FormControlLabel
133139
control={
134140
<Switch
135141
checked={enableNotification}
136142
onChange={enableNotificationChange}
137143
/>
138144
}
139-
label={trans.__('Enable Notification')}
145+
label={trans.__('Enable Notifications')}
140146
/>
141147
<TextField
142148
label={trans.__('Send To')}

src/handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export namespace Scheduler {
363363
compute_type?: string;
364364
schedule?: string;
365365
timezone?: string;
366-
notification?: INotification;
366+
notifications_settings?: INotification;
367367
}
368368

369369
export interface IUpdateJobDefinition {
@@ -372,7 +372,7 @@ export namespace Scheduler {
372372
timezone?: string;
373373
active?: boolean;
374374
input_uri?: string;
375-
notification?: INotification;
375+
notifications_settings?: INotification;
376376
}
377377

378378
export interface IDescribeJobDefinition {
@@ -391,7 +391,7 @@ export namespace Scheduler {
391391
create_time: number;
392392
update_time: number;
393393
active: boolean;
394-
notification?: INotification;
394+
notifications_settings?: INotification;
395395
}
396396

397397
export interface IEmailNotifications {
@@ -424,7 +424,7 @@ export namespace Scheduler {
424424
output_filename_template?: string;
425425
output_formats?: string[];
426426
compute_type?: string;
427-
notification?: INotification;
427+
notifications_settings?: INotification;
428428
}
429429

430430
export interface ICreateJobFromDefinition {
@@ -473,7 +473,7 @@ export namespace Scheduler {
473473
start_time?: number;
474474
end_time?: number;
475475
downloaded: boolean;
476-
notification?: INotification;
476+
notifications_settings?: INotification;
477477
}
478478

479479
export interface ICreateJobResponse {

src/mainviews/create-job.tsx

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Cluster } from '../components/cluster';
1111
import { ComputeTypePicker } from '../components/compute-type-picker';
1212
import { CreateScheduleOptions } from '../components/create-schedule-options';
1313
import { EnvironmentPicker } from '../components/environment-picker';
14-
import { NotificationPicker } from '../components/notification-picker';
14+
import { NotificationsSettings } from '../components/notification-picker';
1515
import {
1616
OutputFormatPicker,
1717
outputFormatsForEnvironment
@@ -129,8 +129,11 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
129129
outputFormats: outputFormats
130130
};
131131

132-
if (envList[0].notifications_enabled && !props.model.notification) {
133-
newModel.notification = { enableNotification: true };
132+
if (
133+
envList[0].notifications_enabled &&
134+
!props.model.notificationsSettings
135+
) {
136+
newModel.notificationsSettings = { enableNotification: true };
134137
}
135138

136139
props.handleModelChange(newModel);
@@ -333,11 +336,11 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
333336
jobOptions.parameters = serializeParameters(props.model.parameters);
334337
}
335338

336-
if (props.model.notification?.enableNotification) {
337-
jobOptions.notification = {
338-
send_to: props.model.notification.sendTo ?? [],
339-
events: props.model.notification.selectedEvents ?? [],
340-
include_output: props.model.notification.includeOutput ?? false
339+
if (props.model.notificationsSettings?.enableNotification) {
340+
jobOptions.notifications_settings = {
341+
send_to: props.model.notificationsSettings.sendTo ?? [],
342+
events: props.model.notificationsSettings.selectedEvents ?? [],
343+
include_output: props.model.notificationsSettings.includeOutput ?? false
341344
};
342345
}
343346

@@ -388,11 +391,11 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
388391
);
389392
}
390393

391-
if (props.model.notification?.enableNotification) {
392-
jobDefinitionOptions.notification = {
393-
send_to: props.model.notification.sendTo ?? [],
394-
events: props.model.notification.selectedEvents ?? [],
395-
include_output: props.model.notification.includeOutput ?? false
394+
if (props.model.notificationsSettings?.enableNotification) {
395+
jobDefinitionOptions.notifications_settings = {
396+
send_to: props.model.notificationsSettings.sendTo ?? [],
397+
events: props.model.notificationsSettings.selectedEvents ?? [],
398+
include_output: props.model.notificationsSettings.includeOutput ?? false
396399
};
397400
}
398401

@@ -539,7 +542,7 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
539542
value={props.model.computeType}
540543
/>
541544
{envsByName[props.model.environment]?.notifications_enabled && (
542-
<NotificationPicker
545+
<NotificationsSettings
543546
notificationEvents={
544547
envsByName[props.model.environment].notification_events
545548
}

src/mainviews/detail-view/job-definition.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '@mui/material';
1111
import { ButtonBar } from '../../components/button-bar';
1212
import { ConfirmDialogDeleteButton } from '../../components/confirm-dialog-buttons';
13-
import { ListJobsTable } from '../list-jobs';
1413
import cronstrue from 'cronstrue';
1514
import {
1615
IJobDefinitionModel,
@@ -23,7 +22,8 @@ import {
2322
LabeledValue
2423
} from '../../components/labeled-value';
2524
import { JupyterFrontEnd } from '@jupyterlab/application';
26-
import { NotificationDetails } from '../../components/notification-detail';
25+
import { ListJobsTable } from '../list-jobs';
26+
import { NotificationsSettingsDetails } from '../../components/notification-detail';
2727
import { Scheduler as SchedulerTokens } from '../../tokens';
2828
import { SchedulerService } from '../../handler';
2929
import { timestampLocalize } from './job-detail';
@@ -289,8 +289,8 @@ export function JobDefinition(props: IJobDefinitionProps): JSX.Element {
289289
{DefinitionButtonBar}
290290
{JobDefinition}
291291
{JobsList}
292-
{props.model.notification && (
293-
<NotificationDetails notification={props.model.notification} />
292+
{props.model.notificationsSettings && (
293+
<NotificationsSettingsDetails notification={props.model.notificationsSettings} />
294294
)}
295295
{AdvancedOptions}
296296
</>

0 commit comments

Comments
 (0)