mirror of
https://github.com/getredash/redash.git
synced 2026-05-10 15:00:16 -04:00
* Add dot behavior to autocomplete * Transform the Keyword Builder in an external js * Remove methods from QueryEditor constructor
51 lines
1.0 KiB
JavaScript
51 lines
1.0 KiB
JavaScript
import { map } from 'lodash';
|
|
|
|
function buildTableColumnKeywords(table) {
|
|
const keywords = [];
|
|
table.columns.forEach((column) => {
|
|
keywords.push({
|
|
caption: column,
|
|
name: `${table.name}.${column}`,
|
|
value: `${table.name}.${column}`,
|
|
score: 100,
|
|
meta: 'Column',
|
|
className: 'completion',
|
|
});
|
|
});
|
|
return keywords;
|
|
}
|
|
|
|
function buildKeywordsFromSchema(schema) {
|
|
const tableKeywords = [];
|
|
const columnKeywords = {};
|
|
const tableColumnKeywords = {};
|
|
|
|
schema.forEach((table) => {
|
|
tableKeywords.push({
|
|
name: table.name,
|
|
value: table.name,
|
|
score: 100,
|
|
meta: 'Table',
|
|
});
|
|
tableColumnKeywords[table.name] = buildTableColumnKeywords(table);
|
|
table.columns.forEach((c) => {
|
|
columnKeywords[c] = 'Column';
|
|
});
|
|
});
|
|
|
|
return {
|
|
table: tableKeywords,
|
|
column: map(columnKeywords, (v, k) => ({
|
|
name: k,
|
|
value: k,
|
|
score: 50,
|
|
meta: v,
|
|
})),
|
|
tableColumn: tableColumnKeywords,
|
|
};
|
|
}
|
|
|
|
export default {
|
|
buildKeywordsFromSchema,
|
|
};
|