2023-10-10 22:00:45 +00:00
|
|
|
|
import React, { useContext } from "react";
|
|
|
|
|
|
|
|
|
|
|
|
import scriptAPI from "services/entities/scripts";
|
|
|
|
|
|
import { NotificationContext } from "context/notification";
|
2023-03-06 15:03:48 +00:00
|
|
|
|
|
|
|
|
|
|
import Modal from "components/Modal";
|
|
|
|
|
|
import Button from "components/buttons/Button";
|
|
|
|
|
|
|
|
|
|
|
|
const baseClass = "delete-script-modal";
|
|
|
|
|
|
|
|
|
|
|
|
interface IDeleteScriptModalProps {
|
|
|
|
|
|
scriptName: string;
|
|
|
|
|
|
scriptId: number;
|
|
|
|
|
|
onCancel: () => void;
|
2023-10-10 22:00:45 +00:00
|
|
|
|
onDone: () => void;
|
2023-03-06 15:03:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const DeleteScriptModal = ({
|
|
|
|
|
|
scriptName,
|
|
|
|
|
|
scriptId,
|
|
|
|
|
|
onCancel,
|
2023-10-10 22:00:45 +00:00
|
|
|
|
onDone,
|
2023-03-06 15:03:48 +00:00
|
|
|
|
}: IDeleteScriptModalProps) => {
|
2023-10-10 22:00:45 +00:00
|
|
|
|
const { renderFlash } = useContext(NotificationContext);
|
|
|
|
|
|
|
|
|
|
|
|
const onClickDelete = async (id: number) => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
await scriptAPI.deleteScript(id);
|
|
|
|
|
|
renderFlash("success", "Successfully deleted!");
|
|
|
|
|
|
} catch {
|
|
|
|
|
|
renderFlash("error", "Couldn’t delete. Please try again.");
|
|
|
|
|
|
}
|
|
|
|
|
|
onDone();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2023-03-06 15:03:48 +00:00
|
|
|
|
return (
|
|
|
|
|
|
<Modal
|
|
|
|
|
|
className={baseClass}
|
2024-02-23 14:57:18 +00:00
|
|
|
|
title="Delete script"
|
2023-03-06 15:03:48 +00:00
|
|
|
|
onExit={onCancel}
|
2023-10-10 22:00:45 +00:00
|
|
|
|
onEnter={() => onClickDelete(scriptId)}
|
2023-03-06 15:03:48 +00:00
|
|
|
|
>
|
|
|
|
|
|
<>
|
|
|
|
|
|
<p>
|
2024-09-10 21:04:10 +00:00
|
|
|
|
The script{" "}
|
|
|
|
|
|
<span className={`${baseClass}__script-name`}>{scriptName}</span> will
|
2024-09-27 22:42:47 +00:00
|
|
|
|
run on pending hosts. After the script runs, its output and
|
2024-09-10 21:04:10 +00:00
|
|
|
|
exit code will appear in the activity feed.
|
2023-03-06 15:03:48 +00:00
|
|
|
|
</p>
|
|
|
|
|
|
<div className="modal-cta-wrap">
|
|
|
|
|
|
<Button
|
|
|
|
|
|
type="button"
|
2023-10-10 22:00:45 +00:00
|
|
|
|
onClick={() => onClickDelete(scriptId)}
|
2023-03-06 15:03:48 +00:00
|
|
|
|
variant="alert"
|
|
|
|
|
|
className="delete-loading"
|
|
|
|
|
|
>
|
|
|
|
|
|
Delete
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
<Button onClick={onCancel} variant="inverse-alert">
|
|
|
|
|
|
Cancel
|
|
|
|
|
|
</Button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
</Modal>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default DeleteScriptModal;
|