mirror of
https://github.com/apache/superset.git
synced 2026-04-20 16:44:46 +00:00
Adding a ShrinkSql component (#1058)
This commit is contained in:
committed by
GitHub
parent
544b3f350f
commit
62c71110df
38
caravel/assets/javascripts/SqlLab/components/SqlShrink.jsx
Normal file
38
caravel/assets/javascripts/SqlLab/components/SqlShrink.jsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||
import { github } from 'react-syntax-highlighter/dist/styles';
|
||||
|
||||
const SqlShrink = (props) => {
|
||||
let lines = props.sql.split('\n');
|
||||
if (lines.length >= props.maxLines) {
|
||||
lines = lines.slice(0, props.maxLines);
|
||||
lines.push('{...}');
|
||||
}
|
||||
const shrunk = lines.map((line) => {
|
||||
if (line.length > props.maxWidth) {
|
||||
return line.slice(0, props.maxWidth) + '{...}';
|
||||
}
|
||||
return line;
|
||||
})
|
||||
.join('\n');
|
||||
return (
|
||||
<div>
|
||||
<SyntaxHighlighter language="sql" style={github}>
|
||||
{shrunk}
|
||||
</SyntaxHighlighter>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
SqlShrink.defaultProps = {
|
||||
maxWidth: 60,
|
||||
maxLines: 6,
|
||||
};
|
||||
|
||||
SqlShrink.propTypes = {
|
||||
sql: React.PropTypes.string,
|
||||
maxWidth: React.PropTypes.integer,
|
||||
maxLines: React.PropTypes.integer,
|
||||
};
|
||||
|
||||
export default SqlShrink;
|
||||
Reference in New Issue
Block a user