mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
This commit is contained in:
@@ -5,7 +5,7 @@ import { DataSourceSettings, DataSourcePlugin, DataSourceConstructor } from '@gr
|
||||
import { NavModel } from '@grafana/data';
|
||||
import { getMockDataSource } from '../__mocks__/dataSourcesMocks';
|
||||
import { getMockPlugin } from '../../plugins/__mocks__/pluginMocks';
|
||||
import { setDataSourceName, setIsDefault } from '../state/actions';
|
||||
import { setDataSourceName, setIsDefault, dataSourceLoaded } from '../state/actions';
|
||||
|
||||
const pluginMock = new DataSourcePlugin({} as DataSourceConstructor<any>);
|
||||
|
||||
@@ -26,6 +26,7 @@ const setup = (propOverrides?: object) => {
|
||||
setDataSourceName,
|
||||
updateDataSource: jest.fn(),
|
||||
setIsDefault,
|
||||
dataSourceLoaded,
|
||||
query: {},
|
||||
...propOverrides,
|
||||
};
|
||||
|
||||
@@ -17,7 +17,14 @@ import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
|
||||
// Actions & selectors
|
||||
import { getDataSource, getDataSourceMeta } from '../state/selectors';
|
||||
import { deleteDataSource, loadDataSource, setDataSourceName, setIsDefault, updateDataSource } from '../state/actions';
|
||||
import {
|
||||
deleteDataSource,
|
||||
loadDataSource,
|
||||
setDataSourceName,
|
||||
setIsDefault,
|
||||
updateDataSource,
|
||||
dataSourceLoaded,
|
||||
} from '../state/actions';
|
||||
import { getNavModel } from 'app/core/selectors/navModel';
|
||||
import { getRouteParamsId } from 'app/core/selectors/location';
|
||||
|
||||
@@ -40,13 +47,13 @@ export interface Props {
|
||||
setDataSourceName: typeof setDataSourceName;
|
||||
updateDataSource: typeof updateDataSource;
|
||||
setIsDefault: typeof setIsDefault;
|
||||
dataSourceLoaded: typeof dataSourceLoaded;
|
||||
plugin?: GenericDataSourcePlugin;
|
||||
query: UrlQueryMap;
|
||||
page?: string;
|
||||
}
|
||||
|
||||
interface State {
|
||||
dataSource: DataSourceSettings;
|
||||
plugin?: GenericDataSourcePlugin;
|
||||
isTesting?: boolean;
|
||||
testingMessage?: string;
|
||||
@@ -59,7 +66,6 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
dataSource: props.dataSource,
|
||||
plugin: props.plugin,
|
||||
};
|
||||
}
|
||||
@@ -93,18 +99,10 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: Props) {
|
||||
const { dataSource } = this.props;
|
||||
|
||||
if (prevProps.dataSource !== dataSource) {
|
||||
this.setState({ dataSource });
|
||||
}
|
||||
}
|
||||
|
||||
onSubmit = async (evt: React.FormEvent<HTMLFormElement>) => {
|
||||
evt.preventDefault();
|
||||
|
||||
await this.props.updateDataSource({ ...this.state.dataSource });
|
||||
await this.props.updateDataSource({ ...this.props.dataSource });
|
||||
|
||||
this.testDataSource();
|
||||
};
|
||||
@@ -132,7 +130,7 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
};
|
||||
|
||||
onModelChange = (dataSource: DataSourceSettings) => {
|
||||
this.setState({ dataSource });
|
||||
this.props.dataSourceLoaded(dataSource);
|
||||
};
|
||||
|
||||
isReadOnly() {
|
||||
@@ -149,7 +147,7 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
async testDataSource() {
|
||||
const dsApi = await getDatasourceSrv().get(this.state.dataSource.name);
|
||||
const dsApi = await getDatasourceSrv().get(this.props.dataSource.name);
|
||||
|
||||
if (!dsApi.testDatasource) {
|
||||
return;
|
||||
@@ -185,7 +183,7 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
get hasDataSource() {
|
||||
return this.state.dataSource.id > 0;
|
||||
return this.props.dataSource.id > 0;
|
||||
}
|
||||
|
||||
renderLoadError(loadError: any) {
|
||||
@@ -245,8 +243,8 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
renderSettings() {
|
||||
const { dataSourceMeta, setDataSourceName, setIsDefault } = this.props;
|
||||
const { testingMessage, testingStatus, dataSource, plugin } = this.state;
|
||||
const { dataSourceMeta, setDataSourceName, setIsDefault, dataSource } = this.props;
|
||||
const { testingMessage, testingStatus, plugin } = this.state;
|
||||
|
||||
return (
|
||||
<form onSubmit={this.onSubmit}>
|
||||
@@ -270,7 +268,7 @@ export class DataSourceSettingsPage extends PureComponent<Props, State> {
|
||||
{plugin && (
|
||||
<PluginSettings
|
||||
plugin={plugin}
|
||||
dataSource={this.state.dataSource}
|
||||
dataSource={dataSource}
|
||||
dataSourceMeta={dataSourceMeta}
|
||||
onModelChange={this.onModelChange}
|
||||
/>
|
||||
@@ -348,6 +346,7 @@ const mapDispatchToProps = {
|
||||
setDataSourceName,
|
||||
updateDataSource,
|
||||
setIsDefault,
|
||||
dataSourceLoaded,
|
||||
};
|
||||
|
||||
export default hot(module)(
|
||||
|
||||
Reference in New Issue
Block a user