[MM-54816] Convert ./components/admin_console/color_setting.tsx from Class Component to Function Component (#24963)

* Convert class component to function component

* Apply changes from suggestions

* Lint check

* Update schema_admin_settings.test.jsx.snap

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
This commit is contained in:
Rohit Chaudhari
2023-11-06 17:12:55 +05:30
committed by GitHub
parent 486e836b83
commit 2f86b1ffd7
2 changed files with 24 additions and 24 deletions

View File

@@ -595,7 +595,7 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
}
value={true}
/>
<ColorSetting
<Memo(ColorSetting)
disabled={false}
helpText={
<SchemaText

View File

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import React from 'react';
import React, {useCallback} from 'react';
import ColorInput from 'components/color_input';
@@ -16,27 +16,27 @@ type Props = {
disabled?: boolean;
}
export default class ColorSetting extends React.PureComponent<Props> {
private handleChange = (color: string) => {
if (this.props.onChange) {
this.props.onChange(this.props.id, color);
const ColorSetting = (props: Props) => {
const handleChange = useCallback((color: string) => {
if (props.onChange) {
props.onChange(props.id, color);
}
};
}, [props.id, props.onChange]);
public render() {
return (
<Setting
label={this.props.label}
helpText={this.props.helpText}
inputId={this.props.id}
>
<ColorInput
id={this.props.id}
value={this.props.value}
onChange={this.handleChange}
isDisabled={this.props.disabled}
/>
</Setting>
);
}
}
return (
<Setting
label={props.label}
helpText={props.helpText}
inputId={props.id}
>
<ColorInput
id={props.id}
value={props.value}
onChange={handleChange}
isDisabled={props.disabled}
/>
</Setting>
);
};
export default React.memo(ColorSetting);