mirror of
https://github.com/fleetdm/fleet
synced 2026-05-06 14:58:33 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #32632 # Details This PR updates the Script Library page in the following ways: * When no scripts are uploaded for a team, it shows the "Add script" UI with a button that opens a new "Add Script" modal * When scripts are uploaded, the "Add script" button is instead added to the header of the scripts list, and clicking it opens that modal # Checklist for submitter If some of the following don't apply, delete the relevant line. - [X] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [ ] Added/updated automated tests working on this - [X] QA'd all new/changed functionality manually - [X] Test empty state: go to controls/scripts/library for a team with no scripts. Clicking "upload" button in empty state should open the add script modal. - [X] In the modal, select a .ps1 script. Should not see additional text. - [X] Close modal without uploading. Re-open. File field should be cleared & upload button visible again. - [X] Select a .sh script. Should see additional text about macOS and Linux. - [X] Add script. Make sure script saves and modal closes. - [X] Once script has been added, make sure empty state is gone and "Add script" button is at the top of the list. - [X] Go to /controls/os-settings/custom-settings for a team with no profiles uploaded. Make sure empty state text styles match the empty state for script uploads. - [X] Open modal to add profile. Make sure upload text styles match the script upload modal. - [X] Enable GitOps mode. Go to controls/scripts/library for a team with scripts added. Make sure new "Add script" button is disabled w/ standard tooltip in GitOps mode. Scripts empty state: <img width="697" height="352" alt="image" src="https://github.com/user-attachments/assets/32f0f246-bddb-4bb7-bc39-48d9978de9fa" /> Scripts uploader: <img width="745" height="590" alt="image" src="https://github.com/user-attachments/assets/f82414e2-9318-4543-b5ca-41e759662587" /> Scripts uploader with .sh <img width="750" height="539" alt="image" src="https://github.com/user-attachments/assets/0b989067-921a-4d18-93ed-09aac90fc9cb" /> Scripts table: <img width="686" height="256" alt="image" src="https://github.com/user-attachments/assets/848f1b56-6e9e-48d4-9a03-6fdf5427301e" /> Profiles empty state: <img width="700" height="377" alt="image" src="https://github.com/user-attachments/assets/8f92bcd9-2215-41f6-a540-4774f7e9542b" /> Profiles uploader: <img width="707" height="682" alt="image" src="https://github.com/user-attachments/assets/eef216af-3447-48e7-882a-e42e888e1c17" />
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
import React, { useContext, useState } 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 "../ScriptUploadModal/helpers";
|
||
|
||
const baseClass = "delete-script-modal";
|
||
|
||
interface IDeleteScriptModalProps {
|
||
scriptName: string;
|
||
scriptId: number;
|
||
onCancel: () => void;
|
||
afterDelete: () => void;
|
||
isHidden?: boolean;
|
||
}
|
||
|
||
const DeleteScriptModal = ({
|
||
scriptName,
|
||
scriptId,
|
||
onCancel,
|
||
afterDelete,
|
||
isHidden = false,
|
||
}: IDeleteScriptModalProps) => {
|
||
const { renderFlash } = useContext(NotificationContext);
|
||
const [isDeleting, setIsDeleting] = useState(false);
|
||
|
||
const onClickDelete = async (id: number) => {
|
||
setIsDeleting(true);
|
||
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
|
||
: "Couldn’t delete. Please try again."
|
||
);
|
||
}
|
||
setIsDeleting(false);
|
||
afterDelete();
|
||
};
|
||
|
||
return (
|
||
<Modal
|
||
className={baseClass}
|
||
title="Delete script"
|
||
onExit={onCancel}
|
||
onEnter={() => onClickDelete(scriptId)}
|
||
isHidden={isHidden}
|
||
isContentDisabled={isDeleting}
|
||
>
|
||
<>
|
||
<p>
|
||
This action will cancel any pending script execution for{" "}
|
||
<span className={`${baseClass}__script-name`}>{scriptName}</span>
|
||
</p>
|
||
<p>
|
||
If the script is currently running on a host it will still complete,
|
||
but results won't appear in Fleet.
|
||
</p>
|
||
<p>You cannot undo this action.</p>
|
||
<div className="modal-cta-wrap">
|
||
<Button
|
||
type="button"
|
||
onClick={() => onClickDelete(scriptId)}
|
||
variant="alert"
|
||
className="delete-loading"
|
||
isLoading={isDeleting}
|
||
>
|
||
Delete
|
||
</Button>
|
||
<Button onClick={onCancel} variant="inverse-alert">
|
||
Cancel
|
||
</Button>
|
||
</div>
|
||
</>
|
||
</Modal>
|
||
);
|
||
};
|
||
|
||
export default DeleteScriptModal;
|