mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SQL Datasources: Move database setting to jsonData (#58649)
* Datasource settings: Add deprecation notice for database field * SQL Datasources: Migrate from settings.database to settings.jsonData.database * Check jsonData first * Remove comment from docs
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { DataSourceJsonData, DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
||||
import { logDebug } from '@grafana/runtime';
|
||||
|
||||
import { SQLOptions } from '../../types';
|
||||
|
||||
/**
|
||||
* Moves the database field from the options object to jsonData.database and empties the database field.
|
||||
*/
|
||||
export function useMigrateDatabaseField<T extends DataSourceJsonData = SQLOptions, S = {}>({
|
||||
onOptionsChange,
|
||||
options,
|
||||
}: DataSourcePluginOptionsEditorProps<T, S>) {
|
||||
useEffect(() => {
|
||||
if (options.database) {
|
||||
logDebug(`Migrating from options.database with value ${options.database} for ${options.name}`);
|
||||
onOptionsChange({
|
||||
...options,
|
||||
database: '',
|
||||
jsonData: { ...options.jsonData, database: options.database },
|
||||
});
|
||||
}
|
||||
}, [onOptionsChange, options]);
|
||||
}
|
||||
Reference in New Issue
Block a user