[MM-57709] Convert ./components/channel_select/channel_select.tsx from Class Component to Function Component (#26718)

Этот коммит содержится в:
Syed Ali Abbas Zaidi
2024-04-12 02:54:35 +05:00
коммит произвёл GitHub
родитель 8589476229
Коммит 165b5ea821
3 изменённых файлов: 74 добавлений и 62 удалений

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

@@ -1,13 +1,13 @@
// 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 React from 'react'; import React, {memo} from 'react';
import type {ChangeEventHandler} from 'react'; import type {ChangeEventHandler} from 'react';
import {useIntl} from 'react-intl';
import type {Channel} from '@mattermost/types/channels'; import type {Channel} from '@mattermost/types/channels';
import Constants from 'utils/constants'; import Constants from 'utils/constants';
import * as Utils from 'utils/utils';
type Props = { type Props = {
channels: Channel[]; channels: Channel[];
@@ -18,20 +18,31 @@ type Props = {
selectDm: boolean; selectDm: boolean;
}; };
export default class ChannelSelect extends React.PureComponent<Props> { const ChannelSelect = ({
render(): JSX.Element { channels,
selectOpen,
selectPrivate,
selectDm,
value,
onChange,
}: Props) => {
const intl = useIntl();
const options = [ const options = [
<option <option
key='' key=''
value='' value=''
> >
{Utils.localizeMessage('channel_select.placeholder', '--- Select a channel ---')} {intl.formatMessage({
id: 'channel_select.placeholder',
defaultMessage: '--- Select a channel ---',
})}
</option>, </option>,
]; ];
this.props.channels.forEach((channel: Channel) => { channels.forEach((channel: Channel) => {
const channelName = channel.display_name || channel.name; const channelName = channel.display_name || channel.name;
if (channel.type === Constants.OPEN_CHANNEL && this.props.selectOpen) { if (channel.type === Constants.OPEN_CHANNEL && selectOpen) {
options.push( options.push(
<option <option
key={channel.id} key={channel.id}
@@ -40,7 +51,7 @@ export default class ChannelSelect extends React.PureComponent<Props> {
{channelName} {channelName}
</option>, </option>,
); );
} else if (channel.type === Constants.PRIVATE_CHANNEL && this.props.selectPrivate) { } else if (channel.type === Constants.PRIVATE_CHANNEL && selectPrivate) {
options.push( options.push(
<option <option
key={channel.id} key={channel.id}
@@ -49,7 +60,7 @@ export default class ChannelSelect extends React.PureComponent<Props> {
{channelName} {channelName}
</option>, </option>,
); );
} else if (channel.type === Constants.DM_CHANNEL && this.props.selectDm) { } else if (channel.type === Constants.DM_CHANNEL && selectDm) {
options.push( options.push(
<option <option
key={channel.id} key={channel.id}
@@ -64,12 +75,13 @@ export default class ChannelSelect extends React.PureComponent<Props> {
return ( return (
<select <select
className='form-control' className='form-control'
value={this.props.value} value={value}
onChange={this.props.onChange} onChange={onChange}
id='channelSelect' id='channelSelect'
> >
{options} {options}
</select> </select>
); );
} };
}
export default memo(ChannelSelect);

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

@@ -106,7 +106,7 @@ exports[`components/integrations/AbstractIncomingWebhook should call action func
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}
@@ -367,7 +367,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot 1
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}
@@ -628,7 +628,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}
@@ -892,7 +892,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}
@@ -1120,7 +1120,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}
@@ -1348,7 +1348,7 @@ exports[`components/integrations/AbstractIncomingWebhook should match snapshot,
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}

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

@@ -163,7 +163,7 @@ exports[`components/integrations/AbstractOutgoingWebhook should match snapshot 1
<div <div
className="col-md-5 col-sm-8" className="col-md-5 col-sm-8"
> >
<Connect(ChannelSelect) <Connect(Component)
onChange={[Function]} onChange={[Function]}
selectDm={false} selectDm={false}
selectOpen={true} selectOpen={true}