mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 01:42:12 +08:00

* badlm0mma/sql_datasource_update/ initial notes * baldm0mma/sql_datasource_update/ solution * baldm0mma/sql_datasource_update/ clean datasetSelector * baldm0mma/sql_datasource_update/ clean up queryEditor.tsx * baldm0mma/sql_datasource_update/ clewan up queryHeader.tsx * baldm0mma/sql_datasource_update/ clean up tableSelector.tsx * baldm0mma/sql_datasource_update/ clean up mysqlDatasource.ts * baldm0mma/sql_datasource_update/ clean up configurationEditor.tsx * baldm0mma/sql_datasource_update/ rem conlog from queryEditor.tsx * baldm0mma/sql_datasource_update/ rem conlog from queryEditor.tsx * baldm0mma/sql_datasource_update/ remove conlog in tableSelector.tsx * baldm0mma/sql_datasource_update/ rem conlog in sqlDatasource.ts * baldm0mma/sql_datasource_update/ update deafult database value in sqlDatasource.ts * baldm0mma/sql_datasource_update/ update logic to accomidate no preconfig * baldm0mma/sql_datasource_update/ update props * baldm0mma/sql_datasource_update/ update prop names * baldm0mma/sql_datasource_update/ update prop names in tableSelector * baldm0mma/sql_datasource_update/ update annos in datasetSelector * baldm0mma/sql_datasource_update/ update naming * baldm0mma/sql_datasource_update/ update to standard langauae * baldm0mma/sql_datasource_update/ update prop names * baldm0mma/sql_datasource_update/ update annos in datasetSelector * baldm0mma/sql_datasource_update/ remove unused import in tableSelector.tsx * baldm0mma/sql_datasource_update/ remove addDefaultdataset * baldm0mma/sql_datasource_update/ reset query when needed * baldm0mma/sql_datasource_update/ update asymc return val * baldm0mma/sql_datasource_update/ remove psql query editor * baldm0mma/sql_datasource_update/ remove con logs in defaults.ts * baldm0mma/sql_datasource_update/ revert postgres changes * baldm0mma/sql_datasource_update/ update postgres naming * baldm0mma/sql_datasource_update/ add altert * baldm0mma/sql_datasource_update/ update annos and add alerts and alert logic * baldm0mma/sql_datasource_update/ update postgres nomenclature * baldm0mma/sql_datasource_update/ update annos and remove con logs * baldm0mma/sql_datasource_update/ update nomenclature * baldm0mma/sql_datasource_update/ drone fix * baldm0mma/sql_datasource_update/ export and format * baldm0mma/sql_datasource_update/ update docs for mysql datasource with dataset dropdown disable info * baldm0mma/sql_datasource_update/ update mssql docs * baldm0mma/sql_datasource_update/ update postgres docs and alert logic * baldm0mma/sql_datasource_update/ add tests * baldm0mma/sql_datasource_update/ update docs * baldm0mma/sql_datasource_update/ update test names * baldm0mma/sql_datasource_update/ update alert language * baldm0mma/sql_datasource_update/ correct spelling * baldm0mma/sql_datasource_update/ update postgres query builder image * baldm0mma/sql_datasource_update/ update annos * baldm0mma/sql_datasource_update/ update tests * baldm0mma/sql_datasource_update/ docs updated * baldm0mma/sql_datsource_update/ refactor determinePlaceholder * Update public/app/features/plugins/sql/components/QueryEditor.tsx spelling Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> * Update public/app/features/plugins/sql/components/QueryEditor.tsx spelling Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> * baldm0mma/sql_datasource_update/ remove superfluous cleanup data from tests * baldm0mma/sql_datasource_update/ update spelling * Update public/app/features/plugins/sql/components/SqlComponents.test.tsx spelling Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> * baldm0mma/sql_datasource_update/ add logic to prevent db call for tables if dataset it nullish * baldm0mma/sql_datasource_update/ update alert tests * baldm0mma/sql_datasource_update/ update button text * baldm0mma/sql_datasource_update/ update tests to preferred standard * baldm0mma/sql_datasource_update/add feature flag * baldm0mma/sql_datasource_update/ update mssql docs * baldm0mma/sql_datasource_update/ add feature flag to registry * baldm0mma/sql_datasource_update/ adjust table and dataset dropdown logic * baldm0mma/sql_datasource_update/ update testing to deal with feature flag * baldm0mma/sql_datasource_update/ update wioth cascadeDisable * baldm0mma/sql_datasource_update/ update naming * baldm0mma/sql_datasource_update/ update tests to reflect enabled feature flag * baldm0mma/sql_datasource_update/ update annotations * baldm0mma/sql_datasource_update/ update annos in queryEd * baldm0mma/sql_datasource_update/ update test names * baldm0mma/sql_datasource_update/ update anno issues * baldm0mma/slq_datasource_update/ add query to sqlDatasource with error * baldm0mma/sql_datasource_update/ update docs language * baldm0mma/sql_datasource_update/ remove notes to self * baldm0mma/sql_datasource_update/ add QueryEditorFeatureFlag.utils.ts * baldm0mma/sql_datasource_update/ update database into json * baldm0mma/sql_datasource_update/ found file * Update docs/sources/datasources/mssql/query-editor/index.md Co-authored-by: lwandz13 <126723338+lwandz13@users.noreply.github.com> * baldm0mma/sql_datasource_update/ update feature flag and toggles * baldm0mma/sql_datasource_update/ add hasConfigIssue, update annos, rethink disable logic * baldm0mma/sql_datasource_update/ update warning language * baldm0mma/sql_datasource_update/ update button content * baldm0mma/sql_datasource_update/ update jsonData logic in frontendsettings.go * baldm0mma/sql_datasource_update/ update jsonData logic * baldm0mma/sql_datasource_update/ update annos in frontendsettings.go * baldm0mma/sql_datasource_update/ update sql editor docs * baldm0mma/sql_datasource_update/ update mysql docs * baldm0mma/sql_datasource_update/ update postgres docs * baldm0mma/sql_datasource_update/ remove unused code in datasetSelector.tsx * baldm0mma/sql_datasource_update/ update syntax conventions * baldm0mma/sql_datasource_update/ add logs * baldm0mma/sql_datasource_update/ remove unused code * baldm0mma/sql_datasource_update/ remove conlogs * baldm0mma/sql_datasource_update/ update tests * baldm0mma/sql_datasource_update/ add second error to query * baldm0mma/sql_datasource_update/ run make gen-cue * baldm0mma/sql_database_update/ lint registry * baldm0mma/sql_datasource_update/ update registry * baldm0mma/sql_datasource_update/ upate datasource logic * baldm0mma/sql_datasource_update/ add logs * baldm0mma/sql_datasource_update/ add comms to self * baldm0mma/sql_datasource_update/ comment out false pos tests, and add investigatory comments * baldm0mma/sql_database_update/ update query error to only test for config change if query was made in "builder" mode * baldm0mma/sql_datasource_update/ update annos in frontendsettings.go * baldm0mma/sql_datasource_update/ update error logic to datasource * baldm0mma/sql_datasource_update/ remove alerts from query editor * baldm0mma/sql_datasource_update/ remove unused imports * baldm0mma/sql_datasource_update/ update tests * baldm0mma/sql_datasource_update/ remove comments * baldm0mma/sql_datasource_update/ remove logs in queryGroup.tsx * baldm0mma/sql_datasource_update/ remove outdated annotation in datasetSelector.tsx * baldm0mma/sql_datasource_update/ remove superfluous test and update test description * baldm0mma/sql_datasource_update/ remove feature flag * baldm0mma/sql_datasource_update/ add back feature flag * baldm0mma/sql_datasource_update/ update to enums * baldm0mma/sql_datasource_update/ update panel caps * baldm0mma/sql_datasource_update/ update dataset selector to default update the database correctly * baldm0mma/sql_datasource_update/ move onChange into conditional * baldm0mma/sql_datasource_update/ add logic for previous datasets choice * baldm0mma/sql_datasource_update/ add back previous logic for assigning default datasets * baldm0mma/sql_datasource_update/ update useEffect dep array * baldm0mma/sql_datasource_update/ remove feature toggle * baldm0mma/sql_datasource_update/ add feature toggle --------- Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com> Co-authored-by: lwandz13 <126723338+lwandz13@users.noreply.github.com>
86 lines
3.1 KiB
TypeScript
86 lines
3.1 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { useAsync } from 'react-use';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Select } from '@grafana/ui';
|
|
|
|
import { DB, ResourceSelectorProps, toOption } from '../types';
|
|
|
|
import { isSqlDatasourceDatabaseSelectionFeatureFlagEnabled } from './QueryEditorFeatureFlag.utils';
|
|
|
|
export interface DatasetSelectorProps extends ResourceSelectorProps {
|
|
db: DB;
|
|
dataset: string | undefined;
|
|
preconfiguredDataset: string;
|
|
isPostgresInstance: boolean | undefined;
|
|
onChange: (v: SelectableValue) => void;
|
|
}
|
|
|
|
export const DatasetSelector = ({
|
|
dataset,
|
|
db,
|
|
isPostgresInstance,
|
|
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
|
|
should only allow that single preconfigured database option to be selected. If the user chose to NOT assign/configure a default database,
|
|
then the user should be able to use this component to choose between multiple databases available to the datasource.
|
|
*/
|
|
// `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 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 there is no preconfigured database, but there is a selected dataset, set the current database to the selected dataset.
|
|
if (dataset) {
|
|
onChange(toOption(dataset));
|
|
}
|
|
|
|
// Otherwise, fetch all databases available to the datasource.
|
|
const datasets = await db.datasets();
|
|
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="Dataset selector"
|
|
value={dataset}
|
|
options={state.value}
|
|
onChange={onChange}
|
|
disabled={state.loading}
|
|
isLoading={state.loading}
|
|
menuShouldPortal={true}
|
|
/>
|
|
);
|
|
};
|