aboutsummaryrefslogtreecommitdiffstats
path: root/ui/src/components/runbooks/editor
diff options
context:
space:
mode:
Diffstat (limited to 'ui/src/components/runbooks/editor')
-rw-r--r--ui/src/components/runbooks/editor/Editor.tsx33
-rw-r--r--ui/src/components/runbooks/editor/blocks/Directory/index.tsx65
-rw-r--r--ui/src/components/runbooks/editor/blocks/Run/extensions.ts (renamed from ui/src/components/runbooks/editor/blocks/RunBlock/extensions.ts)0
-rw-r--r--ui/src/components/runbooks/editor/blocks/Run/index.css (renamed from ui/src/components/runbooks/editor/blocks/RunBlock/index.css)0
-rw-r--r--ui/src/components/runbooks/editor/blocks/Run/index.tsx (renamed from ui/src/components/runbooks/editor/blocks/RunBlock/index.tsx)25
-rw-r--r--ui/src/components/runbooks/editor/blocks/Run/terminal.tsx (renamed from ui/src/components/runbooks/editor/blocks/RunBlock/terminal.tsx)0
6 files changed, 115 insertions, 8 deletions
diff --git a/ui/src/components/runbooks/editor/Editor.tsx b/ui/src/components/runbooks/editor/Editor.tsx
index bbf594d8..6b0522f5 100644
--- a/ui/src/components/runbooks/editor/Editor.tsx
+++ b/ui/src/components/runbooks/editor/Editor.tsx
@@ -36,10 +36,12 @@ import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/core/fonts/inter.css";
import "@blocknote/mantine/style.css";
-import { Code } from "lucide-react";
+import { CodeIcon, FolderOpenIcon } from "lucide-react";
import { useDebounceCallback } from "usehooks-ts";
-import RunBlock from "@/components/runbooks/editor/blocks/RunBlock";
+import Run from "@/components/runbooks/editor/blocks/Run";
+import Directory from "@/components/runbooks/editor/blocks/Directory";
+
import { DeleteBlock } from "@/components/runbooks/editor/ui/DeleteBlockButton";
import { AtuinState, useStore } from "@/state/store";
import Runbook from "@/state/runbooks/runbook";
@@ -52,21 +54,34 @@ const schema = BlockNoteSchema.create({
...defaultBlockSpecs,
// Adds the code block.
- run: RunBlock,
+ run: Run,
+ directory: Directory,
},
});
// Slash menu item to insert an Alert block
const insertRun = (editor: typeof schema.BlockNoteEditor) => ({
- title: "Code block",
+ title: "Code",
onItemClick: () => {
insertOrUpdateBlock(editor, {
type: "run",
});
},
- icon: <Code size={18} />,
+ icon: <CodeIcon size={18} />,
aliases: ["code", "run"],
- group: "Code",
+ group: "Execute",
+});
+
+const insertDirectory = (editor: typeof schema.BlockNoteEditor) => ({
+ title: "Directory",
+ onItemClick: () => {
+ insertOrUpdateBlock(editor, {
+ type: "directory",
+ });
+ },
+ icon: <FolderOpenIcon size={18} />,
+ aliases: ["directory", "dir", "folder"],
+ group: "Execute",
});
export default function Editor() {
@@ -161,7 +176,11 @@ export default function Editor() {
triggerCharacter={"/"}
getItems={async (query: any) =>
filterSuggestionItems(
- [...getDefaultReactSlashMenuItems(editor), insertRun(editor)],
+ [
+ ...getDefaultReactSlashMenuItems(editor),
+ insertRun(editor),
+ insertDirectory(editor),
+ ],
query,
)
}
diff --git a/ui/src/components/runbooks/editor/blocks/Directory/index.tsx b/ui/src/components/runbooks/editor/blocks/Directory/index.tsx
new file mode 100644
index 00000000..38e974ff
--- /dev/null
+++ b/ui/src/components/runbooks/editor/blocks/Directory/index.tsx
@@ -0,0 +1,65 @@
+import { useState } from "react";
+import { Input, Tooltip } from "@nextui-org/react";
+import { FolderInputIcon, HelpCircleIcon } from "lucide-react";
+
+// @ts-ignore
+import { createReactBlockSpec } from "@blocknote/react";
+
+interface DirectoryProps {
+ path: string;
+ onInputChange: (string) => void;
+}
+
+const Directory = ({ path, onInputChange }: DirectoryProps) => {
+ const [value, setValue] = useState(path);
+
+ return (
+ <div className="w-full !max-w-full !outline-none overflow-none">
+ <Tooltip
+ content="Change working directory for all subsequent code blocks"
+ delay={1000}
+ >
+ <Input
+ label="Directory"
+ placeholder="~"
+ labelPlacement="outside"
+ value={value}
+ autoComplete="off"
+ autoCapitalize="off"
+ autoCorrect="off"
+ spellCheck="false"
+ onValueChange={(val) => {
+ setValue(val);
+ onInputChange(val);
+ }}
+ startContent={<FolderInputIcon />}
+ />
+ </Tooltip>
+ </div>
+ );
+};
+
+export default createReactBlockSpec(
+ {
+ type: "directory",
+ propSchema: {
+ path: { default: "" },
+ },
+ content: "none",
+ },
+ {
+ // @ts-ignore
+ render: ({ block, editor, code, type }) => {
+ const onInputChange = (val: string) => {
+ editor.updateBlock(block, {
+ // @ts-ignore
+ props: { ...block.props, path: val },
+ });
+ };
+
+ return (
+ <Directory path={block.props.path} onInputChange={onInputChange} />
+ );
+ },
+ },
+);
diff --git a/ui/src/components/runbooks/editor/blocks/RunBlock/extensions.ts b/ui/src/components/runbooks/editor/blocks/Run/extensions.ts
index 76fc4343..76fc4343 100644
--- a/ui/src/components/runbooks/editor/blocks/RunBlock/extensions.ts
+++ b/ui/src/components/runbooks/editor/blocks/Run/extensions.ts
diff --git a/ui/src/components/runbooks/editor/blocks/RunBlock/index.css b/ui/src/components/runbooks/editor/blocks/Run/index.css
index e854c03b..e854c03b 100644
--- a/ui/src/components/runbooks/editor/blocks/RunBlock/index.css
+++ b/ui/src/components/runbooks/editor/blocks/Run/index.css
diff --git a/ui/src/components/runbooks/editor/blocks/RunBlock/index.tsx b/ui/src/components/runbooks/editor/blocks/Run/index.tsx
index 25faa211..e0989f47 100644
--- a/ui/src/components/runbooks/editor/blocks/RunBlock/index.tsx
+++ b/ui/src/components/runbooks/editor/blocks/Run/index.tsx
@@ -1,5 +1,6 @@
// @ts-ignore
import { createReactBlockSpec } from "@blocknote/react";
+
import "./index.css";
import CodeMirror from "@uiw/react-codemirror";
@@ -26,8 +27,25 @@ interface RunBlockProps {
type: string;
pty: string;
isEditable: boolean;
+ editor: any;
}
+const findFirstParentOfType = (editor: any, id: string, type: string): any => {
+ // TODO: the types for blocknote aren't working. Now I'm doing this sort of shit,
+ // really need to fix that.
+ const document = editor.document;
+ var lastOfType = null;
+
+ // Iterate through ALL of the blocks.
+ for (let i = 0; i < document.length; i++) {
+ if (document[i].id == id) return lastOfType;
+
+ if (document[i].type == type) lastOfType = document[i];
+ }
+
+ return lastOfType;
+};
+
const RunBlock = ({
onChange,
id,
@@ -36,6 +54,7 @@ const RunBlock = ({
onRun,
onStop,
pty,
+ editor,
}: RunBlockProps) => {
const [value, setValue] = useState<String>(code);
const cleanupPtyTerm = useStore((store: AtuinState) => store.cleanupPtyTerm);
@@ -68,7 +87,9 @@ const RunBlock = ({
}
if (!isRunning) {
- let pty = await invoke<string>("pty_open");
+ const cwd = findFirstParentOfType(editor, id, "directory");
+ console.log(cwd.props.path);
+ let pty = await invoke<string>("pty_open", { cwd: cwd.props.path });
if (onRun) onRun(pty);
if (currentRunbook) incRunbookPty(currentRunbook);
@@ -150,6 +171,7 @@ export default createReactBlockSpec(
},
code: { default: "" },
pty: { default: "" },
+ global: { default: false },
},
content: "none",
},
@@ -186,6 +208,7 @@ export default createReactBlockSpec(
isEditable={editor.isEditable}
onRun={onRun}
onStop={onStop}
+ editor={editor}
/>
);
},
diff --git a/ui/src/components/runbooks/editor/blocks/RunBlock/terminal.tsx b/ui/src/components/runbooks/editor/blocks/Run/terminal.tsx
index a6dc589f..a6dc589f 100644
--- a/ui/src/components/runbooks/editor/blocks/RunBlock/terminal.tsx
+++ b/ui/src/components/runbooks/editor/blocks/Run/terminal.tsx