Skip to content

Commit

Permalink
admin-web: add delete DAG button
Browse files Browse the repository at this point in the history
  • Loading branch information
yohamta committed Sep 1, 2022
1 parent 6f09a25 commit 2536b9c
Showing 1 changed file with 52 additions and 30 deletions.
82 changes: 52 additions & 30 deletions admin/src/components/molecules/DAGEditButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
import { Button } from '@mui/material';
import React from 'react';
import { Button, Stack } from '@mui/material';

type Props = {
name: string;
};

function DAGEditButtons({ name }: Props) {
return (
<Button
onClick={async () => {
const val = window.prompt('Please input the new DAG name', '');
if (!val) {
return;
}
if (val.indexOf(' ') != -1) {
alert('DAG name cannot contain space');
return;
}
const formData = new FormData();
formData.append('action', 'rename');
formData.append('value', val);
const url = `${API_URL}/dags/${name}`;
const resp = await fetch(url, {
method: 'POST',
headers: { Accept: 'application/json' },
body: formData,
});
if (resp.ok) {
window.location.href = `/dags/${val}`;
} else {
const e = await resp.text();
alert(e);
}
}}
>
Rename
</Button>
<Stack direction="row" spacing={1}>
<Button
onClick={async () => {
const val = window.prompt('Please input the new DAG name', '');
if (!val) {
return;
}
if (val.indexOf(' ') != -1) {
alert('DAG name cannot contain space');
return;
}
const formData = new FormData();
formData.append('action', 'rename');
formData.append('value', val);
const url = `${API_URL}/dags/${name}`;
const resp = await fetch(url, {
method: 'POST',
headers: { Accept: 'application/json' },
body: formData,
});
if (resp.ok) {
window.location.href = `/dags/${val}`;
} else {
const e = await resp.text();
alert(e);
}
}}
>
Rename
</Button>
<Button
onClick={async () => {
if (!confirm('Are you sure to delete the DAG?')) {
return;
}
const url = `${API_URL}/dags/${name}`;
const resp = await fetch(url, {
method: 'DELETE',
headers: { Accept: 'application/json' },
});
if (resp.ok) {
window.location.href = '/dags/';
} else {
const e = await resp.text();
alert(e);
}
}}
>
Delete
</Button>
</Stack>
);
}

Expand Down

0 comments on commit 2536b9c

Please sign in to comment.