import React, { useState } from 'react'; import 'codemirror/theme/base16-light.css'; // import { getSuggestionKeys } from '../CodeBuilder/utils'; import 'codemirror/mode/javascript/javascript'; import 'codemirror/addon/hint/show-hint'; import 'codemirror/addon/search/match-highlighter'; import 'codemirror/addon/hint/show-hint.css'; import { CodeHinter } from '../CodeBuilder/CodeHinter'; export const Transformation = ({ changeOption, currentState, options, darkMode }) => { const defaultValue = options.transformation || `// write your code here // return value will be set as data and the original data will be available as rawData return data.filter(row => row.amount > 1000);`; const [value, setValue] = useState(defaultValue); const [enableTransformation, setEnableTransformation] = useState(() => options.enableTransformation); // let suggestions = useMemo(() => getSuggestionKeys(currentState), [currentState.components, currentState.queries]); function codeChanged(value) { setValue(() => value); changeOption('transformation', value); } function toggleEnableTransformation() { setEnableTransformation((prev) => !prev); changeOption('enableTransformation', !enableTransformation); } return (
{!enableTransformation && (
Transformations can be used to transform the results of queries. All the app variables are accessible from transformers and supports JS libraries such as Lodash & Moment.{' '} Read documentation .
)}

{enableTransformation && (
codeChanged(value)} />
)}
); };