diff --git a/web-console/script/mkcomp b/web-console/script/mkcomp index 01a15091c25..6faf4e132ce 100755 --- a/web-console/script/mkcomp +++ b/web-console/script/mkcomp @@ -79,8 +79,6 @@ writeFile( * limitations under the License. */ -import { IconNames } from '@blueprintjs/icons'; -import classNames from 'classnames'; import React from 'react'; import './${name}.scss'; @@ -88,22 +86,13 @@ import './${name}.scss'; export interface ${camelName}Props { } -export interface ${camelName}State { -} - -export class ${camelName} extends React.PureComponent<${camelName}Props, ${camelName}State> { - constructor(props: ${camelName}Props, context: any) { - super(props, context); - // this.state = {}; - - } - - render(): JSX.Element { - return
+export const ${camelName} = React.memo(function ${camelName}(props: ${camelName}Props) { + return ( +
Stuff... -
; - } -} +
+ ); +}); `, ); diff --git a/web-console/src/components/array-input/array-input.tsx b/web-console/src/components/array-input/array-input.tsx index de4fbd07fb5..02b0f12beb3 100644 --- a/web-console/src/components/array-input/array-input.tsx +++ b/web-console/src/components/array-input/array-input.tsx @@ -17,7 +17,7 @@ */ import { Intent, TextArea } from '@blueprintjs/core'; -import React from 'react'; +import React, { useState } from 'react'; import { compact } from '../../utils'; @@ -31,40 +31,33 @@ export interface ArrayInputProps { intent?: Intent; } -export class ArrayInput extends React.PureComponent { - constructor(props: ArrayInputProps) { - super(props); - this.state = { - stringValue: Array.isArray(props.values) ? props.values.join(', ') : '', - }; - } +export const ArrayInput = React.memo(function ArrayInput(props: ArrayInputProps) { + const { className, placeholder, large, disabled, intent } = props; + const [stringValue, setStringValue] = useState(); - private handleChange = (e: any) => { - const { onChange } = this.props; + const handleChange = (e: any) => { + const { onChange } = props; const stringValue = e.target.value; - const newValues: string[] = stringValue.split(',').map((v: string) => v.trim()); + const newValues: string[] = stringValue.split(/[,\s]+/).map((v: string) => v.trim()); const newValuesFiltered = compact(newValues); - this.setState({ - stringValue: - newValues.length === newValuesFiltered.length ? newValues.join(', ') : stringValue, - }); - if (onChange) onChange(stringValue === '' ? undefined : newValuesFiltered); + if (newValues.length === newValuesFiltered.length) { + onChange(stringValue === '' ? undefined : newValuesFiltered); + setStringValue(undefined); + } else { + setStringValue(stringValue); + } }; - render(): JSX.Element { - const { className, placeholder, large, disabled, intent } = this.props; - const { stringValue } = this.state; - return ( -