mirror of
https://github.com/apache/superset.git
synced 2026-04-24 02:25:13 +00:00
Prettify the frontend code (#8648)
* Add Prettier global configs * Format js/jsx/ts/tsx/less files
This commit is contained in:
@@ -32,21 +32,22 @@ const SCHEMA_AUTOCOMPLETE_SCORE = 60;
|
||||
const TABLE_AUTOCOMPLETE_SCORE = 55;
|
||||
const COLUMN_AUTOCOMPLETE_SCORE = 50;
|
||||
|
||||
const keywords = (
|
||||
const keywords =
|
||||
'SELECT|INSERT|UPDATE|DELETE|FROM|WHERE|AND|OR|GROUP|BY|ORDER|LIMIT|OFFSET|HAVING|AS|CASE|' +
|
||||
'WHEN|THEN|ELSE|END|TYPE|LEFT|RIGHT|JOIN|ON|OUTER|DESC|ASC|UNION|CREATE|TABLE|PRIMARY|KEY|IF|' +
|
||||
'FOREIGN|NOT|REFERENCES|DEFAULT|NULL|INNER|CROSS|NATURAL|DATABASE|DROP|GRANT|SUM|MAX|MIN|COUNT|' +
|
||||
'AVG|DISTINCT'
|
||||
);
|
||||
'AVG|DISTINCT';
|
||||
|
||||
const dataTypes = (
|
||||
const dataTypes =
|
||||
'INT|NUMERIC|DECIMAL|DATE|VARCHAR|CHAR|BIGINT|FLOAT|DOUBLE|BIT|BINARY|TEXT|SET|TIMESTAMP|' +
|
||||
'MONEY|REAL|NUMBER|INTEGER'
|
||||
);
|
||||
'MONEY|REAL|NUMBER|INTEGER';
|
||||
|
||||
const sqlKeywords = [].concat(keywords.split('|'), dataTypes.split('|'));
|
||||
export const sqlWords = sqlKeywords.map(s => ({
|
||||
name: s, value: s, score: SQL_KEYWORD_AUTOCOMPLETE_SCORE, meta: 'sql',
|
||||
name: s,
|
||||
value: s,
|
||||
score: SQL_KEYWORD_AUTOCOMPLETE_SCORE,
|
||||
meta: 'sql',
|
||||
}));
|
||||
|
||||
const propTypes = {
|
||||
@@ -58,17 +59,19 @@ const propTypes = {
|
||||
extendedTables: PropTypes.array,
|
||||
queryEditor: PropTypes.object.isRequired,
|
||||
height: PropTypes.string,
|
||||
hotkeys: PropTypes.arrayOf(PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
descr: PropTypes.string.isRequired,
|
||||
func: PropTypes.func.isRequired,
|
||||
})),
|
||||
hotkeys: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
key: PropTypes.string.isRequired,
|
||||
descr: PropTypes.string.isRequired,
|
||||
func: PropTypes.func.isRequired,
|
||||
}),
|
||||
),
|
||||
onChange: PropTypes.func,
|
||||
};
|
||||
|
||||
const defaultProps = {
|
||||
onBlur: () => { },
|
||||
onChange: () => { },
|
||||
onBlur: () => {},
|
||||
onChange: () => {},
|
||||
schemas: [],
|
||||
tables: [],
|
||||
extendedTables: [],
|
||||
@@ -89,9 +92,14 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
this.setAutoCompleter(this.props);
|
||||
}
|
||||
UNSAFE_componentWillReceiveProps(nextProps) {
|
||||
if (!areArraysShallowEqual(this.props.tables, nextProps.tables) ||
|
||||
if (
|
||||
!areArraysShallowEqual(this.props.tables, nextProps.tables) ||
|
||||
!areArraysShallowEqual(this.props.schemas, nextProps.schemas) ||
|
||||
!areArraysShallowEqual(this.props.extendedTables, nextProps.extendedTables)) {
|
||||
!areArraysShallowEqual(
|
||||
this.props.extendedTables,
|
||||
nextProps.extendedTables,
|
||||
)
|
||||
) {
|
||||
this.setAutoCompleter(nextProps);
|
||||
}
|
||||
if (nextProps.sql !== this.props.sql) {
|
||||
@@ -112,7 +120,7 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
this.onAltEnter();
|
||||
},
|
||||
});
|
||||
this.props.hotkeys.forEach((keyConfig) => {
|
||||
this.props.hotkeys.forEach(keyConfig => {
|
||||
editor.commands.addCommand({
|
||||
name: keyConfig.name,
|
||||
bindKey: { win: keyConfig.key, mac: keyConfig.key },
|
||||
@@ -123,10 +131,15 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
editor.selection.on('changeSelection', () => {
|
||||
const selectedText = editor.getSelectedText();
|
||||
// Backspace trigger 1 character selection, ignoring
|
||||
if (selectedText !== this.state.selectedText && selectedText.length !== 1) {
|
||||
if (
|
||||
selectedText !== this.state.selectedText &&
|
||||
selectedText.length !== 1
|
||||
) {
|
||||
this.setState({ selectedText });
|
||||
this.props.actions.queryEditorSetSelectedText(
|
||||
this.props.queryEditor, selectedText);
|
||||
this.props.queryEditor,
|
||||
selectedText,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -162,12 +175,12 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
const columns = {};
|
||||
const tables = props.tables || [];
|
||||
const extendedTables = props.extendedTables || [];
|
||||
const tableWords = tables.map((t) => {
|
||||
const tableWords = tables.map(t => {
|
||||
const tableName = t.value;
|
||||
const extendedTable = extendedTables.find(et => et.name === tableName);
|
||||
const cols = extendedTable && extendedTable.columns || [];
|
||||
cols.forEach((col) => {
|
||||
columns[col.name] = null; // using an object as a unique set
|
||||
const cols = (extendedTable && extendedTable.columns) || [];
|
||||
cols.forEach(col => {
|
||||
columns[col.name] = null; // using an object as a unique set
|
||||
});
|
||||
return {
|
||||
name: t.label,
|
||||
@@ -177,11 +190,17 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
};
|
||||
});
|
||||
|
||||
const columnWords = Object.keys(columns).map(col => (
|
||||
{ name: col, value: col, score: COLUMN_AUTOCOMPLETE_SCORE, meta: 'column' }
|
||||
));
|
||||
const columnWords = Object.keys(columns).map(col => ({
|
||||
name: col,
|
||||
value: col,
|
||||
score: COLUMN_AUTOCOMPLETE_SCORE,
|
||||
meta: 'column',
|
||||
}));
|
||||
|
||||
const words = schemaWords.concat(tableWords).concat(columnWords).concat(sqlWords);
|
||||
const words = schemaWords
|
||||
.concat(tableWords)
|
||||
.concat(columnWords)
|
||||
.concat(sqlWords);
|
||||
|
||||
this.setState({ words }, () => {
|
||||
const completer = {
|
||||
@@ -194,7 +213,7 @@ class AceEditorWrapper extends React.PureComponent {
|
||||
}
|
||||
getAceAnnotations() {
|
||||
const validationResult = this.props.queryEditor.validationResult;
|
||||
const resultIsReady = (validationResult && validationResult.completed);
|
||||
const resultIsReady = validationResult && validationResult.completed;
|
||||
if (resultIsReady && validationResult.errors.length > 0) {
|
||||
const errors = validationResult.errors.map(err => ({
|
||||
type: 'error',
|
||||
|
||||
Reference in New Issue
Block a user