Commit 72b7497d by Peter Holmberg

Added isDefault switch on settings

parent aa6c52a1
...@@ -5,7 +5,9 @@ import BasicSettings, { Props } from './BasicSettings'; ...@@ -5,7 +5,9 @@ import BasicSettings, { Props } from './BasicSettings';
const setup = () => { const setup = () => {
const props: Props = { const props: Props = {
dataSourceName: 'Graphite', dataSourceName: 'Graphite',
onChange: jest.fn(), isDefault: false,
onDefaultChange: jest.fn(),
onNameChange: jest.fn(),
}; };
return shallow(<BasicSettings {...props} />); return shallow(<BasicSettings {...props} />);
......
import React, { SFC } from 'react'; import React, { SFC } from 'react';
import { Label } from 'app/core/components/Label/Label'; import { Label } from 'app/core/components/Label/Label';
import { Switch } from '../../../core/components/Switch/Switch';
export interface Props { export interface Props {
dataSourceName: string; dataSourceName: string;
onChange: (name: string) => void; isDefault: boolean;
onNameChange: (name: string) => void;
onDefaultChange: (value: boolean) => void;
} }
const BasicSettings: SFC<Props> = ({ dataSourceName, onChange }) => { const BasicSettings: SFC<Props> = ({ dataSourceName, isDefault, onDefaultChange, onNameChange }) => {
return ( return (
<div className="gf-form-group"> <div className="gf-form-group">
<div className="gf-form max-width-30"> <div className="gf-form-inline">
<Label <div className="gf-form max-width-30" style={{ marginRight: '3px' }}>
tooltip={ <Label
'The name is used when you select the data source in panels. The Default data source is' + tooltip={
'preselected in new panels.' 'The name is used when you select the data source in panels. The Default data source is' +
} 'preselected in new panels.'
> }
Name >
</Label> Name
<input </Label>
className="gf-form-input max-width-23" <input
type="text" className="gf-form-input max-width-23"
value={dataSourceName} type="text"
placeholder="Name" value={dataSourceName}
onChange={event => onChange(event.target.value)} placeholder="Name"
required onChange={event => onNameChange(event.target.value)}
/> required
/>
</div>
<Switch label="Default" checked={isDefault} onChange={event => onDefaultChange(event.target.checked)} />
</div> </div>
</div> </div>
); );
......
...@@ -15,6 +15,7 @@ const setup = (propOverrides?: object) => { ...@@ -15,6 +15,7 @@ const setup = (propOverrides?: object) => {
loadDataSource: jest.fn(), loadDataSource: jest.fn(),
setDataSourceName: jest.fn(), setDataSourceName: jest.fn(),
updateDataSource: jest.fn(), updateDataSource: jest.fn(),
setIsDefault: jest.fn(),
}; };
Object.assign(props, propOverrides); Object.assign(props, propOverrides);
......
...@@ -13,7 +13,7 @@ import { getBackendSrv } from 'app/core/services/backend_srv'; ...@@ -13,7 +13,7 @@ import { getBackendSrv } from 'app/core/services/backend_srv';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { getDataSource, getDataSourceMeta } from '../state/selectors'; import { getDataSource, getDataSourceMeta } from '../state/selectors';
import { deleteDataSource, loadDataSource, setDataSourceName, updateDataSource } from '../state/actions'; import { deleteDataSource, loadDataSource, setDataSourceName, setIsDefault, updateDataSource } from '../state/actions';
import { getNavModel } from 'app/core/selectors/navModel'; import { getNavModel } from 'app/core/selectors/navModel';
import { getRouteParamsId } from 'app/core/selectors/location'; import { getRouteParamsId } from 'app/core/selectors/location';
...@@ -29,6 +29,7 @@ export interface Props { ...@@ -29,6 +29,7 @@ export interface Props {
loadDataSource: typeof loadDataSource; loadDataSource: typeof loadDataSource;
setDataSourceName: typeof setDataSourceName; setDataSourceName: typeof setDataSourceName;
updateDataSource: typeof updateDataSource; updateDataSource: typeof updateDataSource;
setIsDefault: typeof setIsDefault;
} }
interface State { interface State {
...@@ -164,7 +165,7 @@ export class DataSourceSettings extends PureComponent<Props, State> { ...@@ -164,7 +165,7 @@ export class DataSourceSettings extends PureComponent<Props, State> {
} }
render() { render() {
const { dataSource, dataSourceMeta, navModel } = this.props; const { dataSource, dataSourceMeta, navModel, setDataSourceName, setIsDefault } = this.props;
const { testingMessage, testingStatus } = this.state; const { testingMessage, testingStatus } = this.state;
return ( return (
...@@ -177,8 +178,10 @@ export class DataSourceSettings extends PureComponent<Props, State> { ...@@ -177,8 +178,10 @@ export class DataSourceSettings extends PureComponent<Props, State> {
<div> <div>
<form onSubmit={this.onSubmit}> <form onSubmit={this.onSubmit}>
<BasicSettings <BasicSettings
dataSourceName={this.props.dataSource.name} dataSourceName={dataSource.name}
onChange={name => this.props.setDataSourceName(name)} isDefault={dataSource.isDefault}
onDefaultChange={state => setIsDefault(state)}
onNameChange={name => setDataSourceName(name)}
/> />
{this.shouldRenderInfoBox() && <div className="grafana-info-box">{this.getInfoText()}</div>} {this.shouldRenderInfoBox() && <div className="grafana-info-box">{this.getInfoText()}</div>}
...@@ -240,6 +243,7 @@ const mapDispatchToProps = { ...@@ -240,6 +243,7 @@ const mapDispatchToProps = {
loadDataSource, loadDataSource,
setDataSourceName, setDataSourceName,
updateDataSource, updateDataSource,
setIsDefault,
}; };
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DataSourceSettings)); export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DataSourceSettings));
...@@ -17,6 +17,7 @@ export enum ActionTypes { ...@@ -17,6 +17,7 @@ export enum ActionTypes {
SetDataSourcesLayoutMode = 'SET_DATA_SOURCES_LAYOUT_MODE', SetDataSourcesLayoutMode = 'SET_DATA_SOURCES_LAYOUT_MODE',
SetDataSourceTypeSearchQuery = 'SET_DATA_SOURCE_TYPE_SEARCH_QUERY', SetDataSourceTypeSearchQuery = 'SET_DATA_SOURCE_TYPE_SEARCH_QUERY',
SetDataSourceName = 'SET_DATA_SOURCE_NAME', SetDataSourceName = 'SET_DATA_SOURCE_NAME',
SetIsDefault = 'SET_IS_DEFAULT',
} }
interface LoadDataSourcesAction { interface LoadDataSourcesAction {
...@@ -59,6 +60,11 @@ interface SetDataSourceNameAction { ...@@ -59,6 +60,11 @@ interface SetDataSourceNameAction {
payload: string; payload: string;
} }
interface SetIsDefaultAction {
type: ActionTypes.SetIsDefault;
payload: boolean;
}
const dataSourcesLoaded = (dataSources: DataSource[]): LoadDataSourcesAction => ({ const dataSourcesLoaded = (dataSources: DataSource[]): LoadDataSourcesAction => ({
type: ActionTypes.LoadDataSources, type: ActionTypes.LoadDataSources,
payload: dataSources, payload: dataSources,
...@@ -99,6 +105,11 @@ export const setDataSourceName = (name: string) => ({ ...@@ -99,6 +105,11 @@ export const setDataSourceName = (name: string) => ({
payload: name, payload: name,
}); });
export const setIsDefault = (state: boolean) => ({
type: ActionTypes.SetIsDefault,
payload: state,
});
export type Action = export type Action =
| LoadDataSourcesAction | LoadDataSourcesAction
| SetDataSourcesSearchQueryAction | SetDataSourcesSearchQueryAction
...@@ -109,7 +120,8 @@ export type Action = ...@@ -109,7 +120,8 @@ export type Action =
| LoadDataSourceAction | LoadDataSourceAction
| UpdateNavIndexAction | UpdateNavIndexAction
| LoadDataSourceMetaAction | LoadDataSourceMetaAction
| SetDataSourceNameAction; | SetDataSourceNameAction
| SetIsDefaultAction;
type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>; type ThunkResult<R> = ThunkAction<R, StoreState, undefined, Action>;
......
...@@ -39,6 +39,9 @@ export const dataSourcesReducer = (state = initialState, action: Action): DataSo ...@@ -39,6 +39,9 @@ export const dataSourcesReducer = (state = initialState, action: Action): DataSo
case ActionTypes.SetDataSourceName: case ActionTypes.SetDataSourceName:
return { ...state, dataSource: { ...state.dataSource, name: action.payload } }; return { ...state, dataSource: { ...state.dataSource, name: action.payload } };
case ActionTypes.SetIsDefault:
return { ...state, dataSource: { ...state.dataSource, isDefault: action.payload } };
} }
return state; return state;
......
...@@ -218,15 +218,6 @@ ...@@ -218,15 +218,6 @@
esutils "^2.0.2" esutils "^2.0.2"
js-tokens "^4.0.0" js-tokens "^4.0.0"
<<<<<<< HEAD
"@babel/runtime@^7.1.2":
version "7.1.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.1.5.tgz#4170907641cf1f61508f563ece3725150cc6fe39"
dependencies:
regenerator-runtime "^0.12.0"
||||||| merged common ancestors
=======
"@babel/parser@^7.1.2", "@babel/parser@^7.1.3": "@babel/parser@^7.1.2", "@babel/parser@^7.1.3":
version "7.1.3" version "7.1.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.3.tgz#2c92469bac2b7fbff810b67fca07bd138b48af77" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.3.tgz#2c92469bac2b7fbff810b67fca07bd138b48af77"
...@@ -659,6 +650,12 @@ ...@@ -659,6 +650,12 @@
"@babel/helper-plugin-utils" "^7.0.0" "@babel/helper-plugin-utils" "^7.0.0"
"@babel/plugin-transform-typescript" "^7.1.0" "@babel/plugin-transform-typescript" "^7.1.0"
"@babel/runtime@^7.1.2":
version "7.1.5"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.1.5.tgz#4170907641cf1f61508f563ece3725150cc6fe39"
dependencies:
regenerator-runtime "^0.12.0"
"@babel/template@^7.1.0", "@babel/template@^7.1.2": "@babel/template@^7.1.0", "@babel/template@^7.1.2":
version "7.1.2" version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644"
...@@ -683,7 +680,6 @@ ...@@ -683,7 +680,6 @@
globals "^11.1.0" globals "^11.1.0"
lodash "^4.17.10" lodash "^4.17.10"
>>>>>>> master
"@babel/types@^7.0.0": "@babel/types@^7.0.0":
version "7.1.2" version "7.1.2"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.2.tgz#183e7952cf6691628afdc2e2b90d03240bac80c0" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.2.tgz#183e7952cf6691628afdc2e2b90d03240bac80c0"
...@@ -1845,21 +1841,10 @@ babel-jest@^23.6.0: ...@@ -1845,21 +1841,10 @@ babel-jest@^23.6.0:
babel-plugin-istanbul "^4.1.6" babel-plugin-istanbul "^4.1.6"
babel-preset-jest "^23.2.0" babel-preset-jest "^23.2.0"
<<<<<<< HEAD
babel-loader@^7.1.4:
version "7.1.5"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.5.tgz#e3ee0cd7394aa557e013b02d3e492bfd07aa6d68"
||||||| merged common ancestors
babel-loader@^7.1.4:
version "7.1.5"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.5.tgz#e3ee0cd7394aa557e013b02d3e492bfd07aa6d68"
integrity sha512-iCHfbieL5d1LfOQeeVJEUyD9rTwBcP/fcEbRCfempxTDuqrKpu0AZjLAQHEQa3Yqyj9ORKe2iHfoj4rHLf7xpw==
=======
babel-loader@^8.0.4: babel-loader@^8.0.4:
version "8.0.4" version "8.0.4"
resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.4.tgz#7bbf20cbe4560629e2e41534147692d3fecbdce6" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.4.tgz#7bbf20cbe4560629e2e41534147692d3fecbdce6"
integrity sha512-fhBhNkUToJcW9nV46v8w87AJOwAJDz84c1CL57n3Stj73FANM/b9TbCUK4YhdOwEyZ+OxhYpdeZDNzSI29Firw== integrity sha512-fhBhNkUToJcW9nV46v8w87AJOwAJDz84c1CL57n3Stj73FANM/b9TbCUK4YhdOwEyZ+OxhYpdeZDNzSI29Firw==
>>>>>>> master
dependencies: dependencies:
find-cache-dir "^1.0.0" find-cache-dir "^1.0.0"
loader-utils "^1.0.2" loader-utils "^1.0.2"
...@@ -2225,30 +2210,7 @@ babel-plugin-transform-strict-mode@^6.24.1: ...@@ -2225,30 +2210,7 @@ babel-plugin-transform-strict-mode@^6.24.1:
babel-runtime "^6.22.0" babel-runtime "^6.22.0"
babel-types "^6.24.1" babel-types "^6.24.1"
<<<<<<< HEAD
babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
dependencies:
babel-runtime "^6.26.0"
core-js "^2.5.0"
regenerator-runtime "^0.10.5"
babel-preset-es2015@^6.24.1, babel-preset-es2015@^6.9.0:
||||||| merged common ancestors
babel-polyfill@^6.26.0:
version "6.26.0"
resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153"
integrity sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=
dependencies:
babel-runtime "^6.26.0"
core-js "^2.5.0"
regenerator-runtime "^0.10.5"
babel-preset-es2015@^6.24.1, babel-preset-es2015@^6.9.0:
=======
babel-preset-es2015@^6.9.0: babel-preset-es2015@^6.9.0:
>>>>>>> master
version "6.24.1" version "6.24.1"
resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz#d44050d6bc2c9feea702aaf38d727a0210538939" resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz#d44050d6bc2c9feea702aaf38d727a0210538939"
dependencies: dependencies:
...@@ -6184,21 +6146,10 @@ header-case@^1.0.0: ...@@ -6184,21 +6146,10 @@ header-case@^1.0.0:
no-case "^2.2.0" no-case "^2.2.0"
upper-case "^1.1.3" upper-case "^1.1.3"
<<<<<<< HEAD
highlight-words-core@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.0.tgz#232bec301cbf2a4943d335dc748ce70e9024f3b1"
||||||| merged common ancestors
highlight-words-core@^1.1.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.0.tgz#232bec301cbf2a4943d335dc748ce70e9024f3b1"
integrity sha512-nu5bMsWIgpsrlXEMNKSvbJMeUPhFxCOVT28DnI8UCVfhm3e98LC8oeyMNrc7E18+QQ4l/PvbeN7ojyN4XsmBdA==
=======
highlight-words-core@^1.2.0: highlight-words-core@^1.2.0:
version "1.2.2" version "1.2.2"
resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.2.tgz#1eff6d7d9f0a22f155042a00791237791b1eeaaa" resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.2.tgz#1eff6d7d9f0a22f155042a00791237791b1eeaaa"
integrity sha512-BXUKIkUuh6cmmxzi5OIbUJxrG8OAk2MqoL1DtO3Wo9D2faJg2ph5ntyuQeLqaHJmzER6H5tllCDA9ZnNe9BVGg== integrity sha512-BXUKIkUuh6cmmxzi5OIbUJxrG8OAk2MqoL1DtO3Wo9D2faJg2ph5ntyuQeLqaHJmzER6H5tllCDA9ZnNe9BVGg==
>>>>>>> master
hmac-drbg@^1.0.0: hmac-drbg@^1.0.0:
version "1.0.1" version "1.0.1"
...@@ -10639,21 +10590,10 @@ react-grid-layout@0.16.6: ...@@ -10639,21 +10590,10 @@ react-grid-layout@0.16.6:
react-draggable "3.x" react-draggable "3.x"
react-resizable "1.x" react-resizable "1.x"
<<<<<<< HEAD
react-highlight-words@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.10.0.tgz#2e905c76c11635237f848ecad00600f1b6f6f4a8"
||||||| merged common ancestors
react-highlight-words@^0.10.0:
version "0.10.0"
resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.10.0.tgz#2e905c76c11635237f848ecad00600f1b6f6f4a8"
integrity sha512-/5jh6a8pir3baCOMC5j88MBmNciSwG5bXWNAAtbtDb3WYJoGn82e2zLCQFnghIBWod1h5y6/LRO8TS6ERbN5aQ==
=======
react-highlight-words@0.11.0: react-highlight-words@0.11.0:
version "0.11.0" version "0.11.0"
resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.11.0.tgz#4f3c2039a8fd275f3ab795e59946b0324d8e6bee" resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.11.0.tgz#4f3c2039a8fd275f3ab795e59946b0324d8e6bee"
integrity sha512-b+fgdQXNjX6RwHfiBYn6qH2D2mJEDNLuxdsqRseIiQffoCAoj7naMQ5EktUkmo9Bh1mXq/aMpJbdx7Lf2PytcQ== integrity sha512-b+fgdQXNjX6RwHfiBYn6qH2D2mJEDNLuxdsqRseIiQffoCAoj7naMQ5EktUkmo9Bh1mXq/aMpJbdx7Lf2PytcQ==
>>>>>>> master
dependencies: dependencies:
highlight-words-core "^1.2.0" highlight-words-core "^1.2.0"
prop-types "^15.5.8" prop-types "^15.5.8"
...@@ -11020,22 +10960,7 @@ regenerate@^1.2.1, regenerate@^1.4.0: ...@@ -11020,22 +10960,7 @@ regenerate@^1.2.1, regenerate@^1.4.0:
version "1.4.0" version "1.4.0"
resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11" resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.4.0.tgz#4a856ec4b56e4077c557589cae85e7a4c8869a11"
<<<<<<< HEAD
regenerator-runtime@^0.10.5:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
regenerator-runtime@^0.11.0:
||||||| merged common ancestors
regenerator-runtime@^0.10.5:
version "0.10.5"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658"
integrity sha1-M2w+/BIgrc7dosn6tntaeVWjNlg=
regenerator-runtime@^0.11.0:
=======
regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1: regenerator-runtime@^0.11.0, regenerator-runtime@^0.11.1:
>>>>>>> master
version "0.11.1" version "0.11.1"
resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment