AAfghahi commented on a change in pull request #13032:
URL: https://github.com/apache/superset/pull/13032#discussion_r575497407



##########
File path: superset-frontend/src/SqlLab/components/HighlightedSql.tsx
##########
@@ -27,93 +26,92 @@ import ModalTrigger from '../../components/ModalTrigger';
 
 SyntaxHighlighter.registerLanguage('sql', sql);
 
-const defaultProps = {
-  maxWidth: 50,
-  maxLines: 5,
-  shrink: false,
-};
+interface propTypes {
+  sql: string;
+  rawSql?: string;
+  maxWidth?: number;
+  maxLines?: number;
+  shrink?: any;
+}
 
-const propTypes = {
-  sql: PropTypes.string.isRequired,
-  rawSql: PropTypes.string,
-  maxWidth: PropTypes.number,
-  maxLines: PropTypes.number,
-  shrink: PropTypes.bool,
-};
+interface modalTypes {
+  rawSql?: string;
+  sql: string;
+}
 
-class HighlightedSql extends React.Component {
-  constructor(props) {
-    super(props);
-    this.state = {
-      modalBody: null,
-    };
-  }
+interface nodeTypes {
+  shrink: boolean;
+  sql: string;
+  maxLines: number;
+  maxWidth: number;
+}
 
-  shrinkSql() {
-    const ssql = this.props.sql || '';
+function TriggerNode({ shrink, sql, maxLines, maxWidth }: nodeTypes) {
+  const shrinkSql = () => {
+    const ssql = sql || '';
     let lines = ssql.split('\n');
-    if (lines.length >= this.props.maxLines) {
-      lines = lines.slice(0, this.props.maxLines);
+    if (lines.length >= maxLines) {
+      lines = lines.slice(0, maxLines);
       lines.push('{...}');
     }
     return lines
       .map(line => {
-        if (line.length > this.props.maxWidth) {
-          return `${line.slice(0, this.props.maxWidth)}{...}`;
+        if (line.length > maxWidth) {
+          return `${line.slice(0, maxWidth)}{...}`;
         }
         return line;
       })
       .join('\n');
-  }
+  };
 
-  triggerNode() {
-    const shownSql = this.props.shrink
-      ? this.shrinkSql(this.props.sql)
-      : this.props.sql;
-    return (
+  return (
+    <SyntaxHighlighter language="sql" style={github}>
+      {shrink ? shrinkSql() : sql}
+    </SyntaxHighlighter>
+  );
+}
+
+function HighlightSqlModal({ rawSql, sql }: modalTypes) {
+  return (
+    <div>
+      <h4>{t('Source SQL')}</h4>
       <SyntaxHighlighter language="sql" style={github}>
-        {shownSql}
+        {sql}
       </SyntaxHighlighter>
-    );
-  }
-
-  generateModal() {
-    let rawSql;
-    if (this.props.rawSql && this.props.rawSql !== this.props.sql) {
-      rawSql = (
+      {rawSql && rawSql !== sql && (
         <div>
           <h4>{t('Raw SQL')}</h4>
           <SyntaxHighlighter language="sql" style={github}>
-            {this.props.rawSql}
+            {rawSql}
           </SyntaxHighlighter>
         </div>
-      );
-    }
-    this.setState({
-      modalBody: (
-        <div>
-          <h4>{t('Source SQL')}</h4>
-          <SyntaxHighlighter language="sql" style={github}>
-            {this.props.sql}
-          </SyntaxHighlighter>
-          {rawSql}
-        </div>
-      ),
-    });
-  }
+      )}
+    </div>
+  );
+}
 
-  render() {
-    return (
-      <ModalTrigger
-        modalTitle={t('SQL')}
-        triggerNode={this.triggerNode()}
-        modalBody={this.state.modalBody}
-        beforeOpen={this.generateModal.bind(this)}
-      />
-    );
-  }
+function HighlightedSql({
+  sql,
+  rawSql,
+  maxWidth = 50,
+  maxLines = 5,
+  shrink = false,
+}: propTypes) {
+  return (
+    <ModalTrigger
+      modalTitle={t('SQL')}
+      modalBody={<HighlightSqlModal rawSql={rawSql} sql={sql} />}
+      triggerNode={
+        <TriggerNode
+          shrink={shrink}
+          sql={sql}
+          maxLines={maxLines}
+          maxWidth={maxWidth}
+        />
+      }
+    />
+  );
 }
-HighlightedSql.propTypes = propTypes;
-HighlightedSql.defaultProps = defaultProps;
+// HighlightedSql.propTypes = propTypes;

Review comment:
       Yeah, it seemed important so I didn't want to remove it right away. But 
this confirms that I should. 




----------------------------------------------------------------
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