Skip to content

Commit

Permalink
UI – Add policy automation modal for running scripts (#22436)
Browse files Browse the repository at this point in the history
## #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](#22436 (comment))


![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>
  • Loading branch information
3 people authored Oct 4, 2024
1 parent e4df7ab commit ce9bb71
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 52 deletions.
1 change: 1 addition & 0 deletions changes/22118-run-scripts-fe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Add ability to trigger script run on policy failure
9 changes: 8 additions & 1 deletion frontend/interfaces/policy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PropTypes from "prop-types";
import { SelectedPlatformString } from "interfaces/platform";
import { IScript } from "./script";

// Legacy PropTypes used on host interface
export default PropTypes.shape({
Expand Down Expand Up @@ -42,8 +43,8 @@ export interface IPolicy {
critical: boolean;
calendar_events_enabled: boolean;
install_software?: IPolicySoftwareToInstall;
run_script?: Pick<IScript, "id" | "name">;
}

export interface IPolicySoftwareToInstall {
name: string;
software_title_id: number;
Expand Down Expand Up @@ -90,6 +91,10 @@ export interface ILoadTeamPoliciesResponse {
policies?: IPolicyStats[];
}

export interface ILoadTeamPolicyResponse {
policy: IPolicyStats;
}

export interface IPolicyFormData {
description?: string | number | boolean | undefined;
resolution?: string | number | boolean | undefined;
Expand All @@ -102,6 +107,8 @@ export interface IPolicyFormData {
calendar_events_enabled?: boolean;
// undefined from GET/LIST when not set, null for PATCH to unset
software_title_id?: number | null;
// null for PATCH to unset - note asymmetry with GET/LIST - see IPolicy.run_script
script_id?: number | null;
}

export interface IPolicyNew {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ 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";

Expand All @@ -27,8 +30,15 @@ const DeleteScriptModal = ({
try {
await scriptAPI.deleteScript(id);
renderFlash("success", "Successfully deleted!");
} catch {
renderFlash("error", "Couldn’t delete. Please try again.");
} 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."
);
}
onDone();
};
Expand Down
Loading

0 comments on commit ce9bb71

Please sign in to comment.