2017-08-10 01:56:27 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2017-03-23 22:10:42 +00:00
|
|
|
import KeyValueEditor from '../../key-value-editor/editor';
|
|
|
|
import {trackEvent} from '../../../../analytics/index';
|
|
|
|
import {AUTH_BASIC} from '../../../../common/constants';
|
2016-04-09 21:08:55 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-03-23 22:10:42 +00:00
|
|
|
class BasicAuth extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleOnCreate () {
|
2017-03-28 22:45:23 +00:00
|
|
|
trackEvent('Basic Auth Editor', 'Create');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_handleOnDelete () {
|
2017-03-28 22:45:23 +00:00
|
|
|
trackEvent('Basic Auth Editor', 'Delete');
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_handleToggleDisable (pair) {
|
2016-11-26 08:29:16 +00:00
|
|
|
const label = pair.disabled ? 'Disable' : 'Enable';
|
2017-03-28 22:45:23 +00:00
|
|
|
trackEvent('Basic Auth Editor', 'Toggle', label);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-26 08:29:16 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleChange (pairs) {
|
2016-11-26 08:29:16 +00:00
|
|
|
const pair = {
|
2017-03-23 22:10:42 +00:00
|
|
|
type: AUTH_BASIC,
|
2016-11-26 08:29:16 +00:00
|
|
|
username: pairs.length ? pairs[0].name : '',
|
|
|
|
password: pairs.length ? pairs[0].value : '',
|
2017-03-03 20:09:08 +00:00
|
|
|
disabled: pairs.length ? pairs[0].disabled : false
|
2016-11-26 08:29:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.props.onChange(pair);
|
2017-03-03 01:44:07 +00:00
|
|
|
}
|
2016-11-26 08:29:16 +00:00
|
|
|
|
|
|
|
render () {
|
2017-03-12 00:31:23 +00:00
|
|
|
const {
|
|
|
|
authentication,
|
|
|
|
showPasswords,
|
|
|
|
handleRender,
|
|
|
|
handleGetRenderContext
|
|
|
|
} = this.props;
|
|
|
|
|
2016-11-26 08:29:16 +00:00
|
|
|
const pairs = [{
|
|
|
|
name: authentication.username || '',
|
|
|
|
value: authentication.password || '',
|
2017-03-03 20:09:08 +00:00
|
|
|
disabled: authentication.disabled || false
|
2016-11-26 08:29:16 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<KeyValueEditor
|
|
|
|
pairs={pairs}
|
|
|
|
maxPairs={1}
|
2017-03-01 21:15:56 +00:00
|
|
|
disableDelete
|
2017-02-27 21:00:13 +00:00
|
|
|
handleRender={handleRender}
|
2017-03-12 00:31:23 +00:00
|
|
|
handleGetRenderContext={handleGetRenderContext}
|
2016-11-26 08:29:16 +00:00
|
|
|
namePlaceholder="Username"
|
2016-11-29 20:55:31 +00:00
|
|
|
valuePlaceholder="•••••••••••"
|
2016-11-26 08:29:16 +00:00
|
|
|
valueInputType={showPasswords ? 'text' : 'password'}
|
|
|
|
onToggleDisable={this._handleToggleDisable}
|
|
|
|
onCreate={this._handleOnCreate}
|
|
|
|
onDelete={this._handleOnDelete}
|
|
|
|
onChange={this._handleChange}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-04-09 21:08:55 +00:00
|
|
|
|
2017-03-23 22:10:42 +00:00
|
|
|
BasicAuth.propTypes = {
|
2017-02-27 21:00:13 +00:00
|
|
|
handleRender: PropTypes.func.isRequired,
|
2017-03-12 00:31:23 +00:00
|
|
|
handleGetRenderContext: PropTypes.func.isRequired,
|
2016-11-26 00:37:59 +00:00
|
|
|
handleUpdateSettingsShowPasswords: PropTypes.func.isRequired,
|
2016-04-09 21:08:55 +00:00
|
|
|
onChange: PropTypes.func.isRequired,
|
2016-11-26 00:37:59 +00:00
|
|
|
authentication: PropTypes.object.isRequired,
|
2017-03-03 20:09:08 +00:00
|
|
|
showPasswords: PropTypes.bool.isRequired
|
2016-04-09 21:08:55 +00:00
|
|
|
};
|
|
|
|
|
2017-03-23 22:10:42 +00:00
|
|
|
export default BasicAuth;
|