2
0

feat(editor): Code step

This commit is contained in:
Baptiste Arnaud
2022-03-07 17:39:57 +01:00
parent b2784f19fd
commit e3e07ddd4d
13 changed files with 239 additions and 16 deletions

View File

@ -27,6 +27,7 @@ import {
DateInputSettingsBody,
} from './bodies'
import { ChoiceInputSettingsBody } from './bodies/ChoiceInputSettingsBody'
import { CodeSettings } from './bodies/CodeSettings'
import { ConditionSettingsBody } from './bodies/ConditionSettingsBody'
import { GoogleAnalyticsSettings } from './bodies/GoogleAnalyticsSettings'
import { GoogleSheetsSettingsBody } from './bodies/GoogleSheetsSettingsBody'
@ -177,6 +178,14 @@ export const StepSettings = ({
/>
)
}
case LogicStepType.CODE: {
return (
<CodeSettings
options={step.options}
onOptionsChange={handleOptionsChange}
/>
)
}
case IntegrationStepType.GOOGLE_SHEETS: {
return (
<GoogleSheetsSettingsBody

View File

@ -0,0 +1,39 @@
import { FormLabel, Stack, Text } from '@chakra-ui/react'
import { CodeEditor } from 'components/shared/CodeEditor'
import { DebouncedInput } from 'components/shared/DebouncedInput'
import { CodeOptions } from 'models'
import React from 'react'
type Props = {
options: CodeOptions
onOptionsChange: (options: CodeOptions) => void
}
export const CodeSettings = ({ options, onOptionsChange }: Props) => {
const handleNameChange = (name: string) =>
onOptionsChange({ ...options, name })
const handleCodeChange = (content: string) =>
onOptionsChange({ ...options, content })
return (
<Stack spacing={4}>
<Stack>
<FormLabel mb="0" htmlFor="name">
Name:
</FormLabel>
<DebouncedInput
id="name"
initialValue={options.name}
onChange={handleNameChange}
/>
</Stack>
<Stack>
<Text>Code:</Text>
<CodeEditor
value={options.content ?? ''}
lang="js"
onChange={handleCodeChange}
/>
</Stack>
</Stack>
)
}

View File

@ -78,6 +78,16 @@ export const StepNodeContent = ({ step, indices }: Props) => {
/>
)
}
case LogicStepType.CODE: {
return (
<ConfigureContent
label={
step.options?.content ? `Run ${step.options?.name}` : undefined
}
/>
)
}
case IntegrationStepType.GOOGLE_SHEETS: {
return (
<ConfigureContent