Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For R.C. - Fleet UI: Add copy for policy tied to install software #25247

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions frontend/components/PlatformSelector/PlatformSelector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react";
import classNames from "classnames";

import { IPolicySoftwareToInstall } from "interfaces/policy";
import Checkbox from "components/forms/fields/Checkbox";
import CustomLink from "components/CustomLink";
import TooltipWrapper from "components/TooltipWrapper";
import { buildQueryStringFromParams } from "utilities/url";
import paths from "router/paths";

interface IPlatformSelectorProps {
baseClass?: string;
Expand All @@ -13,6 +19,8 @@ interface IPlatformSelectorProps {
setCheckLinux: (val: boolean) => void;
setCheckChrome: (val: boolean) => void;
disabled?: boolean;
installSoftware?: IPolicySoftwareToInstall;
currentTeamId?: number;
}

export const PlatformSelector = ({
Expand All @@ -26,16 +34,48 @@ export const PlatformSelector = ({
setCheckLinux,
setCheckChrome,
disabled = false,
installSoftware,
currentTeamId,
}: IPlatformSelectorProps): JSX.Element => {
const baseClass = "platform-selector";

const labelClasses = classNames("form-field__label", {
[`form-field__label--disabled`]: disabled,
});

const renderInstallSoftwareHelpText = () => {
if (!installSoftware) {
return null;
}
const softwareName = installSoftware.name;
const softwareId = installSoftware.software_title_id.toString();
const softwareLink = `${paths.SOFTWARE_TITLE_DETAILS(
softwareId
)}?${buildQueryStringFromParams({ team_id: currentTeamId })}`;

return (
<span className={`${baseClass}__install-software`}>
<CustomLink text={softwareName} url={softwareLink} /> will only install
on{" "}
<TooltipWrapper
tipContent={
<>
To see targets, select{" "}
<b>{softwareName} &gt; Actions &gt; Edit</b>. Currently, hosts
that aren&apos;t targeted show an empty (---) policy status.
</>
}
>
targeted hosts
</TooltipWrapper>
.
</span>
);
};

return (
<div className={`${parentClass}__${baseClass} ${baseClass} form-field`}>
<span className={labelClasses}>Targets:</span>
<span className={labelClasses}>Target:</span>
<span className={`${baseClass}__checkboxes`}>
<Checkbox
value={checkDarwin}
Expand Down Expand Up @@ -71,9 +111,8 @@ export const PlatformSelector = ({
</Checkbox>
</span>
<div className="form-field__help-text">
Your policy will only run on the selected platform(s). Additionally, if
install software automation is enabled, it will only be installed on
hosts defined in the software scope.
Policy runs on all hosts with these platform(s).
{renderInstallSoftwareHelpText()}
</div>
</div>
);
Expand Down
8 changes: 7 additions & 1 deletion frontend/components/PlatformSelector/_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// override global form-field width: 100%
width: auto;

span {
&__checkboxes {
display: flex;
align-items: center;
gap: 12px;
Expand All @@ -15,4 +15,10 @@
&__platform-checkbox-wrapper {
width: auto;
}

.form-field__help-text {
display: flex;
flex-direction: column;
gap: $pad-medium;
}
}
9 changes: 8 additions & 1 deletion frontend/hooks/usePlatformSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
QUERYABLE_PLATFORMS,
QueryablePlatform,
} from "interfaces/platform";
import { IPolicySoftwareToInstall } from "interfaces/policy";

import PlatformSelector from "components/PlatformSelector";

Expand All @@ -15,12 +16,16 @@ export interface IPlatformSelector {
isAnyPlatformSelected: boolean;
render: () => JSX.Element;
disabled?: boolean;
installSoftware?: IPolicySoftwareToInstall;
currentTeamId?: number;
}

const usePlatformSelector = (
platformContext: SelectedPlatformString | null | undefined,
baseClass = "",
disabled = false
disabled = false,
installSoftware: IPolicySoftwareToInstall | undefined,
currentTeamId: number | undefined
): IPlatformSelector => {
const [checkDarwin, setCheckDarwin] = useState(false);
const [checkWindows, setCheckWindows] = useState(false);
Expand Down Expand Up @@ -73,6 +78,8 @@ const usePlatformSelector = (
setCheckLinux={setCheckLinux}
setCheckChrome={setCheckChrome}
disabled={disabled}
installSoftware={installSoftware}
currentTeamId={currentTeamId}
/>
);
}, [checkDarwin, checkWindows, checkLinux, checkChrome, disabled]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ const PolicyForm = ({

const {
currentUser,
currentTeam,
isGlobalObserver,
isGlobalAdmin,
isGlobalMaintainer,
Expand Down Expand Up @@ -146,7 +147,9 @@ const PolicyForm = ({
const platformSelector = usePlatformSelector(
lastEditedQueryPlatform,
baseClass,
platformSelectorDisabled
platformSelectorDisabled,
storedPolicy?.install_software,
currentTeam?.id
);

const {
Expand Down
Loading