diff --git a/public/app/features/plugins/sql/components/DatasetSelector.tsx b/public/app/features/plugins/sql/components/DatasetSelector.tsx index 2df95568ccf..11fcac922fb 100644 --- a/public/app/features/plugins/sql/components/DatasetSelector.tsx +++ b/public/app/features/plugins/sql/components/DatasetSelector.tsx @@ -4,7 +4,7 @@ import { useAsync } from 'react-use'; import { SelectableValue } from '@grafana/data'; import { Select } from '@grafana/ui'; -import { DB, ResourceSelectorProps, toOption } from '../types'; +import { DB, ResourceSelectorProps, SQLDialect, toOption } from '../types'; import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils'; @@ -12,17 +12,11 @@ export interface DatasetSelectorProps extends ResourceSelectorProps { db: DB; dataset: string | undefined; preconfiguredDataset: string; - isPostgresInstance: boolean | undefined; + dialect: SQLDialect; onChange: (v: SelectableValue) => void; } -export const DatasetSelector = ({ - dataset, - db, - isPostgresInstance, - onChange, - preconfiguredDataset, -}: DatasetSelectorProps) => { +export const DatasetSelector = ({ dataset, db, dialect, onChange, preconfiguredDataset }: DatasetSelectorProps) => { /* The behavior of this component - for MSSQL and MySQL datasources - is based on whether the user chose to create a datasource with or without a default database (preconfiguredDataset). If the user configured a default database, this selector @@ -31,7 +25,7 @@ export const DatasetSelector = ({ */ // `hasPreconfigCondition` is true if either 1) the sql datasource has a preconfigured default database, // OR if 2) the datasource is Postgres. In either case the only option available to the user is the preconfigured database. - const hasPreconfigCondition = !!preconfiguredDataset || isPostgresInstance; + const hasPreconfigCondition = !!preconfiguredDataset || dialect === 'postgres'; const state = useAsync(async () => { if (isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) { diff --git a/public/app/features/plugins/sql/components/QueryEditor.tsx b/public/app/features/plugins/sql/components/QueryEditor.tsx index 00427b35276..25c4e4779ff 100644 --- a/public/app/features/plugins/sql/components/QueryEditor.tsx +++ b/public/app/features/plugins/sql/components/QueryEditor.tsx @@ -14,7 +14,7 @@ import { RawEditor } from './query-editor-raw/RawEditor'; import { VisualEditor } from './visual-query-builder/VisualEditor'; interface SqlQueryEditorProps extends QueryEditorProps { - queryHeaderProps?: Pick; + queryHeaderProps?: Pick; } export function SqlQueryEditor({ @@ -29,7 +29,7 @@ export function SqlQueryEditor({ const db = datasource.getDB(); const { preconfiguredDatabase } = datasource; - const isPostgresInstance = !!queryHeaderProps?.isPostgresInstance; + const dialect = queryHeaderProps?.dialect ?? 'other'; const { loading, error } = useAsync(async () => { return () => { if (datasource.getDB(datasource.id).init !== undefined) { @@ -97,7 +97,7 @@ export function SqlQueryEditor({ queryRowFilter={queryRowFilter} query={queryWithDefaults} isQueryRunnable={isQueryRunnable} - isPostgresInstance={isPostgresInstance} + dialect={dialect} /> diff --git a/public/app/features/plugins/sql/components/QueryHeader.tsx b/public/app/features/plugins/sql/components/QueryHeader.tsx index 5b7adb502fe..0450a67ebc4 100644 --- a/public/app/features/plugins/sql/components/QueryHeader.tsx +++ b/public/app/features/plugins/sql/components/QueryHeader.tsx @@ -8,7 +8,7 @@ import { reportInteraction } from '@grafana/runtime'; import { Button, InlineSwitch, RadioButtonGroup, Tooltip } from '@grafana/ui'; import { QueryWithDefaults } from '../defaults'; -import { SQLQuery, QueryFormat, QueryRowFilter, QUERY_FORMAT_OPTIONS, DB } from '../types'; +import { SQLQuery, QueryFormat, QueryRowFilter, QUERY_FORMAT_OPTIONS, DB, SQLDialect } from '../types'; import { ConfirmModal } from './ConfirmModal'; import { DatasetSelector } from './DatasetSelector'; @@ -17,7 +17,7 @@ import { TableSelector } from './TableSelector'; export interface QueryHeaderProps { db: DB; - isPostgresInstance?: boolean; + dialect: SQLDialect; isQueryRunnable: boolean; onChange: (query: SQLQuery) => void; onQueryRowChange: (queryRowFilter: QueryRowFilter) => void; @@ -34,7 +34,7 @@ const editorModes = [ export function QueryHeader({ db, - isPostgresInstance, + dialect, isQueryRunnable, onChange, onQueryRowChange, @@ -108,9 +108,12 @@ export function QueryHeader({ }; const datasetDropdownIsAvailable = () => { - // If the feature flag is DISABLED, && the datasource is Postgres (`isPostgresInstance`), + if (dialect === 'influx') { + return false; + } + // If the feature flag is DISABLED, && the datasource is Postgres (`dialect = 'postgres`), // we want to hide the dropdown - as per previous behavior. - if (!isSqlDatasourceDatabaseSelectionFeatureFlagEnabled() && isPostgresInstance) { + if (!isSqlDatasourceDatabaseSelectionFeatureFlagEnabled() && dialect === 'postgres') { return false; } @@ -290,7 +293,7 @@ export function QueryHeader({ diff --git a/public/app/features/plugins/sql/components/SqlComponents.test.tsx b/public/app/features/plugins/sql/components/SqlComponents.test.tsx index 864ac8a133e..9cfd8b59565 100644 --- a/public/app/features/plugins/sql/components/SqlComponents.test.tsx +++ b/public/app/features/plugins/sql/components/SqlComponents.test.tsx @@ -30,7 +30,7 @@ describe('DatasetSelector', () => { }); it('should not query the database if Postgres instance, and no preconfigured database', async () => { - const mockProps = buildMockDatasetSelectorProps({ isPostgresInstance: true }); + const mockProps = buildMockDatasetSelectorProps({ dialect: 'postgres' }); render(); await waitFor(() => { diff --git a/public/app/features/plugins/sql/components/SqlComponents.testHelpers.ts b/public/app/features/plugins/sql/components/SqlComponents.testHelpers.ts index 4f605bbc0fb..df20f537a2d 100644 --- a/public/app/features/plugins/sql/components/SqlComponents.testHelpers.ts +++ b/public/app/features/plugins/sql/components/SqlComponents.testHelpers.ts @@ -76,7 +76,7 @@ export function buildMockDatasetSelectorProps(overrides?: Partial = { dialect: 'postgres' }; export function PostgresQueryEditor(props: QueryEditorProps) { return ; diff --git a/public/app/plugins/datasource/influxdb/components/editor/query/fsql/FSQLEditor.tsx b/public/app/plugins/datasource/influxdb/components/editor/query/fsql/FSQLEditor.tsx index 5b33e20a8d3..568a0a7c353 100644 --- a/public/app/plugins/datasource/influxdb/components/editor/query/fsql/FSQLEditor.tsx +++ b/public/app/plugins/datasource/influxdb/components/editor/query/fsql/FSQLEditor.tsx @@ -61,6 +61,7 @@ class UnthemedSQLQueryEditor extends PureComponent { const defaultQuery = applyQueryDefaults(query); return { ...defaultQuery, + dataset: 'iox', sql: { ...defaultQuery.sql, limit: undefined, @@ -98,6 +99,7 @@ class UnthemedSQLQueryEditor extends PureComponent { query={this.transformQuery(query)} onRunQuery={onRunSQLQuery} onChange={onSQLChange} + queryHeaderProps={{ dialect: 'influx' }} />
{ - const datasets = await this.runSql(showDatabases(), { refId: 'datasets' }); - return datasets.map((t) => quoteIdentifierIfNecessary(t[0])); + return Promise.resolve(['iox']); } async fetchTables(dataset?: string): Promise {