Files
redash/client/app/components/keywordBuilder.js
Arik Fraimovich 56d3be2248 Prettier all the Javascript code & GitHub Action (#4433)
* Prettier all the JS files

* Add GitHub Action to autoformat code pushed to master

* Fix eslint violation due to formatting.

* Remove GitHub actions for styling

* Add restyled.io config
2019-12-11 17:05:38 +02:00

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,
};