Files
fleet/frontend/components/Editor/Editor.tsx
T
Steven Palmesano 62ed3583e6 Clear button styles (#49292)
**Related issue:** Resolves #49276

**New features**
- Added new "Secondary" (bordered, off-white fill) and "Subdued"
(borderless, low-emphasis) button variants to match the Figma spec,
alongside the existing Primary style.
- Allowed rows to be selected in Controls > OS updates.

**Cleanup**
- Once nothing referenced the old styles anymore, fully removed the old
`text-icon`, `brand-inverse-icon`, `inverse-alert`, `inverse`, and
`icon` button variants (type, styles, and Storybook entries) from the
shared `Button` component.
- Removed the `iconStroke` prop, which had become a no-op once the old
variants it supported were gone.
- Renamed `ActionsDropdown`'s variants
(`button`/`brand-button`/`small-button`) to
`subdued`/`primary`/`secondary` to match the same naming used everywhere
else.
- Replaced a one-off dropdown implementation on the Software title page
with the shared `ActionsDropdown` component, instead of maintaining
duplicate styling logic.
- Changed the button name on Host details > Reports > Report details
from "View data for all hosts" to "View report for all hosts" (to match
the previous page's Actions drop-down options).


# Checklist for submitter

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.


## Testing

- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually

<img width="1475" height="241" alt="Screenshot 2026-07-21 at 06 35 49"
src="https://github.com/user-attachments/assets/7cfbd444-7837-40e8-854e-bc5989d57d85"
/>
<img width="661" height="306" alt="Screenshot 2026-07-21 at 06 37 18"
src="https://github.com/user-attachments/assets/5d0c4873-8179-4089-b115-7e8cd3a53b4d"
/>
<img width="1427" height="423" alt="Screenshot 2026-07-21 at 06 37 30"
src="https://github.com/user-attachments/assets/a4850a60-f44a-4902-b45e-0094f23a52f8"
/>
<img width="1427" height="640" alt="Screenshot 2026-07-21 at 06 37 46"
src="https://github.com/user-attachments/assets/738a4a7f-cd7d-4162-b659-6f649c32204d"
/>
<img width="1445" height="479" alt="Screenshot 2026-07-22 at 07 03 22"
src="https://github.com/user-attachments/assets/4f672dc0-5c6d-4eb8-8465-ed5233fcd1b2"
/>
<img width="811" height="871" alt="Screenshot 2026-07-21 at 06 41 20"
src="https://github.com/user-attachments/assets/5421c96e-2dab-492a-af26-be0e5a7791ca"
/>
2026-07-23 07:11:59 -05:00

175 lines
4.3 KiB
TypeScript

import React, { ReactNode } from "react";
import classnames from "classnames";
import AceEditor from "react-ace";
import "ace-builds/src-noconflict/mode-sh";
import "ace-builds/src-noconflict/mode-powershell";
import "ace-builds/src-noconflict/mode-python";
import "ace-builds/src-noconflict/mode-xml";
import { Ace } from "ace-builds";
import TooltipWrapper from "components/TooltipWrapper";
import CopyButton from "components/buttons/CopyButton";
const baseClass = "editor";
interface IEditorProps {
focus?: boolean;
label?: string;
labelTooltip?: string | JSX.Element;
error?: string | null;
readOnly?: boolean;
/**
* Help text to display below the editor.
*/
helpText?: ReactNode;
/** Sets the value of the input. Use this if you'd like the editor
* to be a controlled component */
value?: string;
/** Sets the default value of the input. Use this if you'd like the editor
* to be an uncontrolled component */
defaultValue?: string;
/** Enable copying the value of the editor.
* @default false
*/
enableCopy?: boolean;
/** Enabled wrapping lines.
* @default false
*/
wrapEnabled?: boolean;
/** A unique name for the editor.
* @default "editor"
*/
name?: string;
/** The syntax highlighting mode to use.
*/
mode?: string;
/** Include correct styles as a form field.
* @default true
*/
isFormField?: boolean;
maxLines?: number;
className?: string;
onChange?: (value: string, event?: Ace.Delta) => void;
onBlur?: () => void;
/** Called after the Ace editor mounts with the editor instance. */
onLoad?: (editor: Ace.Editor) => void;
}
/**
* This component is a generic editor that uses the AceEditor component.
* TODO: We should move SQLEditor and YamlAce into here and deprecate importing
* them directly. This component should be used for all editor components and
* be configurable from the props. We should look into dynmaic imports for
* this.
*/
const Editor = ({
helpText,
label,
labelTooltip,
error,
focus,
value,
defaultValue,
readOnly = false,
enableCopy = false,
wrapEnabled = false,
name = "editor",
mode,
isFormField = true,
maxLines = 20,
className,
onChange,
onBlur,
onLoad: onLoadProp,
}: IEditorProps) => {
const classNames = classnames(baseClass, className, {
"form-field": isFormField,
[`${baseClass}__error`]: !!error,
});
const renderCopyButton = () => {
return (
<div className={`${baseClass}__copy-wrapper`}>
<CopyButton copyText={value ?? ""} variant="subdued" />
</div>
);
};
const onLoadHandler = (editor: Ace.Editor) => {
// Lose focus using the Escape key so you can Tab forward (or Shift+Tab backwards) through app
editor.commands.addCommand({
name: "escapeToBlur",
bindKey: { win: "Esc", mac: "Esc" },
exec: (aceEditor) => {
aceEditor.blur(); // Lose focus from the editor
return true;
},
readOnly: true,
});
onLoadProp?.(editor);
};
const renderLabel = () => {
const labelText = error || label;
const labelClassName = classnames(`${baseClass}__label`, {
[`${baseClass}__label--error`]: !!error,
});
if (!labelText) {
return null;
}
if (labelTooltip) {
return (
<TooltipWrapper
className={labelClassName}
tipContent={labelTooltip}
position="top-start"
>
{labelText}
</TooltipWrapper>
);
}
return <div className={labelClassName}>{labelText}</div>;
};
const renderHelpText = () => {
if (helpText) {
return <div className={`${baseClass}__help-text`}>{helpText}</div>;
}
return null;
};
return (
<div className={classNames}>
{renderLabel()}
{enableCopy && renderCopyButton()}
<AceEditor
mode={mode}
wrapEnabled={wrapEnabled}
name={name}
className={baseClass}
fontSize={14}
theme="fleet"
width="100%"
readOnly={readOnly}
minLines={2}
maxLines={maxLines}
editorProps={{ $blockScrolling: Infinity }}
value={value}
defaultValue={defaultValue}
tabSize={2}
focus={focus}
onChange={onChange}
onBlur={onBlur}
onLoad={onLoadHandler}
/>
{renderHelpText()}
</div>
);
};
export default Editor;