-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using the monaco editor as the code editor
- Loading branch information
Showing
2 changed files
with
21 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 10 additions & 7 deletions
17
enclave-manager/web/src/components/enclaves/configuration/inputs/JSONArgumentInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import { Textarea } from "@chakra-ui/react"; | ||
import { Controller } from "react-hook-form"; | ||
import { stringifyError } from "../../../../utils"; | ||
import { CodeEditor } from "../../../CodeEditor"; | ||
import { useEnclaveConfigurationFormContext } from "../EnclaveConfigurationForm"; | ||
import { KurtosisArgumentTypeInputProps } from "./KurtosisArgumentTypeInput"; | ||
|
||
export const JSONArgumentInput = (props: Omit<KurtosisArgumentTypeInputProps, "type">) => { | ||
const { register } = useEnclaveConfigurationFormContext(); | ||
const { control } = useEnclaveConfigurationFormContext(); | ||
|
||
return ( | ||
<Textarea | ||
{...register(props.name, { | ||
disabled: props.disabled, | ||
<Controller | ||
render={({ field }) => <CodeEditor text={field.value} onTextChange={field.onChange} />} | ||
name={props.name} | ||
defaultValue={"{}"} | ||
rules={{ | ||
required: props.isRequired, | ||
value: "{}", | ||
validate: (value: string) => { | ||
try { | ||
JSON.parse(value); | ||
} catch (err: any) { | ||
return `This is not valid JSON. ${stringifyError(err)}`; | ||
} | ||
}, | ||
})} | ||
}} | ||
disabled={props.disabled} | ||
/> | ||
); | ||
}; |