fleet/frontend/pages/ManageControlsPage/Scripts/components/DeleteScriptModal/DeleteScriptModal.tsx
jacobshandling ce9bb71832
UI – Add policy automation modal for running scripts (#22436)
## #22118 

- Add policy automation option to Run script
- Build corresponding modal and handlers
- Update types and service entities
- Misc. cleanup and optimizations
- update policies page dropdown text for 'No team' to read "Detect
device health issues for hosts that are not on a team." (#22444, not
included in GIF)
- Make empty states here and for install software automations modal[
link to their respective resolution
URLs](https://github.com/fleetdm/fleet/pull/22436#discussion_r1779077205)


![ezgif-6-5b9641a684](https://github.com/user-attachments/assets/2422b499-e675-4148-be0c-f0ad7126de8e)


- [x] Changes file added for user-visible changes in `changes/`, 
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
Co-authored-by: Ian Littman <iansltx@gmail.com>
2024-10-03 18:06:20 -07:00

78 lines
2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import React, { useContext } from "react";
import scriptAPI from "services/entities/scripts";
import { NotificationContext } from "context/notification";
import Modal from "components/Modal";
import Button from "components/buttons/Button";
import { AxiosResponse } from "axios";
import { IApiError } from "../../../../../interfaces/errors";
import { getErrorMessage } from "../ScriptUploader/helpers";
const baseClass = "delete-script-modal";
interface IDeleteScriptModalProps {
scriptName: string;
scriptId: number;
onCancel: () => void;
onDone: () => void;
}
const DeleteScriptModal = ({
scriptName,
scriptId,
onCancel,
onDone,
}: IDeleteScriptModalProps) => {
const { renderFlash } = useContext(NotificationContext);
const onClickDelete = async (id: number) => {
try {
await scriptAPI.deleteScript(id);
renderFlash("success", "Successfully deleted!");
} catch (e) {
const error = e as AxiosResponse<IApiError>;
const apiErrMessage = getErrorMessage(error);
renderFlash(
"error",
apiErrMessage.includes("Policy automation")
? apiErrMessage
: "Couldnt delete. Please try again."
);
}
onDone();
};
return (
<Modal
className={baseClass}
title="Delete script"
onExit={onCancel}
onEnter={() => onClickDelete(scriptId)}
>
<>
<p>
The script{" "}
<span className={`${baseClass}__script-name`}>{scriptName}</span> will
run on pending hosts. After the script runs, its output and exit code
will appear in the activity feed.
</p>
<div className="modal-cta-wrap">
<Button
type="button"
onClick={() => onClickDelete(scriptId)}
variant="alert"
className="delete-loading"
>
Delete
</Button>
<Button onClick={onCancel} variant="inverse-alert">
Cancel
</Button>
</div>
</>
</Modal>
);
};
export default DeleteScriptModal;