fleet/frontend/pages/SoftwarePage/components/PackageAdvancedOptions/PackageAdvancedOptions.tsx
Roberto Dip ad99cbd499
FMA: missing pieces (#22593)
# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 14:49:27 -03:00

151 lines
4.4 KiB
TypeScript

import React, { useState } from "react";
import { noop } from "lodash";
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
import {
isPackageType,
isWindowsPackageType,
isFleetMaintainedPackageType,
PackageType,
} from "interfaces/package_type";
import CustomLink from "components/CustomLink";
import RevealButton from "components/buttons/RevealButton";
import { IPackageFormData } from "../PackageForm/PackageForm";
import AdvancedOptionsFields from "../AdvancedOptionsFields";
const getSupportedScriptTypeText = (pkgType: PackageType) => {
return `Currently, ${
isWindowsPackageType(pkgType) ? "PowerS" : "s"
}hell scripts are supported.`;
};
const PKG_TYPE_TO_ID_TEXT = {
pkg: "package IDs",
deb: "package name",
rpm: "package name",
msi: "product code",
exe: "software name",
} as const;
const getInstallHelpText = (pkgType: PackageType) => (
<>
Use the $INSTALLER_PATH variable to point to the installer.{" "}
{getSupportedScriptTypeText(pkgType)}{" "}
<CustomLink
url={`${LEARN_MORE_ABOUT_BASE_LINK}/install-scripts`}
text="Learn more about install scripts"
newTab
/>
</>
);
const getPostInstallHelpText = (pkgType: PackageType) => {
return getSupportedScriptTypeText(pkgType);
};
const getUninstallHelpText = (pkgType: PackageType) => {
if (isFleetMaintainedPackageType(pkgType)) {
return "Currently, shell scripts are supported";
}
return (
<>
$PACKAGE_ID will be populated with the {PKG_TYPE_TO_ID_TEXT[pkgType]} from
the .{pkgType} file after the software is added.{" "}
{getSupportedScriptTypeText(pkgType)}{" "}
<CustomLink
url={`${LEARN_MORE_ABOUT_BASE_LINK}/uninstall-scripts`}
text="Learn more about uninstall scripts"
newTab
/>
</>
);
};
const baseClass = "package-advanced-options";
interface IPackageAdvancedOptionsProps {
errors: { preInstallQuery?: string; postInstallScript?: string };
selectedPackage: IPackageFormData["software"];
preInstallQuery?: string;
installScript: string;
postInstallScript?: string;
uninstallScript?: string;
showSchemaButton?: boolean;
onClickShowSchema?: () => void;
onChangePreInstallQuery: (value?: string) => void;
onChangeInstallScript: (value: string) => void;
onChangePostInstallScript: (value?: string) => void;
onChangeUninstallScript: (value?: string) => void;
}
const PackageAdvancedOptions = ({
showSchemaButton = false,
errors,
selectedPackage,
preInstallQuery,
installScript,
postInstallScript,
uninstallScript,
onClickShowSchema = noop,
onChangePreInstallQuery,
onChangeInstallScript,
onChangePostInstallScript,
onChangeUninstallScript,
}: IPackageAdvancedOptionsProps) => {
const [showAdvancedOptions, setShowAdvancedOptions] = useState(false);
const renderAdvancedOptions = () => {
const name = selectedPackage?.name || "";
const ext = name.split(".").pop() as PackageType;
if (!isPackageType(ext)) {
// this should never happen
return null;
}
return (
<AdvancedOptionsFields
className={`${baseClass}__input-fields`}
showSchemaButton={showSchemaButton}
installScriptHelpText={getInstallHelpText(ext)}
postInstallScriptHelpText={getPostInstallHelpText(ext)}
uninstallScriptHelpText={getUninstallHelpText(ext)}
errors={errors}
preInstallQuery={preInstallQuery}
installScript={installScript}
postInstallScript={postInstallScript}
uninstallScript={uninstallScript}
onClickShowSchema={onClickShowSchema}
onChangePreInstallQuery={onChangePreInstallQuery}
onChangeInstallScript={onChangeInstallScript}
onChangePostInstallScript={onChangePostInstallScript}
onChangeUninstallScript={onChangeUninstallScript}
/>
);
};
return (
<div className={baseClass}>
<RevealButton
className={`${baseClass}__accordion-title`}
isShowing={showAdvancedOptions}
showText="Advanced options"
hideText="Advanced options"
caretPosition="after"
onClick={() => setShowAdvancedOptions(!showAdvancedOptions)}
disabled={!selectedPackage}
disabledTooltipContent={
<>
Choose a file to modify <br />
advanced options.
</>
}
/>
{showAdvancedOptions && !!selectedPackage && renderAdvancedOptions()}
</div>
);
};
export default PackageAdvancedOptions;