fleet/frontend/components/Editor/Editor.stories.tsx
Allen Houchins 150318c87e
Add Python script support for macOS and Linux (#38562)
This commit introduces support for Python (.py) scripts on macOS and
Linux, including validation for Python shebangs and updates to
documentation, UI, error messages, and backend validation logic. It also
updates tests and file upload handling to recognize and properly process
Python scripts alongside existing shell (.sh) and PowerShell (.ps1)
scripts.

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #

# Checklist for submitter

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

- [ ] 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/guides/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)
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes

## Testing

- [ ] Added/updated automated tests
- [ ] Where appropriate, [automated tests simulate multiple hosts and
test for host
isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing)
(updates to one hosts's records do not affect another)

- [ ] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [ ] Confirmed that the fix is not expected to adversely impact load
test results
- [ ] Alerted the release DRI if additional load testing is needed

## 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`).

## New Fleet configuration settings

- [ ] Setting(s) is/are explicitly excluded from GitOps

If you didn't check the box above, follow this checklist for
GitOps-enabled settings:

- [ ] Verified that the setting is exported via `fleetctl
generate-gitops`
- [ ] Verified the setting is documented in a separate PR to [the GitOps
documentation](https://github.com/fleetdm/fleet/blob/main/docs/Configuration/yaml-files.md#L485)
- [ ] Verified that the setting is cleared on the server if it is not
supplied in a YAML file (or that it is documented as being optional)
- [ ] Verified that any relevant UI is disabled when GitOps mode is
enabled

## fleetd/orbit/Fleet Desktop

- [ ] Verified compatibility with the latest released version of Fleet
(see [Must
rule](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/workflows/fleetd-development-and-release-strategy.md))
- [ ] If the change applies to only one platform, confirmed that
`runtime.GOOS` is used as needed to isolate changes
- [ ] Verified that fleetd runs on macOS, Linux and Windows
- [ ] Verified auto-update works from the released version of component
to the new version (see [tools/tuf/test](../tools/tuf/test/README.md))

---------

Co-authored-by: Jordan Montgomery <elijah.jordan.montgomery@gmail.com>
Co-authored-by: melpike <79950145+melpike@users.noreply.github.com>
Co-authored-by: jkatz01 <yehonatankatz@gmail.com>
Co-authored-by: Jonathan Katz <44128041+jkatz01@users.noreply.github.com>
2026-03-24 10:01:54 -04:00

170 lines
4.3 KiB
TypeScript

import { Meta, StoryObj } from "@storybook/react";
import { action } from "@storybook/addon-actions";
import Editor from ".";
const meta: Meta<typeof Editor> = {
component: Editor,
title: "Components/FormFields/Editor",
argTypes: {
mode: {
control: "select",
options: ["sh", "python", "powershell"],
description: "Syntax highlighting mode",
},
readOnly: { control: "boolean" },
enableCopy: { control: "boolean" },
wrapEnabled: { control: "boolean" },
isFormField: { control: "boolean" },
focus: { control: "boolean" },
label: { control: "text" },
labelTooltip: { control: "text" },
error: { control: "text" },
helpText: { control: "text" },
value: { control: "text" },
defaultValue: { control: "text" },
maxLines: { control: "number" },
name: { control: "text" },
},
};
export default meta;
type Story = StoryObj<typeof Editor>;
export const Default: Story = {
args: {
name: "default-editor",
label: "Shell Script Editor",
value: "#!/bin/bash\necho 'Hello, World!'",
mode: "sh",
onChange: action("onChange"),
onBlur: action("onBlur"),
},
};
export const WithError: Story = {
args: {
...Default.args,
name: "error-editor",
label: "Editor with Error",
error: "There is a syntax error",
value: "echo 'Missing closing quote",
},
};
export const WithHelpText: Story = {
args: {
...Default.args,
name: "help-text-editor",
label: "Editor with Help Text",
helpText: "Write your shell script here. Supports Bash and PowerShell.",
},
};
export const WithTooltip: Story = {
args: {
...Default.args,
name: "tooltip-editor",
label: "Editor with Tooltip",
labelTooltip: "This editor supports syntax highlighting for shell scripts.",
},
};
export const ReadOnly: Story = {
args: {
...Default.args,
name: "readonly-editor",
label: "Read-only Editor",
readOnly: true,
value: "# This editor is read-only\nls -la",
},
};
export const WithCopyButton: Story = {
args: {
...Default.args,
name: "copy-editor",
label: "Editor with Copy Button",
value: "echo 'Copy this script!'",
enableCopy: true,
},
};
export const PowerShellMode: Story = {
args: {
...Default.args,
name: "powershell-editor",
label: "PowerShell Editor",
value: "Write-Host 'Hello from PowerShell!'",
mode: "powershell",
},
};
export const WrappedLines: Story = {
args: {
...Default.args,
name: "wrapped-lines-editor",
label: "Editor with Wrapped Lines",
value:
"# This is a very long line that should wrap to the next line in the editor to demonstrate the wrapEnabled prop in action.",
wrapEnabled: true,
},
};
export const CustomMaxLines: Story = {
args: {
...Default.args,
name: "custom-maxlines-editor",
label: "Editor with Custom Max Lines",
value: "echo 'Line 1'\necho 'Line 2'\necho 'Line 3'\n",
maxLines: 3,
},
};
export const LongScriptWithCopy: Story = {
args: {
name: "long-script-editor",
label: "Long Script with Copy Button",
enableCopy: true,
mode: "sh",
value: `#!/bin/bash
# This is a long example script to test the editor's UI with overflow and copy button interaction.
echo "Starting system update..."
sudo apt-get update -y && sudo apt-get upgrade -y
echo "Installing dependencies..."
sudo apt-get install -y git curl wget unzip build-essential python3 python3-pip
echo "Cloning repository..."
git clone https://github.com/example/repo.git /opt/example-repo
echo "Setting up environment variables..."
export APP_ENV=production
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=admin
export DB_PASSWORD=supersecurepassword1234567890
echo "Configuring application..."
cd /opt/example-repo
cp config.example.json config.json
sed -i 's/localhost/127.0.0.1/g' config.json
echo "Running database migrations..."
python3 manage.py migrate
echo "Starting application..."
nohup python3 manage.py runserver 0.0.0.0:8000 &
echo "Setup complete! Application is running."
`,
wrapEnabled: false, // Try toggling this to true to see the difference!
maxLines: 20,
helpText:
"This is a realistic, long shell script. Try copying it or scrolling horizontally.",
onChange: action("onChange"),
onBlur: action("onBlur"),
},
};