eschutho commented on a change in pull request #12873:
URL: https://github.com/apache/superset/pull/12873#discussion_r571119173
##########
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:
we're going to want to put the `{t('` method calls back, too. Those are
used for translations. :)
----------------------------------------------------------------
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]