Skip to content

Commit

Permalink
refactor: remove intermediate component
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Apr 11, 2023
1 parent 407e689 commit 3b20f98
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/components/Services/ServiceVariables/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@ import VisualEditor from './VisualEditor'
import Toolbar from './Toolbar'
import { FormValues } from '../types'

//TODO: use a spread operator to pass props to the editor
const EditorUncontrolled = ({
isRawEditorMode,
value,
onChange,
}: {
isRawEditorMode: boolean
value: Object
onChange: (newVariables: Object) => void
}) => {
return isRawEditorMode ? (
<RawEditor variables={value} onChange={onChange} />
) : (
<VisualEditor variables={value} onChange={onChange} />
)
}

const EditorControlled = ({
control,
defaultValues,
Expand All @@ -37,13 +20,13 @@ const EditorControlled = ({
name="variables"
control={control}
defaultValue={defaultValues}
render={({ field: { value, onChange } }) => (
<EditorUncontrolled
value={value}
onChange={onChange}
isRawEditorMode={isRawEditorMode}
/>
)}
render={({ field: { value, onChange } }) =>
isRawEditorMode ? (
<RawEditor variables={value} onChange={onChange} />
) : (
<VisualEditor variables={value} onChange={onChange} />
)
}
/>
)
}
Expand Down

0 comments on commit 3b20f98

Please sign in to comment.