From 72b7497d66a9b96394a29ea88e71e4c8ba57337f Mon Sep 17 00:00:00 2001 From: Peter Holmberg Date: Wed, 5 Dec 2018 11:47:02 +0100 Subject: [PATCH] Added isDefault switch on settings --- .../settings/BasicSettings.test.tsx | 4 +- .../datasources/settings/BasicSettings.tsx | 44 ++++++---- .../settings/DataSourceSettings.test.tsx | 1 + .../settings/DataSourceSettings.tsx | 12 ++- .../app/features/datasources/state/actions.ts | 14 ++- .../features/datasources/state/reducers.ts | 3 + yarn.lock | 87 ++----------------- 7 files changed, 59 insertions(+), 106 deletions(-) diff --git a/public/app/features/datasources/settings/BasicSettings.test.tsx b/public/app/features/datasources/settings/BasicSettings.test.tsx index 6729830bb75..0194adc9007 100644 --- a/public/app/features/datasources/settings/BasicSettings.test.tsx +++ b/public/app/features/datasources/settings/BasicSettings.test.tsx @@ -5,7 +5,9 @@ import BasicSettings, { Props } from './BasicSettings'; const setup = () => { const props: Props = { dataSourceName: 'Graphite', - onChange: jest.fn(), + isDefault: false, + onDefaultChange: jest.fn(), + onNameChange: jest.fn(), }; return shallow(); diff --git a/public/app/features/datasources/settings/BasicSettings.tsx b/public/app/features/datasources/settings/BasicSettings.tsx index adaec898dbc..569e0909c4d 100644 --- a/public/app/features/datasources/settings/BasicSettings.tsx +++ b/public/app/features/datasources/settings/BasicSettings.tsx @@ -1,31 +1,37 @@ import React, { SFC } from 'react'; import { Label } from 'app/core/components/Label/Label'; +import { Switch } from '../../../core/components/Switch/Switch'; export interface Props { dataSourceName: string; - onChange: (name: string) => void; + isDefault: boolean; + onNameChange: (name: string) => void; + onDefaultChange: (value: boolean) => void; } -const BasicSettings: SFC = ({ dataSourceName, onChange }) => { +const BasicSettings: SFC = ({ dataSourceName, isDefault, onDefaultChange, onNameChange }) => { return (
-
- - onChange(event.target.value)} - required - /> +
+
+ + onNameChange(event.target.value)} + required + /> +
+ onDefaultChange(event.target.checked)} />
); diff --git a/public/app/features/datasources/settings/DataSourceSettings.test.tsx b/public/app/features/datasources/settings/DataSourceSettings.test.tsx index 73c05fdd518..d6c934aa6a4 100644 --- a/public/app/features/datasources/settings/DataSourceSettings.test.tsx +++ b/public/app/features/datasources/settings/DataSourceSettings.test.tsx @@ -15,6 +15,7 @@ const setup = (propOverrides?: object) => { loadDataSource: jest.fn(), setDataSourceName: jest.fn(), updateDataSource: jest.fn(), + setIsDefault: jest.fn(), }; Object.assign(props, propOverrides); diff --git a/public/app/features/datasources/settings/DataSourceSettings.tsx b/public/app/features/datasources/settings/DataSourceSettings.tsx index 0f07023b472..977d37e35ec 100644 --- a/public/app/features/datasources/settings/DataSourceSettings.tsx +++ b/public/app/features/datasources/settings/DataSourceSettings.tsx @@ -13,7 +13,7 @@ import { getBackendSrv } from 'app/core/services/backend_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; 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 { getRouteParamsId } from 'app/core/selectors/location'; @@ -29,6 +29,7 @@ export interface Props { loadDataSource: typeof loadDataSource; setDataSourceName: typeof setDataSourceName; updateDataSource: typeof updateDataSource; + setIsDefault: typeof setIsDefault; } interface State { @@ -164,7 +165,7 @@ export class DataSourceSettings extends PureComponent { } render() { - const { dataSource, dataSourceMeta, navModel } = this.props; + const { dataSource, dataSourceMeta, navModel, setDataSourceName, setIsDefault } = this.props; const { testingMessage, testingStatus } = this.state; return ( @@ -177,8 +178,10 @@ export class DataSourceSettings extends PureComponent {
this.props.setDataSourceName(name)} + dataSourceName={dataSource.name} + isDefault={dataSource.isDefault} + onDefaultChange={state => setIsDefault(state)} + onNameChange={name => setDataSourceName(name)} /> {this.shouldRenderInfoBox() &&
{this.getInfoText()}
} @@ -240,6 +243,7 @@ const mapDispatchToProps = { loadDataSource, setDataSourceName, updateDataSource, + setIsDefault, }; export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DataSourceSettings)); diff --git a/public/app/features/datasources/state/actions.ts b/public/app/features/datasources/state/actions.ts index c03860e1f01..2c6afed42f6 100644 --- a/public/app/features/datasources/state/actions.ts +++ b/public/app/features/datasources/state/actions.ts @@ -17,6 +17,7 @@ export enum ActionTypes { SetDataSourcesLayoutMode = 'SET_DATA_SOURCES_LAYOUT_MODE', SetDataSourceTypeSearchQuery = 'SET_DATA_SOURCE_TYPE_SEARCH_QUERY', SetDataSourceName = 'SET_DATA_SOURCE_NAME', + SetIsDefault = 'SET_IS_DEFAULT', } interface LoadDataSourcesAction { @@ -59,6 +60,11 @@ interface SetDataSourceNameAction { payload: string; } +interface SetIsDefaultAction { + type: ActionTypes.SetIsDefault; + payload: boolean; +} + const dataSourcesLoaded = (dataSources: DataSource[]): LoadDataSourcesAction => ({ type: ActionTypes.LoadDataSources, payload: dataSources, @@ -99,6 +105,11 @@ export const setDataSourceName = (name: string) => ({ payload: name, }); +export const setIsDefault = (state: boolean) => ({ + type: ActionTypes.SetIsDefault, + payload: state, +}); + export type Action = | LoadDataSourcesAction | SetDataSourcesSearchQueryAction @@ -109,7 +120,8 @@ export type Action = | LoadDataSourceAction | UpdateNavIndexAction | LoadDataSourceMetaAction - | SetDataSourceNameAction; + | SetDataSourceNameAction + | SetIsDefaultAction; type ThunkResult = ThunkAction; diff --git a/public/app/features/datasources/state/reducers.ts b/public/app/features/datasources/state/reducers.ts index 33feae6770a..e8625aac0d2 100644 --- a/public/app/features/datasources/state/reducers.ts +++ b/public/app/features/datasources/state/reducers.ts @@ -39,6 +39,9 @@ export const dataSourcesReducer = (state = initialState, action: Action): DataSo case ActionTypes.SetDataSourceName: return { ...state, dataSource: { ...state.dataSource, name: action.payload } }; + + case ActionTypes.SetIsDefault: + return { ...state, dataSource: { ...state.dataSource, isDefault: action.payload } }; } return state; diff --git a/yarn.lock b/yarn.lock index ed649a1b365..a0ef0a342d1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -218,15 +218,6 @@ esutils "^2.0.2" 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": version "7.1.3" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.1.3.tgz#2c92469bac2b7fbff810b67fca07bd138b48af77" @@ -659,6 +650,12 @@ "@babel/helper-plugin-utils" "^7.0.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": version "7.1.2" resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.1.2.tgz#090484a574fef5a2d2d7726a674eceda5c5b5644" @@ -683,7 +680,6 @@ globals "^11.1.0" lodash "^4.17.10" ->>>>>>> master "@babel/types@^7.0.0": version "7.1.2" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.1.2.tgz#183e7952cf6691628afdc2e2b90d03240bac80c0" @@ -1845,21 +1841,10 @@ babel-jest@^23.6.0: babel-plugin-istanbul "^4.1.6" 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: version "8.0.4" resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-8.0.4.tgz#7bbf20cbe4560629e2e41534147692d3fecbdce6" integrity sha512-fhBhNkUToJcW9nV46v8w87AJOwAJDz84c1CL57n3Stj73FANM/b9TbCUK4YhdOwEyZ+OxhYpdeZDNzSI29Firw== ->>>>>>> master dependencies: find-cache-dir "^1.0.0" loader-utils "^1.0.2" @@ -2225,30 +2210,7 @@ babel-plugin-transform-strict-mode@^6.24.1: babel-runtime "^6.22.0" 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: ->>>>>>> master version "6.24.1" resolved "https://registry.yarnpkg.com/babel-preset-es2015/-/babel-preset-es2015-6.24.1.tgz#d44050d6bc2c9feea702aaf38d727a0210538939" dependencies: @@ -6184,21 +6146,10 @@ header-case@^1.0.0: no-case "^2.2.0" 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: version "1.2.2" resolved "https://registry.yarnpkg.com/highlight-words-core/-/highlight-words-core-1.2.2.tgz#1eff6d7d9f0a22f155042a00791237791b1eeaaa" integrity sha512-BXUKIkUuh6cmmxzi5OIbUJxrG8OAk2MqoL1DtO3Wo9D2faJg2ph5ntyuQeLqaHJmzER6H5tllCDA9ZnNe9BVGg== ->>>>>>> master hmac-drbg@^1.0.0: version "1.0.1" @@ -10639,21 +10590,10 @@ react-grid-layout@0.16.6: react-draggable "3.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: version "0.11.0" resolved "https://registry.yarnpkg.com/react-highlight-words/-/react-highlight-words-0.11.0.tgz#4f3c2039a8fd275f3ab795e59946b0324d8e6bee" integrity sha512-b+fgdQXNjX6RwHfiBYn6qH2D2mJEDNLuxdsqRseIiQffoCAoj7naMQ5EktUkmo9Bh1mXq/aMpJbdx7Lf2PytcQ== ->>>>>>> master dependencies: highlight-words-core "^1.2.0" prop-types "^15.5.8" @@ -11020,22 +10960,7 @@ regenerate@^1.2.1, regenerate@^1.4.0: version "1.4.0" 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: ->>>>>>> master version "0.11.1" resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.1.tgz#be05ad7f9bf7d22e056f9726cee5017fbf19e2e9"