fleet/frontend/pages/SoftwarePage/components/AdvancedOptionsFields/AdvancedOptionsFields.tsx
jacobshandling 7953fe2e2c
UI: Simplify New policy flow (#27173)
## For #26052 

- Remove add policy modal from flow
- Update "Schema" links
- Add "Examples" link


![add-policy](https://github.com/user-attachments/assets/69d60573-f6a6-45e8-92ff-4faa29f224a9)




- [x] Changes file added for user-visible changes in `changes/
- [x] A detailed QA plan exists on the associated ticket (if it isn't
there, work with the product group's QA engineer to add it)
- [x] Manual QA for all new/changed functionality

---------

Co-authored-by: Jacob Shandling <jacob@fleetdm.com>
2025-03-18 12:56:05 -07:00

113 lines
3.1 KiB
TypeScript

import React, { ReactNode } from "react";
import classnames from "classnames";
import Editor from "components/Editor";
import SQLEditor from "components/SQLEditor";
import Button from "components/buttons/Button";
import Icon from "components/Icon";
const baseClass = "advanced-options-fields";
interface IAdvancedOptionsFieldsProps {
showSchemaButton: boolean;
installScriptHelpText: ReactNode;
postInstallScriptHelpText: ReactNode;
uninstallScriptHelpText: ReactNode;
errors: { preInstallQuery?: string; postInstallScript?: string };
preInstallQuery?: string;
installScript: string;
postInstallScript?: string;
uninstallScript?: string;
className?: string;
onClickShowSchema: () => void;
onChangePreInstallQuery: (value?: string) => void;
onChangeInstallScript: (value: string) => void;
onChangePostInstallScript: (value?: string) => void;
onChangeUninstallScript: (value?: string) => void;
}
const AdvancedOptionsFields = ({
showSchemaButton,
installScriptHelpText,
postInstallScriptHelpText,
uninstallScriptHelpText,
errors,
preInstallQuery,
installScript,
postInstallScript,
uninstallScript,
className,
onClickShowSchema,
onChangePreInstallQuery,
onChangeInstallScript,
onChangePostInstallScript,
onChangeUninstallScript,
}: IAdvancedOptionsFieldsProps) => {
const classNames = classnames(baseClass, className);
const renderLabelComponent = (): JSX.Element | null => {
if (!showSchemaButton) {
return null;
}
return (
<Button variant="text-icon" onClick={onClickShowSchema}>
Schema
<Icon name="info" size="small" />
</Button>
);
};
return (
<div className={classNames}>
<SQLEditor
className="form-field"
focus
error={errors.preInstallQuery}
value={preInstallQuery}
placeholder="SELECT * FROM osquery_info WHERE start_time > 1"
label="Pre-install query"
name="preInstallQuery"
maxLines={10}
onChange={onChangePreInstallQuery}
labelActionComponent={renderLabelComponent()}
helpText="Software will be installed only if the query returns results."
/>
<Editor
wrapEnabled
maxLines={10}
name="install-script"
onChange={onChangeInstallScript}
value={installScript}
helpText={installScriptHelpText}
label="Install script"
isFormField
/>
<Editor
label="Post-install script"
focus
error={errors.postInstallScript}
wrapEnabled
name="post-install-script-editor"
maxLines={10}
onChange={onChangePostInstallScript}
value={postInstallScript}
helpText={postInstallScriptHelpText}
isFormField
/>
<Editor
label="Uninstall script"
focus
wrapEnabled
name="uninstall-script-editor"
maxLines={20}
onChange={onChangeUninstallScript}
value={uninstallScript}
helpText={uninstallScriptHelpText}
isFormField
/>
</div>
);
};
export default AdvancedOptionsFields;