diff --git a/CHANGELOG.md b/CHANGELOG.md index bd074a48..947e7f5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.11.0 + +Feature - Time series: Hide fields, use group by in select, use time field in group by + +## 0.10.0 + +Feature - Ad-Hoc sourced by database or table + ## 0.9.13 Fix - update sdk to show streaming errors diff --git a/package.json b/package.json index e6ed45d9..64851acc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clickhouse-datasource", - "version": "0.10.0", + "version": "0.11.0", "description": "Clickhouse Datasource", "scripts": { "build": "grafana-toolkit plugin:build", diff --git a/src/components/queryBuilder/DatabaseSelect.tsx b/src/components/queryBuilder/DatabaseSelect.tsx index 462e168c..c3963a32 100644 --- a/src/components/queryBuilder/DatabaseSelect.tsx +++ b/src/components/queryBuilder/DatabaseSelect.tsx @@ -29,7 +29,7 @@ export const DatabaseSelect = (props: Props) => { onChange={(e) => onChange(e.value!)} options={list} value={props.value} - menuPlacement={'auto'} + menuPlacement={'bottom'} > ); diff --git a/src/components/queryBuilder/Fields.tsx b/src/components/queryBuilder/Fields.tsx index 1ca83fd4..d6769a81 100644 --- a/src/components/queryBuilder/Fields.tsx +++ b/src/components/queryBuilder/Fields.tsx @@ -67,6 +67,7 @@ export const FieldsEditor = (props: FieldsEditorProps) => { onChange={onChange} onBlur={onUpdateField} allowCustomValue={true} + menuPlacement={'bottom'} /> diff --git a/src/components/queryBuilder/Filters.tsx b/src/components/queryBuilder/Filters.tsx index f9ec1080..befa419f 100644 --- a/src/components/queryBuilder/Filters.tsx +++ b/src/components/queryBuilder/Filters.tsx @@ -293,6 +293,7 @@ export const FilterEditor = (props: { onOpenMenu={() => setIsOpen(true)} onCloseMenu={() => setIsOpen(false)} onChange={(e) => onFilterNameChange(e.value!)} + menuPlacement={'bottom'} /> value={orderByItem.dir} @@ -52,6 +53,7 @@ const OrderByItem = (props: { width={12} options={sortOptions} onChange={(e) => onOrderBySortDirectionUpdate(e.value!)} + menuPlacement={'bottom'} /> ); diff --git a/src/components/queryBuilder/QueryBuilder.tsx b/src/components/queryBuilder/QueryBuilder.tsx index c36bfbd4..778cf0ed 100644 --- a/src/components/queryBuilder/QueryBuilder.tsx +++ b/src/components/queryBuilder/QueryBuilder.tsx @@ -166,7 +166,10 @@ export const QueryBuilder = (props: QueryBuilderProps) => { fieldsList={fieldsList} /> )} - + {builder.mode !== BuilderMode.Trend && ( + + )} + {(builder.mode === BuilderMode.Aggregate || builder.mode === BuilderMode.Trend) && ( )} diff --git a/src/components/queryBuilder/TableSelect.tsx b/src/components/queryBuilder/TableSelect.tsx index 4ef6ed9a..8129be21 100644 --- a/src/components/queryBuilder/TableSelect.tsx +++ b/src/components/queryBuilder/TableSelect.tsx @@ -41,7 +41,7 @@ export const TableSelect = (props: Props) => { onChange={(e) => onChange(e.value!)} options={list} value={table} - menuPlacement={'auto'} + menuPlacement={'bottom'} > ); diff --git a/src/components/queryBuilder/TimeField.tsx b/src/components/queryBuilder/TimeField.tsx index e973d6c9..155ead63 100644 --- a/src/components/queryBuilder/TimeField.tsx +++ b/src/components/queryBuilder/TimeField.tsx @@ -30,6 +30,7 @@ export const TimeFieldEditor = (props: TimeFieldEditorProps) => { width={20} onChange={(e) => props.onTimeFieldChange(e.value, getColumnType(e.value))} value={props.timeField} + menuPlacement={'bottom'} /> ); diff --git a/src/components/queryBuilder/utils.ts b/src/components/queryBuilder/utils.ts index 042748ed..3c68d12a 100644 --- a/src/components/queryBuilder/utils.ts +++ b/src/components/queryBuilder/utils.ts @@ -87,8 +87,8 @@ const getAggregationQuery = ( const getTrendByQuery = ( database = '', table = '', - fields: string[] = [], metrics: BuilderMetricField[] = [], + groupBy: string[] = [], timeField = '', timeFieldType = '' ): string => { @@ -101,12 +101,12 @@ const getTrendByQuery = ( }) .join(', '); if (metricsQuery !== '') { - const selected = fields.length > 0 ? `${fields.join(', ')},` : ''; - metricsQuery = `${timeField}, ${selected}${metricsQuery}`; + const group = groupBy.length > 0 ? `${groupBy.join(', ')},` : ''; + metricsQuery = `${timeField}, ${group} ${metricsQuery}`; + } else if (groupBy.length > 0) { + metricsQuery = `${timeField}, ${groupBy.join(', ')}`; } else { - const selected = fields.length > 0 ? `${fields.join(', ')}` : ''; - const sep = selected !== '' ? ',' : ''; - metricsQuery = `${timeField}${sep}${selected}`; + metricsQuery = `${timeField}`; } const sep = database === '' || table === '' ? '' : '.'; @@ -183,8 +183,15 @@ const getFilters = (filters: Filter[]): string => { }, ''); }; -const getGroupBy = (groupBy: string[] = []): string => { - return groupBy.length > 0 ? ` GROUP BY ` + groupBy.map((g) => g).join(', ') : ''; +const getGroupBy = (groupBy: string[] = [], timeField?: string): string => { + const clause = groupBy.length > 0 ? ` GROUP BY ${groupBy.join(', ')}` : ''; + if (timeField === undefined) { + return clause; + } + if (groupBy.length === 0) { + return ` GROUP BY ${timeField}`; + } + return `${clause}, ${timeField}`; }; const getOrderBy = (orderBy?: OrderBy[]): string => { @@ -219,8 +226,8 @@ export const getSQLFromQueryOptions = (options: SqlBuilderOptions): string => { query += getTrendByQuery( options.database, options.table, - options.fields, options.metrics, + options.groupBy, options.timeField, options.timeFieldType ); @@ -231,7 +238,7 @@ export const getSQLFromQueryOptions = (options: SqlBuilderOptions): string => { } const trendFilters = getFilters(options.filters || []); query += trendFilters ? ` AND ${trendFilters}` : ''; - query += getGroupBy(options.groupBy); + query += getGroupBy(options.groupBy, options.timeField); break; case BuilderMode.List: default: diff --git a/src/views/CHQueryEditor.tsx b/src/views/CHQueryEditor.tsx index 2d2045e3..4fb5b30f 100644 --- a/src/views/CHQueryEditor.tsx +++ b/src/views/CHQueryEditor.tsx @@ -64,8 +64,8 @@ export const CHQueryEditor = (props: CHQueryEditorProps) => { if (format !== query.format) { onChange({ ...query, format }); } - onRunQuery(); } + onRunQuery(); }; return (