-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Beats CM] Add password input and re-enable output config schema (#23417
) * wip defining controls * Complete adding formsy password field. * Re-enable output config schema definition. * Simplify import/export for formsy components.
- Loading branch information
1 parent
0dc44ba
commit 27e96f0
Showing
5 changed files
with
201 additions
and
63 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/beats_management/public/components/inputs/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
110 changes: 110 additions & 0 deletions
110
x-pack/plugins/beats_management/public/components/inputs/password_input.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters