migrate DropdownSetting component from class based to function based component (#24796)
* migrate DropdownSetting component to function comp * code optimized * snapshot updated * snapshot updated --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c5b43df163
Коммит
6f4d362f9f
@@ -72,7 +72,7 @@ exports[`components/MessageExportSettings should match snapshot, disabled, actia
|
|||||||
setByEnv={false}
|
setByEnv={false}
|
||||||
value="01:00"
|
value="01:00"
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={true}
|
disabled={true}
|
||||||
helpText={
|
helpText={
|
||||||
<FormattedMarkdownMessage
|
<FormattedMarkdownMessage
|
||||||
@@ -86,7 +86,6 @@ exports[`components/MessageExportSettings should match snapshot, disabled, actia
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="exportFormat"
|
id="exportFormat"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Export Format:"
|
defaultMessage="Export Format:"
|
||||||
@@ -246,7 +245,7 @@ exports[`components/MessageExportSettings should match snapshot, disabled, globa
|
|||||||
setByEnv={false}
|
setByEnv={false}
|
||||||
value="01:00"
|
value="01:00"
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={true}
|
disabled={true}
|
||||||
helpText={
|
helpText={
|
||||||
<FormattedMarkdownMessage
|
<FormattedMarkdownMessage
|
||||||
@@ -260,7 +259,6 @@ exports[`components/MessageExportSettings should match snapshot, disabled, globa
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="exportFormat"
|
id="exportFormat"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Export Format:"
|
defaultMessage="Export Format:"
|
||||||
@@ -515,7 +513,7 @@ exports[`components/MessageExportSettings should match snapshot, enabled, actian
|
|||||||
setByEnv={false}
|
setByEnv={false}
|
||||||
value="01:00"
|
value="01:00"
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<FormattedMarkdownMessage
|
<FormattedMarkdownMessage
|
||||||
@@ -529,7 +527,6 @@ exports[`components/MessageExportSettings should match snapshot, enabled, actian
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="exportFormat"
|
id="exportFormat"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Export Format:"
|
defaultMessage="Export Format:"
|
||||||
@@ -689,7 +686,7 @@ exports[`components/MessageExportSettings should match snapshot, enabled, global
|
|||||||
setByEnv={false}
|
setByEnv={false}
|
||||||
value="01:00"
|
value="01:00"
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<FormattedMarkdownMessage
|
<FormattedMarkdownMessage
|
||||||
@@ -703,7 +700,6 @@ exports[`components/MessageExportSettings should match snapshot, enabled, global
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="exportFormat"
|
id="exportFormat"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Export Format:"
|
defaultMessage="Export Format:"
|
||||||
|
|||||||
@@ -16,10 +16,9 @@ exports[`components/PushSettings should match snapshot, licensed 1`] = `
|
|||||||
/>
|
/>
|
||||||
</AdminHeader>
|
</AdminHeader>
|
||||||
<SettingsGroup>
|
<SettingsGroup>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
helpText={null}
|
helpText={null}
|
||||||
id="pushNotificationServerType"
|
id="pushNotificationServerType"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Enable Push Notifications: "
|
defaultMessage="Enable Push Notifications: "
|
||||||
@@ -50,9 +49,8 @@ exports[`components/PushSettings should match snapshot, licensed 1`] = `
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
id="pushNotificationServerLocation"
|
id="pushNotificationServerLocation"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Push Notification Server location:"
|
defaultMessage="Push Notification Server location:"
|
||||||
@@ -208,10 +206,9 @@ exports[`components/PushSettings should match snapshot, unlicensed 1`] = `
|
|||||||
/>
|
/>
|
||||||
</AdminHeader>
|
</AdminHeader>
|
||||||
<SettingsGroup>
|
<SettingsGroup>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
helpText={null}
|
helpText={null}
|
||||||
id="pushNotificationServerType"
|
id="pushNotificationServerType"
|
||||||
isDisabled={false}
|
|
||||||
label={
|
label={
|
||||||
<Memo(MemoizedFormattedMessage)
|
<Memo(MemoizedFormattedMessage)
|
||||||
defaultMessage="Enable Push Notifications: "
|
defaultMessage="Enable Push Notifications: "
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
|
|||||||
}
|
}
|
||||||
value={false}
|
value={false}
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<SchemaText
|
<SchemaText
|
||||||
@@ -121,7 +121,6 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="FirstSettings.settingc"
|
id="FirstSettings.settingc"
|
||||||
isDisabled={false}
|
|
||||||
key="Config_dropdown_FirstSettings.settingc"
|
key="Config_dropdown_FirstSettings.settingc"
|
||||||
label="Setting Three"
|
label="Setting Three"
|
||||||
onChange={[Function]}
|
onChange={[Function]}
|
||||||
@@ -269,7 +268,7 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<SchemaText
|
<SchemaText
|
||||||
@@ -279,7 +278,6 @@ exports[`components/admin_console/SchemaAdminSettings should match snapshot with
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="SecondSettings.settingi"
|
id="SecondSettings.settingi"
|
||||||
isDisabled={false}
|
|
||||||
key="Config_language_SecondSettings.settingi"
|
key="Config_language_SecondSettings.settingi"
|
||||||
label="Setting Nine"
|
label="Setting Nine"
|
||||||
onChange={[Function]}
|
onChange={[Function]}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
|
|||||||
}
|
}
|
||||||
value={true}
|
value={true}
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<SchemaText
|
<SchemaText
|
||||||
@@ -85,7 +85,6 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="settingc"
|
id="settingc"
|
||||||
isDisabled={false}
|
|
||||||
key="testplugin_dropdown_settingc"
|
key="testplugin_dropdown_settingc"
|
||||||
label="Setting Three"
|
label="Setting Three"
|
||||||
onChange={[Function]}
|
onChange={[Function]}
|
||||||
@@ -387,7 +386,7 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
|
|||||||
}
|
}
|
||||||
value={false}
|
value={false}
|
||||||
/>
|
/>
|
||||||
<DropdownSetting
|
<Memo(DropdownSetting)
|
||||||
disabled={false}
|
disabled={false}
|
||||||
helpText={
|
helpText={
|
||||||
<SchemaText
|
<SchemaText
|
||||||
@@ -396,7 +395,6 @@ exports[`components/admin_console/CustomPluginSettings should match snapshot wit
|
|||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
id="PluginSettings.Plugins.testplugin.settingc"
|
id="PluginSettings.Plugins.testplugin.settingc"
|
||||||
isDisabled={false}
|
|
||||||
key="testplugin_dropdown_PluginSettings.Plugins.testplugin.settingc"
|
key="testplugin_dropdown_PluginSettings.Plugins.testplugin.settingc"
|
||||||
label="Setting Three"
|
label="Setting Three"
|
||||||
onChange={[Function]}
|
onChange={[Function]}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import PropTypes from 'prop-types';
|
import React, {memo, useCallback, useMemo} from 'react';
|
||||||
import React, {PureComponent} from 'react';
|
|
||||||
import type {ReactNode, ChangeEvent} from 'react';
|
import type {ReactNode, ChangeEvent} from 'react';
|
||||||
|
|
||||||
import type {EmailSettings} from '@mattermost/types/config';
|
import type {EmailSettings} from '@mattermost/types/config';
|
||||||
@@ -20,57 +19,49 @@ type Props = {
|
|||||||
helpText?: ReactNode;
|
helpText?: ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class DropdownSetting extends PureComponent<Props> {
|
const DropdownSetting = ({
|
||||||
static propTypes = {
|
id,
|
||||||
id: PropTypes.string.isRequired,
|
values,
|
||||||
values: PropTypes.array.isRequired,
|
label,
|
||||||
label: PropTypes.node.isRequired,
|
value,
|
||||||
value: PropTypes.string.isRequired,
|
onChange,
|
||||||
onChange: PropTypes.func.isRequired,
|
disabled = false,
|
||||||
disabled: PropTypes.bool,
|
setByEnv,
|
||||||
setByEnv: PropTypes.bool.isRequired,
|
helpText,
|
||||||
helpText: PropTypes.node,
|
}: Props) => {
|
||||||
};
|
const handleChange = useCallback((e: ChangeEvent<HTMLSelectElement>) => {
|
||||||
|
onChange(id, e.target.value);
|
||||||
|
}, [onChange, id]);
|
||||||
|
|
||||||
static defaultProps = {
|
const options = useMemo(() =>
|
||||||
isDisabled: false,
|
values.map(({value: val, text}) => (
|
||||||
};
|
<option
|
||||||
|
value={val}
|
||||||
handleChange = (e: ChangeEvent<HTMLSelectElement>) => {
|
key={val}
|
||||||
this.props.onChange(this.props.id, e.target.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const options = [];
|
|
||||||
for (const {value, text} of this.props.values) {
|
|
||||||
options.push(
|
|
||||||
<option
|
|
||||||
value={value}
|
|
||||||
key={value}
|
|
||||||
>
|
|
||||||
{text}
|
|
||||||
</option>,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Setting
|
|
||||||
label={this.props.label}
|
|
||||||
inputId={this.props.id}
|
|
||||||
helpText={this.props.helpText}
|
|
||||||
setByEnv={this.props.setByEnv}
|
|
||||||
>
|
>
|
||||||
<select
|
{text}
|
||||||
data-testid={this.props.id + 'dropdown'}
|
</option>
|
||||||
className='form-control'
|
)), [values]);
|
||||||
id={this.props.id}
|
|
||||||
value={this.props.value}
|
return (
|
||||||
onChange={this.handleChange}
|
<Setting
|
||||||
disabled={this.props.disabled || this.props.setByEnv}
|
label={label}
|
||||||
>
|
inputId={id}
|
||||||
{options}
|
helpText={helpText}
|
||||||
</select>
|
setByEnv={setByEnv}
|
||||||
</Setting>
|
>
|
||||||
);
|
<select
|
||||||
}
|
data-testid={id + 'dropdown'}
|
||||||
}
|
className='form-control'
|
||||||
|
id={id}
|
||||||
|
value={value}
|
||||||
|
onChange={handleChange}
|
||||||
|
disabled={disabled || setByEnv}
|
||||||
|
>
|
||||||
|
{options}
|
||||||
|
</select>
|
||||||
|
</Setting>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(DropdownSetting);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user