diff --git a/public/app/core/components/FormSwitch/FormSwitch.tsx b/public/app/core/components/FormSwitch/FormSwitch.tsx new file mode 100644 index 00000000000..96260edde8a --- /dev/null +++ b/public/app/core/components/FormSwitch/FormSwitch.tsx @@ -0,0 +1,49 @@ +import React, { PureComponent } from 'react'; +import _ from 'lodash'; + +export interface Props { + label: string; + checked: boolean; + labelClass?: string; + switchClass?: string; + onChange: (event) => any; +} + +export interface State { + id: any; +} + +export class FormSwitch extends PureComponent { + state = { + id: _.uniqueId(), + }; + + internalOnChange = event => { + event.stopPropagation(); + + this.props.onChange(event); + }; + + render() { + const { labelClass, switchClass, label, checked } = this.props; + const labelId = `check-${this.state.id}`; + const labelClassName = `gf-form-label ${labelClass} pointer`; + const switchClassName = `gf-form-switch ${switchClass}`; + + return ( +
+ {label && ( + + )} +
+ +
+
+ ); + } +} + +export default FormSwitch; diff --git a/public/app/features/datasources/DataSourceHttpSettings.tsx b/public/app/features/datasources/DataSourceHttpSettings.tsx index 1112d048d0f..b75c634ab61 100644 --- a/public/app/features/datasources/DataSourceHttpSettings.tsx +++ b/public/app/features/datasources/DataSourceHttpSettings.tsx @@ -1,48 +1,91 @@ import React, { PureComponent } from 'react'; +import { connect } from 'react-redux'; +import { DataSource } from 'app/types'; +import FormSwitch from '../../core/components/FormSwitch/FormSwitch'; interface Props { - access: any; - basicAuth: any; + dataSource: DataSource; showAccessOption: any; tlsAuth: any; tlsAuthWithCACert: any; tlsCACert: any; tlsClientCert: any; tlsClientKey: any; - url: any; } interface State { basicAuthUser: string; basicAuthPassword: string; showAccessHelp: boolean; + url: string; + access: string; } -export default class DataSourceHttpSettings extends PureComponent { - state = { - basicAuthUser: '', - basicAuthPassword: '', - showAccessHelp: false, +export class DataSourceHttpSettings extends PureComponent { + constructor(props) { + super(props); + + this.state = { + url: '', + basicAuthUser: props.dataSource.basicAuthUser, + basicAuthPassword: props.dataSource.basicAuthPassword, + showAccessHelp: false, + access: '', + }; + } + + onToggleAccessHelp = () => { + this.setState(prevState => ({ + showAccessHelp: !prevState.showAccessHelp, + })); }; - onToggleAccessHelp = () => {}; + onUrlChange = event => { + this.setState({ + url: event.target.value, + }); + }; + + onAccessChange = event => { + this.setState({ + access: event.target.value, + }); + }; + + onBasicAuthChange = event => { + console.log(event); + }; + + onWithCredentialsChange = event => { + console.log(event); + }; + + onTlsAuthChange = event => { + console.log(event); + }; + + onTlsAuthWithCACertChange = event => { + console.log(event); + }; + + onTlsSkipVerifyChange = event => { + console.log(event); + }; render() { const { - access, - basicAuth, + dataSource, showAccessOption, tlsAuth, tlsAuthWithCACert, tlsCACert, tlsClientCert, tlsClientKey, - url, } = this.props; - const { showAccessHelp, basicAuthUser, basicAuthPassword } = this.state; + const { access, showAccessHelp, basicAuthUser, basicAuthPassword, url } = this.state; - // const accessOptions = [{key: 'proxy', value: 'Server (Default)'}, { key: 'direct', value: 'Browser'}]; + const accessOptions = [{ key: 'proxy', value: 'Server (Default)' }, { key: 'direct', value: 'Browser' }]; return (
@@ -51,173 +94,238 @@ export default class DataSourceHttpSettings extends PureComponent
URL - +
{showAccessOption && (
Access -
+
)} - - {showAccessHelp && ( -
-

- Access mode controls how requests to the data source will be handled. - - Server - {' '} - should be the preferred way if nothing else stated. -

-
Server access mode (Default):
-

- All requests will be made from the browser to Grafana backend/server which in turn will forward the - requests to the data source and by that circumvent possible Cross-Origin Resource Sharing (CORS) - requirements. The URL needs to be accessible from the grafana backend/server if you select this access - mode. -

-
Browser access mode:
-

- All requests will be made from the browser directly to the data source and may be subject to - Cross-Origin Resource Sharing (CORS) requirements. The URL needs to be accessible from the browser if - you select this access mode. -

-
- )} - {access === 'proxy' && ( -
-
- Whitelisted Cookies -
-
- )} - -

Auth

-
-
-
-
-
- - {basicAuth && ( -
-
Basic Auth Details
-
- User - -
-
- Password - -
-
- )} - - {(tlsAuth || tlsAuthWithCACert) && - access === 'proxy' && ( -
-
-
TLS Auth Details
-
- {tlsAuthWithCACert && ( -
-
-
- -
- {!tlsCACert && ( -
-