Skip to content

Commit

Permalink
[Beats CM] Add password input and re-enable output config schema (#23417
Browse files Browse the repository at this point in the history
)

* wip defining controls

* Complete adding formsy password field.

* Re-enable output config schema definition.

* Simplify import/export for formsy components.
  • Loading branch information
justinkambic authored Sep 24, 2018
1 parent 0dc44ba commit 27e96f0
Show file tree
Hide file tree
Showing 5 changed files with 201 additions and 63 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/beats_management/public/components/inputs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { FormsyEuiCodeEditor } from './code_editor';
export { FormsyEuiFieldText } from './input';
export { FormsyEuiPasswordText } from './password_input';
export { FormsyEuiMultiFieldText } from './multi_input';
export { FormsyEuiSelect } from './select';
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

// @ts-ignore currently no definition for EuiFieldPassword
import { CommonProps, EuiFieldPassword, EuiFieldPasswordProps, EuiFormRow } from '@elastic/eui';
import { FormsyInputProps, withFormsy } from 'formsy-react';
import React, { Component, InputHTMLAttributes } from 'react';

interface ComponentProps extends FormsyInputProps, CommonProps, EuiFieldPasswordProps {
instantValidation?: boolean;
label: string;
errorText: string;
fullWidth: boolean;
helpText: React.ReactElement<any>;
compressed: boolean;
onChange?(e: React.ChangeEvent<HTMLInputElement>, value: any): void;
onBlur?(e: React.ChangeEvent<HTMLInputElement>, value: any): void;
}

interface ComponentState {
allowError: boolean;
}

class FieldPassword extends Component<
InputHTMLAttributes<HTMLInputElement> & ComponentProps,
ComponentState
> {
constructor(props: any) {
super(props);

this.state = {
allowError: false,
};
}

public componentDidMount() {
const { defaultValue, setValue } = this.props;
if (defaultValue) {
setValue(defaultValue);
}
}

public handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.currentTarget;
this.props.setValue(value);
if (this.props.onChange) {
this.props.onChange(e, value);
}
if (this.props.instantValidation) {
this.showError();
}
};

public handleBlur = (e: React.ChangeEvent<HTMLInputElement>) => {
this.showError();
if (this.props.onBlur) {
this.props.onBlur(e, e.currentTarget.value);
}
};

public showError = () => this.setState({ allowError: true });

public render() {
const {
id,
required,
label,
getValue,
isValid,
isPristine,
getErrorMessage,
fullWidth,
className,
disabled,
helpText,
onBlur,
} = this.props;

const { allowError } = this.state;
const error = !isPristine() && !isValid() && allowError;

return (
<EuiFormRow
id={id}
label={label}
helpText={helpText}
isInvalid={!disabled && error}
error={!disabled && error ? getErrorMessage() : []}
>
<EuiFieldPassword
id={id}
name={name}
value={getValue() || ''}
isInvalid={!disabled && error}
onChange={this.handleChange}
onBlur={onBlur}
fullWidth={fullWidth}
disabled={disabled}
required={required}
className={className}
/>
</EuiFormRow>
);
}
}

export const FormsyEuiPasswordText = withFormsy(FieldPassword);
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import { get } from 'lodash';
import React from 'react';
import { ConfigurationBlock } from '../../../../common/domain_types';
import { YamlConfigSchema } from '../../../lib/lib';
import { FormsyEuiCodeEditor } from '../../inputs/code_editor';
import { FormsyEuiFieldText } from '../../inputs/input';
import { FormsyEuiMultiFieldText } from '../../inputs/multi_input';
import { FormsyEuiSelect } from '../../inputs/select';
import {
FormsyEuiCodeEditor,
FormsyEuiFieldText,
FormsyEuiMultiFieldText,
FormsyEuiPasswordText,
FormsyEuiSelect,
} from '../../inputs';

addValidationRule('isHosts', (form: FormData, values: FieldValue | string[]) => {
if (values && values.length > 0 && values instanceof Array) {
Expand Down Expand Up @@ -131,6 +134,20 @@ export class ConfigForm extends React.Component<ComponentProps, any> {
required={schema.required}
/>
);
case 'password':
return (
<FormsyEuiPasswordText
key={schema.id}
id={schema.id}
defaultValue={get(this.props, `values.configs[0].${schema.id}`)}
name={schema.id}
helpText={schema.ui.helpText}
label={schema.ui.label}
validations={schema.validations}
validationError={schema.error}
required={schema.required}
/>
);
case 'multi-input':
return (
<FormsyEuiMultiFieldText
Expand Down
116 changes: 58 additions & 58 deletions x-pack/plugins/beats_management/public/config_schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,67 +131,67 @@ const metricbeatModuleConfig: YamlConfigSchema[] = [
},
];

// const outputConfig: YamlConfigSchema[] = [
// {
// id: 'output',
// ui: {
// label: 'Output Type',
// type: 'select',
// },
// options: [
// {
// value: 'elasticsearch',
// text: 'Elasticsearch',
// },
// {
// value: 'logstash',
// text: 'Logstash',
// },
// {
// value: 'kafka',
// text: 'Kafka',
// },
// {
// value: 'console',
// text: 'Console',
// },
// ],
// error: 'Please select an output type',
// required: true,
// },
// {
// id: 'hosts',
// ui: {
// label: 'Hosts',
// type: 'multi-input',
// },
// validations: 'isHost',
// error: 'One file host per line',
// parseValidResult: v => v.split('\n'),
// },
// {
// id: 'username',
// ui: {
// label: 'Username',
// type: 'input',
// },
// validations: 'isString',
// error: 'Unprocessable username',
// },
// {
// id: 'password',
// ui: {
// label: 'Password',
// type: 'input',
// },
// validations: 'isString',
// error: 'Unprocessable password',
// },
// ];
const outputConfig: YamlConfigSchema[] = [
{
id: 'output',
ui: {
label: 'Output Type',
type: 'select',
},
options: [
{
value: 'elasticsearch',
text: 'Elasticsearch',
},
{
value: 'logstash',
text: 'Logstash',
},
{
value: 'kafka',
text: 'Kafka',
},
{
value: 'console',
text: 'Console',
},
],
error: 'Please select an output type',
required: true,
},
{
id: 'hosts',
ui: {
label: 'Hosts',
type: 'multi-input',
},
validations: 'isHosts',
error: 'One file host per line',
parseValidResult: v => v.split('\n'),
},
{
id: 'username',
ui: {
label: 'Username',
type: 'input',
},
validations: 'isString',
error: 'Unprocessable username',
},
{
id: 'password',
ui: {
label: 'Password',
type: 'input',
},
validations: 'isString',
error: 'Unprocessable password',
},
];

export const supportedConfigs = [
{ text: 'Filebeat Input', value: 'filebeat.inputs', config: filebeatInputConfig },
{ text: 'Filebeat Module', value: 'filebeat.modules', config: filebeatModuleConfig },
{ text: 'Metricbeat Input', value: 'metricbeat.modules', config: metricbeatModuleConfig },
// { text: 'Output', value: 'output', config: outputConfig },
{ text: 'Output', value: 'output', config: outputConfig },
];
2 changes: 1 addition & 1 deletion x-pack/plugins/beats_management/public/lib/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface YamlConfigSchema {
id: string;
ui: {
label: string;
type: 'input' | 'multi-input' | 'select' | 'code';
type: 'input' | 'multi-input' | 'select' | 'code' | 'password';
helpText?: string;
};
options?: Array<{ value: string; text: string }>;
Expand Down

0 comments on commit 27e96f0

Please sign in to comment.