mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
- Migrate Postgres query editor to react - Add support for field aliasing in SELECT clauses to SQL based datasources Co-authored-by: Kyle Cunningham <kyle@codeincarnate.com> Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
37 lines
948 B
TypeScript
37 lines
948 B
TypeScript
import React from 'react';
|
|
import { useAsync } from 'react-use';
|
|
|
|
import { SelectableValue, toOption } from '@grafana/data';
|
|
|
|
import { QueryWithDefaults } from '../../defaults';
|
|
import { DB, SQLQuery } from '../../types';
|
|
import { useSqlChange } from '../../utils/useSqlChange';
|
|
|
|
import { SelectRow } from './SelectRow';
|
|
|
|
interface SQLSelectRowProps {
|
|
fields: SelectableValue[];
|
|
query: QueryWithDefaults;
|
|
onQueryChange: (query: SQLQuery) => void;
|
|
db: DB;
|
|
}
|
|
|
|
export function SQLSelectRow({ fields, query, onQueryChange, db }: SQLSelectRowProps) {
|
|
const { onSqlChange } = useSqlChange({ query, onQueryChange, db });
|
|
|
|
const state = useAsync(async () => {
|
|
const functions = await db.functions();
|
|
return functions.map((f) => toOption(f.name));
|
|
}, [db]);
|
|
|
|
return (
|
|
<SelectRow
|
|
columns={fields}
|
|
sql={query.sql!}
|
|
format={query.format}
|
|
functions={state.value}
|
|
onSqlChange={onSqlChange}
|
|
/>
|
|
);
|
|
}
|