-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Beats/config view #22177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beats/config view #22177
Changes from 36 commits
71b162a
ebffb62
85c1e59
e782314
2151ae3
7ab3a96
c2d3a4a
8317937
c1ebd16
58f4aac
ce60486
b071284
6298c2f
b8c0605
d628018
9373a2c
b533c30
40e49e4
acbc416
5219006
9a11a85
0fd670b
aac2b30
22c358d
4cd93aa
9888cf5
4e25282
00e826a
48f3497
d44f2f4
29a5f07
4679e91
6a88c35
0103aea
d0502fe
57fdb5b
dfa443f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * 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 | ||
| import { EuiBasicTable, EuiLink } from '@elastic/eui'; | ||
| import React from 'react'; | ||
| import { supportedConfigs } from '../config_schemas'; | ||
| import { ClientSideConfigurationBlock } from '../lib/lib'; | ||
|
|
||
| interface ComponentProps { | ||
| configs: ClientSideConfigurationBlock[]; | ||
| onConfigClick: (action: 'edit' | 'delete', config: ClientSideConfigurationBlock) => any; | ||
| } | ||
|
|
||
| export const ConfigList: React.SFC<ComponentProps> = props => ( | ||
| <EuiBasicTable | ||
| items={props.configs} | ||
| columns={[ | ||
| { | ||
| field: 'type', | ||
| name: 'Type', | ||
| truncateText: false, | ||
| render: (value: string, config: ClientSideConfigurationBlock) => { | ||
| const type = supportedConfigs.find((sc: any) => sc.value === config.type); | ||
|
|
||
| return ( | ||
| <EuiLink onClick={() => props.onConfigClick('edit', config)}> | ||
| {type ? type.text : config.type} | ||
| </EuiLink> | ||
| ); | ||
| }, | ||
| }, | ||
| { | ||
| field: 'block_obj.module', | ||
| name: 'Module', | ||
| truncateText: false, | ||
| render: (item: ClientSideConfigurationBlock) => | ||
| (item && (item.block_obj as any).module) || 'N/A', | ||
| }, | ||
| { | ||
| field: 'description', | ||
| name: 'Description', | ||
| }, | ||
| { | ||
| name: 'Actions', | ||
| actions: [ | ||
| { | ||
| name: 'Remove', | ||
| description: 'Remove this config from tag', | ||
| type: 'icon', | ||
| icon: 'trash', | ||
| onClick: (item: ClientSideConfigurationBlock) => props.onConfigClick('delete', item), | ||
| }, | ||
| ], | ||
| }, | ||
| ]} | ||
| /> | ||
| ); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * 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 | ||
| import { CommonProps, EuiCodeEditor, EuiCodeEditorProps, EuiFormRow } from '@elastic/eui'; | ||
| // @ts-ignore | ||
| import { FormsyInputProps, withFormsy } from 'formsy-react'; | ||
| import React, { Component, InputHTMLAttributes } from 'react'; | ||
|
|
||
| interface ComponentProps extends FormsyInputProps, CommonProps, EuiCodeEditorProps { | ||
| instantValidation: boolean; | ||
| label: string; | ||
| isReadOnly: boolean; | ||
| mode: 'javascript' | 'yaml'; | ||
| errorText: string; | ||
| fullWidth: boolean; | ||
| helpText: React.ReactElement<any>; | ||
| compressed: boolean; | ||
| onChange(value: string): void; | ||
| onBlur(): void; | ||
| } | ||
|
|
||
| interface ComponentState { | ||
| allowError: boolean; | ||
| } | ||
|
|
||
| class CodeEditor extends Component< | ||
| InputHTMLAttributes<HTMLTextAreaElement> & ComponentProps, | ||
| ComponentState | ||
| > { | ||
| public static defaultProps = { | ||
| passRequiredToField: true, | ||
| }; | ||
|
|
||
| public state = { allowError: false }; | ||
|
|
||
| public componentDidMount() { | ||
| const { defaultValue, setValue } = this.props; | ||
| if (defaultValue) { | ||
| setValue(defaultValue); | ||
| } | ||
| } | ||
|
|
||
| public componentWillReceiveProps(nextProps: ComponentProps) { | ||
| if (nextProps.isFormSubmitted()) { | ||
| this.showError(); | ||
| } | ||
| } | ||
|
|
||
| public handleChange = (value: string) => { | ||
| this.props.setValue(value); | ||
| if (this.props.onChange) { | ||
| this.props.onChange(value); | ||
| } | ||
| if (this.props.instantValidation) { | ||
| this.showError(); | ||
| } | ||
| }; | ||
|
|
||
| public handleBlur = () => { | ||
| this.showError(); | ||
| if (this.props.onBlur) { | ||
| this.props.onBlur(); | ||
| } | ||
| }; | ||
|
|
||
| public showError = () => this.setState({ allowError: true }); | ||
|
|
||
| public render() { | ||
| const { | ||
| id, | ||
| label, | ||
| isReadOnly, | ||
| isValid, | ||
| getValue, | ||
| isPristine, | ||
| getErrorMessage, | ||
| mode, | ||
| fullWidth, | ||
| className, | ||
| helpText, | ||
| } = this.props; | ||
|
|
||
| const { allowError } = this.state; | ||
| const error = !isPristine() && !isValid() && allowError; | ||
|
|
||
| return ( | ||
| <EuiFormRow | ||
| id={id} | ||
| label={label} | ||
| helpText={helpText} | ||
| isInvalid={error} | ||
| error={error ? getErrorMessage() : []} | ||
| > | ||
| <EuiCodeEditor | ||
| id={id} | ||
| name={name} | ||
| mode={mode} | ||
| theme="github" | ||
| value={getValue()} | ||
| isReadOnly={isReadOnly || false} | ||
| isInvalid={error} | ||
| onChange={this.handleChange} | ||
| onBlur={this.handleBlur} | ||
| width={fullWidth ? '100%' : undefined} | ||
| className={className} | ||
| /> | ||
| </EuiFormRow> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const FormsyEuiCodeEditor = withFormsy(CodeEditor); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| import { CommonProps, EuiFieldText, EuiFieldTextProps, EuiFormRow } from '@elastic/eui'; | ||
| import { FormsyInputProps, withFormsy } from 'formsy-react'; | ||
| import React, { Component, InputHTMLAttributes } from 'react'; | ||
|
|
||
| interface ComponentProps extends FormsyInputProps, CommonProps, EuiFieldTextProps { | ||
| 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 FieldText extends Component< | ||
| InputHTMLAttributes<HTMLInputElement> & ComponentProps, | ||
| ComponentState | ||
| > { | ||
| public static defaultProps = { | ||
| passRequiredToField: true, | ||
| }; | ||
|
|
||
| public state = { allowError: false }; | ||
|
|
||
| public componentDidMount() { | ||
| const { defaultValue, setValue } = this.props; | ||
| if (defaultValue) { | ||
| setValue(defaultValue); | ||
| } | ||
| } | ||
|
|
||
| public componentWillReceiveProps(nextProps: ComponentProps) { | ||
| if (nextProps.isFormSubmitted()) { | ||
| this.showError(); | ||
| } | ||
| } | ||
|
|
||
| public handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const { value } = e.currentTarget; | ||
| this.props.setValue(value); | ||
| if (this.props.onChange) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're requiring the parent to provide a function for this prop - is it a best practice in TS to check if a variable is falsey even if it's required?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad types on my part, they should be optional |
||
| this.props.onChange(e, e.currentTarget.value); | ||
| } | ||
| if (this.props.instantValidation) { | ||
| this.showError(); | ||
| } | ||
| }; | ||
|
|
||
| public handleBlur = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| this.showError(); | ||
| if (this.props.onBlur) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as in |
||
| 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, | ||
| } = 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() : []} | ||
| > | ||
| <EuiFieldText | ||
| id={id} | ||
| name={name} | ||
| value={getValue()} | ||
| isInvalid={!disabled && error} | ||
| onChange={this.handleChange} | ||
| onBlur={this.handleBlur} | ||
| fullWidth={fullWidth} | ||
| disabled={disabled} | ||
| required={required} | ||
| className={className} | ||
| /> | ||
| </EuiFormRow> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| export const FormsyEuiFieldText = withFormsy(FieldText); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make these optional - sorry, should have commented here before as well