[MM-56011] Migrated radio_setting.tsx from Class to Functional Component #25603 (#25668)

* Added cancel button in the delete category modal

* fix lint error

* fix eslint issues

* migrated from class to functional component

* updateCode

* used react.memo

* updateSnapshots

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Zubair Imtiaz
2023-12-18 05:26:57 +05:00
коммит произвёл GitHub
родитель 5c061a6f75
Коммит cd8796bf0b
4 изменённых файлов: 47 добавлений и 45 удалений

Просмотреть файл

@@ -288,7 +288,7 @@ exports[`components/MessageExportSettings should match snapshot, disabled, globa
<SettingsGroup
id="globalRelaySettings"
>
<RadioSetting
<Memo(RadioSetting)
disabled={true}
helpText={
<Memo(MemoizedFormattedMessage)
@@ -733,7 +733,7 @@ exports[`components/MessageExportSettings should match snapshot, enabled, global
<SettingsGroup
id="globalRelaySettings"
>
<RadioSetting
<Memo(RadioSetting)
disabled={false}
helpText={
<Memo(MemoizedFormattedMessage)

Просмотреть файл

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

Просмотреть файл

@@ -107,7 +107,7 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
]
}
/>
<RadioSetting
<Memo(RadioSetting)
disabled={false}
helpText={
<SchemaText
@@ -417,7 +417,7 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
]
}
/>
<RadioSetting
<Memo(RadioSetting)
disabled={false}
helpText={
<SchemaText

Просмотреть файл

@@ -15,47 +15,49 @@ interface Props {
helpText?: React.ReactNode;
onChange(id: string, value: any): void;
}
export default class RadioSetting extends React.PureComponent<Props> {
public static defaultProps: Partial<Props> = {
disabled: false,
const RadioSetting = ({
id,
label,
values,
value,
setByEnv,
disabled = false,
helpText,
onChange,
}: Props) => {
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange(id, e.target.value);
};
private handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
this.props.onChange(this.props.id, e.target.value);
};
const options = values.map(({value: optionValue, text}) => (
<div
className='radio'
key={optionValue}
>
<label>
<input
type='radio'
value={optionValue}
name={id}
checked={optionValue === value}
onChange={handleChange}
disabled={disabled || setByEnv}
/>
{text}
</label>
</div>
));
render(): JSX.Element {
const options = [];
for (const {value, text} of this.props.values) {
options.push(
<div
className='radio'
key={value}
>
<label>
<input
type='radio'
value={value}
name={this.props.id}
checked={value === this.props.value}
onChange={this.handleChange}
disabled={this.props.disabled || this.props.setByEnv}
/>
{text}
</label>
</div>,
);
}
return (
<Setting
label={label}
inputId={id}
helpText={helpText}
setByEnv={setByEnv}
>
{options}
</Setting>
);
};
return (
<Setting
label={this.props.label}
inputId={this.props.id}
helpText={this.props.helpText}
setByEnv={this.props.setByEnv}
>
{options}
</Setting>
);
}
}
export default React.memo(RadioSetting);