fleet/frontend/pages/hosts/components/ScriptDetailsModal/ScriptDetailsModal.tsx

299 lines
9.1 KiB
TypeScript
Raw Normal View History

import React, {
useCallback,
useContext,
useRef,
useState,
useEffect,
} from "react";
import { format } from "date-fns";
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
import { useQuery } from "react-query";
import FileSaver from "file-saver";
import { AppContext } from "context/app";
import { NotificationContext } from "context/notification";
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
import scriptAPI from "services/entities/scripts";
import { IHostScript } from "interfaces/script";
import Modal from "components/Modal";
import ModalFooter from "components/ModalFooter";
import Button from "components/buttons/Button";
import Spinner from "components/Spinner";
import Icon from "components/Icon";
import Textarea from "components/Textarea";
import CustomLink from "components/CustomLink";
import DataError from "components/DataError";
import paths from "router/paths";
import ActionsDropdown from "components/ActionsDropdown";
import { generateActionDropdownOptions } from "pages/hosts/details/HostDetailsPage/modals/RunScriptModal/ScriptsTableConfig";
UI - GitOps Mode: Core abstractions, first batch of applications (#26401) ## For #26229 – Part 1 ![ezgif-6bbe6d60c12ed4](https://github.com/user-attachments/assets/37a04b64-abd7-4605-b4ac-9542836ff562) - This PR contains the core abstractions, routes, API updates, and types for GitOps mode in the UI. Since this work will touch essentially every part of the Fleet UI, it is ripe for merge conflicts. To mitigate such conflicts, I'll be merging this work in a number of iterative PRs. ~To effectively gate any of this work from showing until it is all merged to `main`, [this commit](feedbb2d4c25ec2e304e1f18d409cee62f6752ed) hides the settings section that allows enabling/disabling this setting, effectively feature flagging the entire thing. In the last of these iterative PRs, that commit will be reverted to engage the entire feature. For testing purposes, reviewers can `git revert feedbb2d4c25ec2e304e1f18d409cee62f6752ed` locally~ The new settings section for this feature is feature flagged until all PRs are merged - to show the setting section while testing, run `ALLOW_GITOPS_MODE=true NODE_ENV=development yarn run webpack --progress --watch` in place of `make generate-dev` - Changes file will be added and feature flag removed in the last PR - [x] Settings page with routing, form, API integration (hidden until last PR) - [x] Activities - [x] Navbar indicator - Apply GOM conditional UI to: - [x] Manage enroll secret modal: .5 - Controls > - [x] Scripts: - Setup experience > - [x] Install software > Select software modal - [x] OS Settings > - [x] Custom settings - [x] Disk encryption - [x] OS Updates 2/18/25, added to this PR: - [x] Controls > Setup experience > Run script - [x] Software > - [x] Manage automations modal - [x] Add software > - [x] App Store (VPP) - [x] Custom package - [x] Queries - [x] Manage - [x] Automations modal - [x] New - [x] Edit - [x] Policies - [x] Manage - [x] New - [x] Edit - Manage automations - [x] Calendar events - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-02-20 16:41:07 +00:00
import GitOpsModeTooltipWrapper from "components/GitOpsModeTooltipWrapper";
import { getPathWithQueryParams } from "utilities/url";
import { IPaginatedListScript } from "pages/hosts/ManageHostsPage/components/RunScriptBatchPaginatedList/RunScriptBatchPaginatedList";
const baseClass = "script-details-modal";
type PartialOrFullHostScript =
| Pick<IHostScript, "script_id" | "name"> // Use on Scripts page does not include last_execution
| IHostScript;
interface IScriptDetailsModalProps {
onCancel: () => void;
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
/** optional onClose to allow both "go back" behavior and "close" behavior depending on context */
onClose?: () => void;
onDelete?: () => void;
runScriptHelpText?: boolean;
showHostScriptActions?: boolean;
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
onClickRun?: (script: IHostScript) => void;
hostTeamId?: number | null;
selectedScriptId?: number;
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
selectedScriptDetails?: PartialOrFullHostScript | IPaginatedListScript | null;
selectedScriptContent?: string;
isLoadingScriptContent?: boolean;
isScriptContentError?: Error | null;
isHidden?: boolean;
onClickRunDetails?: (scriptExecutionId: string) => void;
teamIdForApi?: number;
suppressSecondaryActions?: boolean;
customPrimaryButtons?: React.ReactNode;
}
const ScriptDetailsModal = ({
onCancel,
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
onClose,
onDelete,
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
onClickRun,
runScriptHelpText = false,
showHostScriptActions = false,
hostTeamId,
selectedScriptId,
selectedScriptDetails,
selectedScriptContent,
isLoadingScriptContent,
isScriptContentError,
isHidden = false,
onClickRunDetails,
teamIdForApi,
suppressSecondaryActions = false,
customPrimaryButtons,
}: IScriptDetailsModalProps) => {
// For scrollable modal
const [isTopScrolling, setIsTopScrolling] = useState(false);
const topDivRef = useRef<HTMLDivElement>(null);
const checkScroll = () => {
if (topDivRef.current) {
const isScrolling =
topDivRef.current.scrollHeight > topDivRef.current.clientHeight;
setIsTopScrolling(isScrolling);
}
};
const { currentUser } = useContext(AppContext);
const { renderFlash } = useContext(NotificationContext);
// handle multiple possibilities for `selectedScriptDetails`
let scriptId: number | null = null;
if (selectedScriptId) {
scriptId = selectedScriptId;
} else if (selectedScriptDetails) {
if ("script_id" in selectedScriptDetails) {
scriptId = selectedScriptDetails.script_id;
} else if ("id" in selectedScriptDetails) {
scriptId = selectedScriptDetails.id;
}
}
const {
data: scriptContent,
error: isSelectedScriptContentError,
isLoading: isLoadingSelectedScriptContent,
} = useQuery<any, Error>(
["scriptContent", scriptId],
() =>
scriptId
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
scriptAPI.downloadScript(scriptId)
: Promise.resolve(null),
{
refetchOnWindowFocus: false,
enabled: !selectedScriptContent && !!scriptId,
}
);
// For scrollable modal
useEffect(() => {
checkScroll();
window.addEventListener("resize", checkScroll);
return () => window.removeEventListener("resize", checkScroll);
}, [scriptContent]); // Re-run when data changes
const getScriptContent = async () => {
try {
const content = selectedScriptContent || scriptContent;
const formatDate = format(new Date(), "yyyy-MM-dd");
const filename = `${formatDate} ${
selectedScriptDetails?.name || "Script details"
}`;
const file = new File([content], filename);
FileSaver.saveAs(file);
} catch {
renderFlash("error", "Couldnt Download. Please try again.");
}
};
const onClickDownload = () => {
if (selectedScriptContent) {
const formatDate = format(new Date(), "yyyy-MM-dd");
const filename = `${formatDate} ${selectedScriptDetails?.name}`;
const file = new File([selectedScriptContent], filename);
FileSaver.saveAs(file);
} else {
getScriptContent();
}
};
const onSelectMoreActions = useCallback(
async (action: string, script: IHostScript) => {
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
switch (action) {
case "showRunDetails": {
if (script.last_execution?.execution_id) {
onClickRunDetails &&
onClickRunDetails(script.last_execution?.execution_id);
}
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
break;
}
case "run": {
// should always be present if these actions are visible
onClickRun && onClickRun(script);
break;
}
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
default: // do nothing
}
},
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
[onClickRunDetails, onClickRun]
);
const shouldShowFooter =
!isLoadingScriptContent && selectedScriptDetails !== undefined;
const renderFooter = () => {
return (
<ModalFooter
isTopScrolling={isTopScrolling}
secondaryButtons={
suppressSecondaryActions ? undefined : (
<>
<Button
className={`${baseClass}__action-button`}
variant="icon"
onClick={() => onClickDownload()}
>
<Icon name="download" />
</Button>
<GitOpsModeTooltipWrapper
position="bottom"
renderChildren={(disableChildren) => (
<Button
disabled={disableChildren}
className={`${baseClass}__action-button`}
variant="icon"
onClick={onDelete}
>
<Icon name="trash" color="ui-fleet-black-75" />
</Button>
)}
/>
</>
)
}
primaryButtons={
customPrimaryButtons || (
<>
{showHostScriptActions && selectedScriptDetails && (
<div className={`${baseClass}__manage-automations-wrapper`}>
<ActionsDropdown
className={`${baseClass}__manage-automations-dropdown`}
onChange={(value) =>
onSelectMoreActions(
value,
selectedScriptDetails as IHostScript
)
}
placeholder="More actions"
isSearchable={false}
options={generateActionDropdownOptions(
currentUser,
hostTeamId || null,
selectedScriptDetails as IHostScript
)}
menuPlacement="top"
/>
</div>
)}
<Button onClick={onCancel}>Done</Button>
</>
)
}
/>
);
};
const renderContent = () => {
if (isLoadingScriptContent || isLoadingSelectedScriptContent) {
return <Spinner />;
}
if (isScriptContentError || isSelectedScriptContentError) {
return <DataError description="Close this modal and try again." />;
}
return (
<div
className={`${baseClass}__script-content modal-scrollable-content`}
ref={topDivRef}
>
<Textarea label="Script content:" variant="code">
{scriptContent}
</Textarea>
{runScriptHelpText && (
<div className="form-field__help-text">
To run this script on a host, go to the{" "}
<CustomLink
text="Hosts"
url={getPathWithQueryParams(paths.MANAGE_HOSTS, {
team_id: teamIdForApi,
})}
/>{" "}
page and select a host.
<br />
To run the script across multiple hosts, add a policy automation on
the{" "}
<CustomLink
text="Policies"
url={getPathWithQueryParams(paths.MANAGE_POLICIES, {
team_id: teamIdForApi,
})}
/>{" "}
page.
</div>
)}
</div>
);
};
return (
<Modal
className={baseClass}
title={selectedScriptDetails?.name || "Script details"}
width="large"
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
onExit={onClose ?? onCancel}
isHidden={isHidden}
>
<>
{renderContent()}
UI: Confirm before running scripts (#33679) <!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #28711 and #33685 - Adds a confirmation step to 2 run script user flows: - Host details > Actions > Run script > Actions > Run - Host details > Actions > Run script > Click script name for script details > More actions > Run - For each user flow, canceling / going back takes the user to wherever they came from, e.g., to the run script (scripts table) modal or to the script details modal - Confirming the script run always redirects to the run script (scripts table) modal - Consolidates and streamlines logic of the script modal group - Clarify + solidify modal options in script modal group <img width="1208" height="693" alt="Screenshot 2025-09-30 at 4 12 46 PM" src="https://github.com/user-attachments/assets/160d4105-cbd1-48f5-9d52-1e11f81f87f5" /> # 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/ - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - New Features - Added a confirmation dialog before running a script from a host’s details, clearly showing the script and host names. - Improvements - Streamlined script run flow with clearer loading indicators and smoother transitions between modals. - Enhanced modal behavior: consistent close/cancel handling and the ability to return to the previous view after canceling a run. - More consistent actions in script details and run views, reducing unexpected refreshes and interruptions. - Chores - Internal test updates to improve reliability of user interaction simulations. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-10-01 17:15:30 +00:00
{shouldShowFooter && renderFooter()}
</>
</Modal>
);
};
export default ScriptDetailsModal;