* feat: add selected columns support to GROUP BY dropdown * feat(vqb): allow selecting columns in GROUP BY dropdown #106349
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
||||
import { SQLQuery } from '../types';
|
||||
|
||||
export function getColumnsWithIndices(query: SQLQuery, fields: SelectableValue[]): SelectableValue[] {
|
||||
if (!fields || !query.sql?.columns) {
|
||||
return fields;
|
||||
}
|
||||
|
||||
const options = query.sql.columns.map((c, i) => {
|
||||
const value = c.name
|
||||
? `${c.name}(${c.parameters?.map((p) => p.name).join(', ')})`
|
||||
: c.parameters?.map((p) => p.name).join(', ');
|
||||
return {
|
||||
value,
|
||||
label: `${i + 1} - ${value}`,
|
||||
};
|
||||
});
|
||||
|
||||
return [
|
||||
{
|
||||
value: '',
|
||||
label: 'Selected columns',
|
||||
options,
|
||||
expanded: true,
|
||||
},
|
||||
...fields,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user