mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
* DynamicComponent for QuerySourceAlerts * General Settings updates * Dynamic Date[Range] updates * EmptyState updates * Query and SchemaBrowser updates * Adjust page headers and add disablePublish * Policy updates * Separate Home FavoritesList component * Update FormatQuery * Autolimit frontend fixes * Misc updates * Keep registering of QuerySourceDropdown * Undo changes in DynamicComponent * Change sql-formatter package.json syntax * Allow opening help trigger in new tab * Don't run npm commands as root in Dockerfile * Cypress: Remove extra execute query
24 lines
640 B
TypeScript
24 lines
640 B
TypeScript
import { trim } from "lodash";
|
|
import sqlFormatter from "sql-formatter";
|
|
|
|
interface QueryFormatterMap {
|
|
[syntax: string]: (queryText: string) => string;
|
|
}
|
|
|
|
const QueryFormatters: QueryFormatterMap = {
|
|
sql: queryText => sqlFormatter.format(trim(queryText)),
|
|
json: queryText => JSON.stringify(JSON.parse(queryText), null, 4),
|
|
};
|
|
|
|
export function isFormatQueryAvailable(syntax: string) {
|
|
return syntax in QueryFormatters;
|
|
}
|
|
|
|
export function formatQuery(queryText: string, syntax: string) {
|
|
if (!isFormatQueryAvailable(syntax)) {
|
|
return queryText;
|
|
}
|
|
const formatter = QueryFormatters[syntax];
|
|
return formatter(queryText);
|
|
}
|