fleet/frontend/pages/SoftwarePage/components/PackageAdvancedOptions/PackageAdvancedOptions.tsx

152 lines
4.4 KiB
TypeScript
Raw Normal View History

import React, { useState } from "react";
import { noop } from "lodash";
import { LEARN_MORE_ABOUT_BASE_LINK } from "utilities/constants";
import {
isPackageType,
isWindowsPackageType,
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 17:49:27 +00:00
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, ${
UI – Uninstall features for host details, install/uninstall actions, activity feed, misc other items (#21933) ## #21566 - Host details updates for Uninstall packages details > software page. Full tasks outlined in the issue, [Figma here](https://www.figma.com/design/ToQaK2yUJwDyzagTdrbOfX/%2320320-Uninstall-packages?node-id=5364-13173&m=dev) **Updated install status tooltips:** ![install-status-tooltips](https://github.com/user-attachments/assets/9869c7d6-f953-4adc-9692-52f5dad9d81a) **Uninstall action:** ![uninstall-action](https://github.com/user-attachments/assets/189d5755-556c-48ca-8824-08db14ec95d4) **Update install details:** ![Screenshot 2024-09-09 at 1 12 58 PM](https://github.com/user-attachments/assets/f52b349b-9f01-49d4-b952-6efd60f29979) ## #21931 - updated specs for install/uninstall states ## #21568 - activity feed items for Uninstall ![Screenshot 2024-09-09 at 5 00 07 PM](https://github.com/user-attachments/assets/eb61949a-9f8d-4b9e-a437-2d31a6808f07) ![Screenshot 2024-09-09 at 5 42 52 PM](https://github.com/user-attachments/assets/a8c2de0e-27e3-4d2b-bf69-702ea7b72e48) ![Screenshot 2024-09-09 at 5 43 03 PM](https://github.com/user-attachments/assets/b6127ed3-6fcf-439e-aa3d-91038a025d92) ## #21567 - Uninstall details modal ![Screenshot 2024-09-10 at 7 42 18 PM](https://github.com/user-attachments/assets/a42e4e4a-eadd-4e75-84c5-c5f6a6230950) _remaining TODO_: - [x] manually QA 'failed' states - [x] determine where to source timestamp from for uninstall activities - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Jacob Shandling <jacob@fleetdm.com> Co-authored-by: Victor Lyuboslavsky <victor@fleetdm.com>
2024-09-12 15:51:59 +00:00
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) => {
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 17:49:27 +00:00
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;