Skip to content

Commit

Permalink
Get back to using formatCode
Browse files Browse the repository at this point in the history
The custom pretty-printer is there to avoid printing `[]` when no data
is available, which is not very user-friendly.
  • Loading branch information
nkaretnikov committed Jan 8, 2024
1 parent 5ed3a6e commit 1dcd462
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ export const SpecificationCreate = ({ onCreateEnvironment }: any) => {
setShow(value);
};

const formatCode = (
channels: string[],
dependencies: string[],
variables: Record<string, string>
) => {
if (
channels.length === 0 &&
dependencies.length === 0 &&
Object.keys(variables).length === 0
) {
return "channels:\n -\ndependencies:\n -\nvariables: {}";
}
return stringify({ channels, dependencies, variables });
};

const handleSubmit = () => {
const code = show
? editorContent
Expand All @@ -104,7 +119,7 @@ export const SpecificationCreate = ({ onCreateEnvironment }: any) => {
<Box>
{show ? (
<CodeEditor
code={stringify(channels, requestedPackages, variables)}
code={formatCode(channels, requestedPackages, variables)}
onChangeEditor={onUpdateEditor}
/>
) : (
Expand Down

0 comments on commit 1dcd462

Please sign in to comment.