import { useCallback } from 'react'; import { SelectableValue, toOption } from '@grafana/data'; import { t } from '@grafana/i18n'; import { AccessoryButton, EditorList, InputGroup } from '@grafana/plugin-ui'; import { Select } from '@grafana/ui'; import { QueryEditorGroupByExpression } from '../../expressions'; import { SQLExpression } from '../../types'; import { setGroupByField } from '../../utils/sql.utils'; interface GroupByRowProps { sql: SQLExpression; onSqlChange: (sql: SQLExpression) => void; columns?: Array>; } export function GroupByRow({ sql, columns, onSqlChange }: GroupByRowProps) { const onGroupByChange = useCallback( (item: Array>) => { // As new (empty object) items come in, we need to make sure they have the correct type const cleaned = item.map((v) => setGroupByField(v.property?.name)); const newSql = { ...sql, groupBy: cleaned }; onSqlChange(newSql); }, [onSqlChange, sql] ); return ( ); } function makeRenderColumn({ options }: { options?: Array> }) { const renderColumn = function ( item: Partial, onChangeItem: (item: QueryEditorGroupByExpression) => void, onDeleteItem: () => void ) { return (