Remove sqlDatasourceDatabaseSelection feature toggle (#109391)
* Remove `sqlDatasourceDatabaseSelection` feature toggle * Update e2e tests
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useAsync } from 'react-use';
|
||||
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
@@ -7,8 +6,6 @@ import { Select } from '@grafana/ui';
|
||||
|
||||
import { DB, ResourceSelectorProps, SQLDialect, toOption } from '../types';
|
||||
|
||||
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils';
|
||||
|
||||
export interface DatasetSelectorProps extends ResourceSelectorProps {
|
||||
db: DB;
|
||||
dataset: string | undefined;
|
||||
@@ -37,13 +34,11 @@ export const DatasetSelector = ({
|
||||
const hasPreconfigCondition = !!preconfiguredDataset || dialect === 'postgres';
|
||||
|
||||
const state = useAsync(async () => {
|
||||
if (isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) {
|
||||
// If a default database is already configured for a MSSQL or MySQL data source, OR the data source is Postgres, no need to fetch other databases.
|
||||
if (hasPreconfigCondition) {
|
||||
// Set the current database to the preconfigured database.
|
||||
onChange(toOption(preconfiguredDataset));
|
||||
return [toOption(preconfiguredDataset)];
|
||||
}
|
||||
// If a default database is already configured for a MSSQL or MySQL data source, OR the data source is Postgres, no need to fetch other databases.
|
||||
if (hasPreconfigCondition) {
|
||||
// Set the current database to the preconfigured database.
|
||||
onChange(toOption(preconfiguredDataset));
|
||||
return [toOption(preconfiguredDataset)];
|
||||
}
|
||||
|
||||
// If there is no preconfigured database, but there is a selected dataset, set the current database to the selected dataset.
|
||||
@@ -56,24 +51,6 @@ export const DatasetSelector = ({
|
||||
return datasets.map(toOption);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSqlDatasourceDatabaseSelectionFeatureFlagEnabled()) {
|
||||
// Set default dataset when values are fetched
|
||||
if (!dataset) {
|
||||
if (state.value && state.value[0]) {
|
||||
onChange(state.value[0]);
|
||||
}
|
||||
} else {
|
||||
if (state.value && state.value.find((v) => v.value === dataset) === undefined) {
|
||||
// if value is set and newly fetched values does not contain selected value
|
||||
if (state.value.length > 0) {
|
||||
onChange(state.value[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [state.value, onChange, dataset]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
aria-label={t('grafana-sql.components.dataset-selector.aria-label-dataset-selector', 'Dataset selector')}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
export const isSqlDatasourceDatabaseSelectionFeatureFlagEnabled = () => {
|
||||
return !!config.featureToggles.sqlDatasourceDatabaseSelection;
|
||||
};
|
||||
@@ -13,7 +13,6 @@ import { SQLQuery, QueryFormat, QueryRowFilter, QUERY_FORMAT_OPTIONS, DB, SQLDia
|
||||
|
||||
import { ConfirmModal } from './ConfirmModal';
|
||||
import { DatasetSelector } from './DatasetSelector';
|
||||
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils';
|
||||
import { TableSelector } from './TableSelector';
|
||||
|
||||
export interface QueryHeaderProps {
|
||||
@@ -117,11 +116,6 @@ export function QueryHeader({
|
||||
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() && dialect === 'postgres') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import { SQLExpression } from '../types';
|
||||
import { makeVariable } from '../utils/testHelpers';
|
||||
|
||||
@@ -10,14 +8,6 @@ import { buildMockDatasetSelectorProps, buildMockTableSelectorProps } from './Sq
|
||||
import { TableSelector } from './TableSelector';
|
||||
import { removeQuotesForMultiVariables } from './visual-query-builder/SQLWhereRow';
|
||||
|
||||
beforeEach(() => {
|
||||
config.featureToggles.sqlDatasourceDatabaseSelection = true;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
config.featureToggles.sqlDatasourceDatabaseSelection = false;
|
||||
});
|
||||
|
||||
describe('DatasetSelector', () => {
|
||||
it('should only query the database when needed', async () => {
|
||||
const mockProps = buildMockDatasetSelectorProps();
|
||||
|
||||
Reference in New Issue
Block a user