[MM-57709] Convert ./components/channel_select/channel_select.tsx from Class Component to Function Component (#26718)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
8589476229
Коммит
165b5ea821
@@ -1,13 +1,13 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
import React, {memo} from 'react';
|
||||
import type {ChangeEventHandler} from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
|
||||
import type {Channel} from '@mattermost/types/channels';
|
||||
|
||||
import Constants from 'utils/constants';
|
||||
import * as Utils from 'utils/utils';
|
||||
|
||||
type Props = {
|
||||
channels: Channel[];
|
||||
@@ -18,58 +18,70 @@ type Props = {
|
||||
selectDm: boolean;
|
||||
};
|
||||
|
||||
export default class ChannelSelect extends React.PureComponent<Props> {
|
||||
render(): JSX.Element {
|
||||
const options = [
|
||||
<option
|
||||
key=''
|
||||
value=''
|
||||
>
|
||||
{Utils.localizeMessage('channel_select.placeholder', '--- Select a channel ---')}
|
||||
</option>,
|
||||
];
|
||||
const ChannelSelect = ({
|
||||
channels,
|
||||
selectOpen,
|
||||
selectPrivate,
|
||||
selectDm,
|
||||
value,
|
||||
onChange,
|
||||
}: Props) => {
|
||||
const intl = useIntl();
|
||||
|
||||
this.props.channels.forEach((channel: Channel) => {
|
||||
const channelName = channel.display_name || channel.name;
|
||||
if (channel.type === Constants.OPEN_CHANNEL && this.props.selectOpen) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
} else if (channel.type === Constants.PRIVATE_CHANNEL && this.props.selectPrivate) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
} else if (channel.type === Constants.DM_CHANNEL && this.props.selectDm) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
}
|
||||
});
|
||||
const options = [
|
||||
<option
|
||||
key=''
|
||||
value=''
|
||||
>
|
||||
{intl.formatMessage({
|
||||
id: 'channel_select.placeholder',
|
||||
defaultMessage: '--- Select a channel ---',
|
||||
})}
|
||||
</option>,
|
||||
];
|
||||
|
||||
return (
|
||||
<select
|
||||
className='form-control'
|
||||
value={this.props.value}
|
||||
onChange={this.props.onChange}
|
||||
id='channelSelect'
|
||||
>
|
||||
{options}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
}
|
||||
channels.forEach((channel: Channel) => {
|
||||
const channelName = channel.display_name || channel.name;
|
||||
if (channel.type === Constants.OPEN_CHANNEL && selectOpen) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
} else if (channel.type === Constants.PRIVATE_CHANNEL && selectPrivate) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
} else if (channel.type === Constants.DM_CHANNEL && selectDm) {
|
||||
options.push(
|
||||
<option
|
||||
key={channel.id}
|
||||
value={channel.id}
|
||||
>
|
||||
{channelName}
|
||||
</option>,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<select
|
||||
className='form-control'
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
id='channelSelect'
|
||||
>
|
||||
{options}
|
||||
</select>
|
||||
);
|
||||
};
|
||||
|
||||
export default memo(ChannelSelect);
|
||||
|
||||
@@ -106,7 +106,7 @@ exports[`components/integrations/AbstractIncomingWebhook should call action func
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
@@ -367,7 +367,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot 1
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
@@ -628,7 +628,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
@@ -892,7 +892,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
@@ -1120,7 +1120,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
@@ -1348,7 +1348,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
|
||||
@@ -163,7 +163,7 @@ exports[`components/integrations/AbstractOutgoingWebhook should match snapshot 1
|
||||
<div
|
||||
className="col-md-5 col-sm-8"
|
||||
>
|
||||
<Connect(ChannelSelect)
|
||||
<Connect(Component)
|
||||
onChange={[Function]}
|
||||
selectDm={false}
|
||||
selectOpen={true}
|
||||
|
||||
Ссылка в новой задаче
Block a user