From 83ee3035f587c9c9d7a87b799ffcbbb296215fae Mon Sep 17 00:00:00 2001 From: Raphael Schweikert Date: Thu, 10 Oct 2024 19:42:39 +0200 Subject: [PATCH] feat(editor): use a fancy editor for fallback hop editing --- package-lock.json | 14 +++++ package.json | 1 + src/main/frontend/App.tsx | 6 ++ src/main/frontend/sections/RunControls.tsx | 11 ++-- .../sections/editor/types/FallbackStep.tsx | 38 ++++-------- src/main/frontend/widgets/CodeEditor.tsx | 59 +++++++++++++++++++ src/main/frontend/widgets/StepEditor.tsx | 36 ++++++----- 7 files changed, 113 insertions(+), 52 deletions(-) create mode 100644 src/main/frontend/widgets/CodeEditor.tsx diff --git a/package-lock.json b/package-lock.json index c2088ee..89986a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^8.8.0", "@typescript-eslint/parser": "^8.8.0", + "@uidotdev/usehooks": "^2.4.1", "concurrently": "^9.0.1", "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", @@ -8152,6 +8153,19 @@ "url": "https://opencollective.com/typescript-eslint" } }, + "node_modules/@uidotdev/usehooks": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/@uidotdev/usehooks/-/usehooks-2.4.1.tgz", + "integrity": "sha512-1I+RwWyS+kdv3Mv0Vmc+p0dPYH0DTRAo04HLyXReYBL9AeseDWUJyi4THuksBJcu9F0Pih69Ak150VDnqbVnXg==", + "dev": true, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "react": ">=18.0.0", + "react-dom": ">=18.0.0" + } + }, "node_modules/@ungap/structured-clone": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", diff --git a/package.json b/package.json index ac8893c..f3092d2 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@types/react-dom": "^18.3.0", "@typescript-eslint/eslint-plugin": "^8.8.0", "@typescript-eslint/parser": "^8.8.0", + "@uidotdev/usehooks": "^2.4.1", "concurrently": "^9.0.1", "eslint": "^8.57.1", "eslint-config-prettier": "^9.1.0", diff --git a/src/main/frontend/App.tsx b/src/main/frontend/App.tsx index ce8021c..dfb5f79 100644 --- a/src/main/frontend/App.tsx +++ b/src/main/frontend/App.tsx @@ -48,6 +48,12 @@ const RootElement = styled('div')` > .output { grid-area: output; } + + label:not(coral-checkbox label) { + display: inline-flex; + align-items: baseline; + gap: 6px; + } `; export const App: FC<{ runEndpoint: string }> = props => { diff --git a/src/main/frontend/sections/RunControls.tsx b/src/main/frontend/sections/RunControls.tsx index e2d7f0d..7a00829 100644 --- a/src/main/frontend/sections/RunControls.tsx +++ b/src/main/frontend/sections/RunControls.tsx @@ -1,4 +1,4 @@ -import React, { FC, FormEvent, useContext, useId, useRef } from 'react'; +import React, { FC, FormEvent, useContext, useRef } from 'react'; import { styled } from 'goober'; import { RunEndpointContext, ScriptContext } from '../App'; @@ -32,18 +32,17 @@ export const RunControls: FC<{ runWith: (data: FormData) => Promise }> = ( await runWith(data); } - const id = useId(); - return ( {script.parameters.length ? (
Arguments
- {script.parameters.map(({ name, type }, i) => ( + {script.parameters.map(({ name, type }) => ( - - + ))}
diff --git a/src/main/frontend/sections/editor/types/FallbackStep.tsx b/src/main/frontend/sections/editor/types/FallbackStep.tsx index 69e4698..1af1d51 100644 --- a/src/main/frontend/sections/editor/types/FallbackStep.tsx +++ b/src/main/frontend/sections/editor/types/FallbackStep.tsx @@ -1,48 +1,32 @@ -import React, { FC, useContext, useEffect, useRef, useState } from 'react'; +import React, { FC, useContext } from 'react'; import { AnyHop, Hop } from '../../../model/hops'; import { StepEditor } from '../../../widgets/StepEditor'; import { ScriptContext } from '../../../App'; +import { CodeEditor } from '../../../widgets/CodeEditor'; export const FallbackStep: FC<{ parentHops: Hop[]; hop: AnyHop }> = ({ parentHops, hop }) => { const scriptContext = useContext(ScriptContext); - const { type: _, ...hopWithoutType } = hop; - const cleaned = JSON.stringify(hopWithoutType, null, ' '); - - const [code, setCode] = useState(cleaned); - const updated = useRef(false); - - useEffect(() => { - setCode(cleaned); - updated.current = false; - }, [hop]); + const { type: hopType, ...hopWithoutType } = hop; + const code = JSON.stringify(hopWithoutType, null, ' '); return ( - -