Skip to content

Commit 6d38c11

Browse files
committed
display notification info in JobDetail
1 parent 17079cf commit 6d38c11

File tree

5 files changed

+113
-45
lines changed

5 files changed

+113
-45
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import React from 'react';
2+
3+
import { Card, CardContent, Stack, FormLabel } from '@mui/material';
4+
import { useTranslator } from '../hooks';
5+
import { Scheduler } from '../handler';
6+
import { LabeledValue } from '../components/labeled-value';
7+
8+
interface INotificationItemProps {
9+
label: string;
10+
value: string | boolean;
11+
}
12+
13+
interface INotificationDetailsProps {
14+
notification: Scheduler.INotification;
15+
}
16+
17+
const NotificationItem: React.FC<INotificationItemProps> = ({
18+
label,
19+
value
20+
}) => {
21+
const displayValue =
22+
typeof value === 'boolean' ? (value ? 'Yes' : 'No') : value;
23+
24+
return (
25+
<LabeledValue
26+
label={label}
27+
value={displayValue}
28+
style={{ flex: '1 1 100%' }}
29+
/>
30+
);
31+
};
32+
33+
export const NotificationDetails: React.FC<INotificationDetailsProps> = ({
34+
notification
35+
}) => {
36+
const trans = useTranslator('jupyterlab');
37+
38+
return (
39+
<Card>
40+
<CardContent>
41+
<FormLabel component="legend" sx={{ mb: 2 }}>
42+
{trans.__('Notification')}
43+
</FormLabel>
44+
<Stack spacing={2}>
45+
<FormLabel component="legend">{trans.__('Send To')}</FormLabel>
46+
{notification.send_to.map((email, idx) => (
47+
<NotificationItem
48+
key={idx}
49+
label={trans.__(`Send To ${idx}`)}
50+
value={email}
51+
/>
52+
))}
53+
<FormLabel component="legend">{trans.__('Events')}</FormLabel>
54+
{notification.events.map((event, idx) => (
55+
<NotificationItem
56+
key={idx}
57+
label={trans.__(`Event ${idx}`)}
58+
value={event}
59+
/>
60+
))}
61+
<NotificationItem
62+
label={trans.__('Include Output')}
63+
value={notification.include_output}
64+
/>
65+
</Stack>
66+
</CardContent>
67+
</Card>
68+
);
69+
};

src/components/notification-picker.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, useEffect, useState } from 'react';
1+
import React, { useCallback, useState } from 'react';
22

33
import { Cluster } from './cluster';
44
import {
@@ -43,18 +43,6 @@ export function NotificationPicker({
4343
model.notification?.includeOutput || false
4444
);
4545

46-
useEffect(() => {
47-
if (model.notification?.enableNotification === undefined) {
48-
modelChange({
49-
...model,
50-
notification: {
51-
...model.notification,
52-
enableNotification: enableNotification
53-
}
54-
});
55-
}
56-
}, []);
57-
5846
const enableNotificationChange = (e: React.ChangeEvent<HTMLInputElement>) => {
5947
const updatedEnableNotification = e.target.checked;
6048
setEnableNotification(updatedEnableNotification);

src/mainviews/create-job.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,18 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
122122
envList[0].name
123123
)?.map(format => format.name);
124124

125-
props.handleModelChange({
125+
const newModel = {
126126
...props.model,
127127
environment: envList[0].name,
128128
computeType: newComputeType,
129129
outputFormats: outputFormats
130-
});
130+
};
131+
132+
if (envList[0].notifications_enabled && !props.model.notification) {
133+
newModel.notification = { enableNotification: true };
134+
}
135+
136+
props.handleModelChange(newModel);
131137
}
132138
};
133139

@@ -335,6 +341,10 @@ export function CreateJob(props: ICreateJobProps): JSX.Element {
335341
};
336342
}
337343

344+
console.log('\n\n***\nHELLO WORLD!!!');
345+
console.log(jobOptions);
346+
console.log(props.model);
347+
338348
props.handleModelChange({
339349
...props.model,
340350
createError: undefined,

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React, { useMemo, useState } from 'react';
22

3-
import { JupyterFrontEnd } from '@jupyterlab/application';
4-
53
import {
64
Alert,
75
Button,
@@ -10,27 +8,26 @@ import {
108
FormLabel,
119
Stack
1210
} from '@mui/material';
13-
14-
import cronstrue from 'cronstrue';
15-
1611
import { ButtonBar } from '../../components/button-bar';
1712
import { ConfirmDialogDeleteButton } from '../../components/confirm-dialog-buttons';
18-
import {
19-
ILabeledValueProps,
20-
LabeledValue
21-
} from '../../components/labeled-value';
22-
import { SchedulerService } from '../../handler';
23-
import { useEventLogger, useTranslator } from '../../hooks';
2413
import { ListJobsTable } from '../list-jobs';
14+
import cronstrue from 'cronstrue';
2515
import {
2616
IJobDefinitionModel,
2717
JobsView,
2818
ICreateJobModel,
2919
emptyCreateJobModel
3020
} from '../../model';
21+
import {
22+
ILabeledValueProps,
23+
LabeledValue
24+
} from '../../components/labeled-value';
25+
import { JupyterFrontEnd } from '@jupyterlab/application';
26+
import { NotificationDetails } from '../../components/notification-detail';
3127
import { Scheduler as SchedulerTokens } from '../../tokens';
32-
28+
import { SchedulerService } from '../../handler';
3329
import { timestampLocalize } from './job-detail';
30+
import { useEventLogger, useTranslator } from '../../hooks';
3431

3532
export interface IJobDefinitionProps {
3633
app: JupyterFrontEnd;
@@ -292,6 +289,9 @@ export function JobDefinition(props: IJobDefinitionProps): JSX.Element {
292289
{DefinitionButtonBar}
293290
{JobDefinition}
294291
{JobsList}
292+
{props.model.notification && (
293+
<NotificationDetails notification={props.model.notification} />
294+
)}
295295
{AdvancedOptions}
296296
</>
297297
);

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
import React, { useCallback, useState } from 'react';
22

3-
import { JupyterFrontEnd } from '@jupyterlab/application';
4-
5-
import { ButtonBar } from '../../components/button-bar';
6-
import {
7-
ConfirmDialogDeleteButton,
8-
ConfirmDialogStopButton
9-
} from '../../components/confirm-dialog-buttons';
10-
import { JobFileLink } from '../../components/job-file-link';
11-
import { Scheduler, SchedulerService } from '../../handler';
12-
import { useEventLogger, useTranslator } from '../../hooks';
13-
import { ICreateJobModel, IJobDetailModel, JobsView } from '../../model';
14-
import { Scheduler as SchedulerTokens } from '../../tokens';
15-
163
import {
174
Alert,
185
Button,
@@ -23,7 +10,23 @@ import {
2310
TextField,
2411
TextFieldProps
2512
} from '@mui/material';
13+
import { ButtonBar } from '../../components/button-bar';
2614
import { CommandIDs } from '../..';
15+
import {
16+
ConfirmDialogDeleteButton,
17+
ConfirmDialogStopButton
18+
} from '../../components/confirm-dialog-buttons';
19+
import { ICreateJobModel, IJobDetailModel, JobsView } from '../../model';
20+
import {
21+
ILabeledValueProps,
22+
LabeledValue
23+
} from '../../components/labeled-value';
24+
import { JobFileLink } from '../../components/job-file-link';
25+
import { JupyterFrontEnd } from '@jupyterlab/application';
26+
import { NotificationDetails } from '../../components/notification-detail';
27+
import { Scheduler, SchedulerService } from '../../handler';
28+
import { Scheduler as SchedulerTokens } from '../../tokens';
29+
import { useEventLogger, useTranslator } from '../../hooks';
2730

2831
export const TextFieldStyled = (props: TextFieldProps): JSX.Element => (
2932
<TextField
@@ -34,11 +37,6 @@ export const TextFieldStyled = (props: TextFieldProps): JSX.Element => (
3437
/>
3538
);
3639

37-
import {
38-
ILabeledValueProps,
39-
LabeledValue
40-
} from '../../components/labeled-value';
41-
4240
export interface IJobDetailProps {
4341
app: JupyterFrontEnd;
4442
model: IJobDetailModel | null;
@@ -354,6 +352,9 @@ export function JobDetail(props: IJobDetailProps): JSX.Element {
354352
{JobButtonBar}
355353
{CoreOptions}
356354
{Parameters}
355+
{props.model.notification && (
356+
<NotificationDetails notification={props.model.notification} />
357+
)}
357358
{AdvancedOptions}
358359
</>
359360
);

0 commit comments

Comments
 (0)