etr2460 commented on a change in pull request #12873:
URL: https://github.com/apache/superset/pull/12873#discussion_r571131999



##########
File path: superset-frontend/src/SqlLab/components/TemplateParamsEditor.jsx
##########
@@ -42,49 +42,28 @@ const StyledConfigEditor = styled(ConfigEditor)`
   }
 `;
 
-export default class TemplateParamsEditor extends React.Component {
-  constructor(props) {
-    super(props);
-    const codeText = props.code || '{}';
-    this.state = {
-      codeText,
-      parsedJSON: null,
-      isValid: true,
-    };
-    this.onChange = this.onChange.bind(this);
-  }
-
-  componentDidMount() {
-    this.onChange(this.state.codeText);
-  }
+function TemplateParamsEditor({ code, language, onChange }) {
+  const [parsedJSON, setParsedJSON] = useState();
+  const [isValid, setIsValid] = useState(true);
 
-  onChange(value) {
-    const codeText = value;
-    let isValid;
-    let parsedJSON = {};
+  useEffect(() => {
     try {
-      parsedJSON = JSON.parse(value);
-      isValid = true;
-    } catch (e) {
-      isValid = false;
+      setParsedJSON(JSON.parse(code));
+      setIsValid(true);
+    } catch {
+      setIsValid(false);
     }
-    this.setState({ parsedJSON, isValid, codeText });
-    const newValue = isValid ? codeText : '{}';
-    if (newValue !== this.props.code) {
-      this.props.onChange(newValue);
-    }
-  }
+  }, [code]);
 
-  renderDoc() {
-    return (
+  const modalBody = (
+    <div>
       <p>
-        {t('Assign a set of parameters as')}
+        Assign a set of parameters as

Review comment:
       I asked her to remove these, the translation method calls weren't being 
used properly here anyway. Translating fragments of sentences doesn't work 
because different languages put their words/phrases in different orders, so you 
can't simply concatenate a bunch of translated fragments together in the 
English order




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to