Skip to content

Commit 6162b5e

Browse files
committed
use notifications instead of alerts
1 parent aeae91d commit 6162b5e

File tree

2 files changed

+81
-47
lines changed

2 files changed

+81
-47
lines changed

src/renderer/components/Experiment/Tasks/EditTaskModal.tsx

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ModalClose, ModalDialog, Sheet, Stack, Typography } from '@mui/joy';
1212
import { FolderIcon } from 'lucide-react';
1313

1414
import * as chatAPI from 'renderer/lib/transformerlab-api-sdk';
15+
import { useNotification } from 'renderer/components/Shared/NotificationSystem';
1516

1617
type EditTaskModalProps = {
1718
open: boolean;
@@ -26,6 +27,7 @@ export default function EditTaskModal({
2627
task,
2728
onSaved = () => {},
2829
}: EditTaskModalProps) {
30+
const { addNotification } = useNotification();
2931
const [title, setTitle] = React.useState('');
3032
const [command, setCommand] = React.useState('');
3133
const [clusterName, setClusterName] = React.useState('');
@@ -66,7 +68,7 @@ export default function EditTaskModal({
6668
e.preventDefault();
6769
if (!task) return;
6870
if (!command) {
69-
alert('Command is required');
71+
addNotification({ type: 'warning', message: 'Command is required' });
7072
return;
7173
}
7274
setSaving(true);
@@ -103,7 +105,10 @@ export default function EditTaskModal({
103105

104106
if (!response.ok) {
105107
const txt = await response.text();
106-
alert(`Failed to save task: ${txt}`);
108+
addNotification({
109+
type: 'danger',
110+
message: `Failed to save task: ${txt}`,
111+
});
107112
setSaving(false);
108113
return;
109114
}
@@ -114,7 +119,7 @@ export default function EditTaskModal({
114119
onClose();
115120
} catch (err) {
116121
console.error(err);
117-
alert('Failed to save task.');
122+
addNotification({ type: 'danger', message: 'Failed to save task.' });
118123
} finally {
119124
setSaving(false);
120125
}
@@ -225,19 +230,26 @@ export default function EditTaskModal({
225230
</FormControl>
226231

227232
{/* Show uploaded directory indicator if present */}
228-
{task && (() => {
229-
const cfg = typeof task.config === 'string' ? safeParse(task.config) : task.config || {};
230-
return cfg.uploaded_dir_path ? (
231-
<Sheet variant="soft" sx={{ p: 2, borderRadius: 'md', mt: 2 }}>
232-
<Stack direction="row" spacing={1} alignItems="center">
233-
<FolderIcon size={16} />
234-
<Typography level="body-sm">
235-
This task includes an uploaded directory
236-
</Typography>
237-
</Stack>
238-
</Sheet>
239-
) : null;
240-
})()}
233+
{task &&
234+
(() => {
235+
const cfg =
236+
typeof task.config === 'string'
237+
? safeParse(task.config)
238+
: task.config || {};
239+
return cfg.uploaded_dir_path ? (
240+
<Sheet
241+
variant="soft"
242+
sx={{ p: 2, borderRadius: 'md', mt: 2 }}
243+
>
244+
<Stack direction="row" spacing={1} alignItems="center">
245+
<FolderIcon size={16} />
246+
<Typography level="body-sm">
247+
This task includes an uploaded directory
248+
</Typography>
249+
</Stack>
250+
</Sheet>
251+
) : null;
252+
})()}
241253
</DialogContent>
242254
<DialogActions>
243255
<Button

src/renderer/components/Experiment/Tasks/Tasks.tsx

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import JobsList from './JobsList';
1616
import NewTaskModal from './NewTaskModal';
1717
import EditTaskModal from './EditTaskModal';
1818
import ViewOutputModalStreaming from './ViewOutputModalStreaming';
19+
import { useNotification } from 'renderer/components/Shared/NotificationSystem';
1920

2021
const duration = require('dayjs/plugin/duration');
2122

@@ -34,6 +35,7 @@ export default function Tasks() {
3435
const [viewEvalImagesFromJob, setViewEvalImagesFromJob] = useState(-1);
3536
const [viewOutputFromSweepJob, setViewOutputFromSweepJob] = useState(false);
3637
const { experimentInfo } = useExperimentInfo();
38+
const { addNotification } = useNotification();
3739

3840
const handleOpen = () => setModalOpen(true);
3941
const handleClose = () => setModalOpen(false);
@@ -97,19 +99,24 @@ export default function Tasks() {
9799
);
98100

99101
if (response.ok) {
100-
// eslint-disable-next-line no-alert
101-
alert('Task deleted successfully!');
102+
addNotification({
103+
type: 'success',
104+
message: 'Task deleted successfully!',
105+
});
102106
// Refresh the data to remove the deleted task
103107
await tasksMutate();
104108
} else {
105-
// eslint-disable-next-line no-alert
106-
alert('Failed to delete task. Please try again.');
109+
addNotification({
110+
type: 'danger',
111+
message: 'Failed to delete task. Please try again.',
112+
});
107113
}
108114
} catch (error) {
109-
// eslint-disable-next-line no-console
110115
console.error('Error deleting task:', error);
111-
// eslint-disable-next-line no-alert
112-
alert('Failed to delete task. Please try again.');
116+
addNotification({
117+
type: 'danger',
118+
message: 'Failed to delete task. Please try again.',
119+
});
113120
}
114121
};
115122

@@ -130,26 +137,30 @@ export default function Tasks() {
130137
);
131138

132139
if (response.ok) {
133-
// eslint-disable-next-line no-alert
134-
alert('Job deleted successfully!');
140+
addNotification({
141+
type: 'success',
142+
message: 'Job deleted successfully!',
143+
});
135144
// Refresh the data to remove the deleted job
136145
await jobsMutate();
137146
} else {
138-
// eslint-disable-next-line no-alert
139-
alert('Failed to delete job. Please try again.');
147+
addNotification({
148+
type: 'danger',
149+
message: 'Failed to delete job. Please try again.',
150+
});
140151
}
141152
} catch (error) {
142-
// eslint-disable-next-line no-console
143153
console.error('Error deleting job:', error);
144-
// eslint-disable-next-line no-alert
145-
alert('Failed to delete job. Please try again.');
154+
addNotification({
155+
type: 'danger',
156+
message: 'Failed to delete job. Please try again.',
157+
});
146158
}
147159
};
148160

149161
const handleSubmit = async (data: any) => {
150162
if (!experimentInfo?.id) {
151-
// eslint-disable-next-line no-alert
152-
alert('No experiment selected');
163+
addNotification({ type: 'warning', message: 'No experiment selected' });
153164
return;
154165
}
155166

@@ -191,18 +202,23 @@ export default function Tasks() {
191202
if (response.ok) {
192203
setModalOpen(false);
193204
await tasksMutate();
194-
// eslint-disable-next-line no-alert
195-
alert('Task created. Use Queue to launch remotely.');
205+
addNotification({
206+
type: 'success',
207+
message: 'Task created. Use Queue to launch remotely.',
208+
});
196209
} else {
197210
const txt = await response.text();
198-
// eslint-disable-next-line no-alert
199-
alert(`Failed to create task: ${txt}`);
211+
addNotification({
212+
type: 'danger',
213+
message: `Failed to create task: ${txt}`,
214+
});
200215
}
201216
} catch (error) {
202-
// eslint-disable-next-line no-console
203217
console.error('Error creating task:', error);
204-
// eslint-disable-next-line no-alert
205-
alert('Failed to create task. Please try again.');
218+
addNotification({
219+
type: 'danger',
220+
message: 'Failed to create task. Please try again.',
221+
});
206222
} finally {
207223
setIsSubmitting(false);
208224
}
@@ -229,26 +245,32 @@ export default function Tasks() {
229245
formData.append('accelerators', String(cfg.accelerators));
230246
if (cfg.num_nodes) formData.append('num_nodes', String(cfg.num_nodes));
231247
if (cfg.setup) formData.append('setup', String(cfg.setup));
232-
if (cfg.uploaded_dir_path) formData.append('uploaded_dir_path', String(cfg.uploaded_dir_path));
248+
if (cfg.uploaded_dir_path)
249+
formData.append('uploaded_dir_path', String(cfg.uploaded_dir_path));
233250

234251
const resp = await chatAPI.authenticatedFetch(
235252
chatAPI.Endpoints.Jobs.LaunchRemote(experimentInfo.id),
236253
{ method: 'POST', body: formData },
237254
);
238255
const result = await resp.json();
239256
if (result.status === 'success') {
240-
// eslint-disable-next-line no-alert
241-
alert('Task queued for remote launch.');
257+
addNotification({
258+
type: 'success',
259+
message: 'Task queued for remote launch.',
260+
});
242261
await Promise.all([jobsMutate(), tasksMutate()]);
243262
} else {
244-
// eslint-disable-next-line no-alert
245-
alert(`Remote launch failed: ${result.message}`);
263+
addNotification({
264+
type: 'danger',
265+
message: `Remote launch failed: ${result.message}`,
266+
});
246267
}
247268
} catch (e) {
248-
// eslint-disable-next-line no-console
249269
console.error(e);
250-
// eslint-disable-next-line no-alert
251-
alert('Failed to queue remote task.');
270+
addNotification({
271+
type: 'danger',
272+
message: 'Failed to queue remote task.',
273+
});
252274
}
253275
};
254276

0 commit comments

Comments
 (0)