[MM-57721] Convert ./components/channel_header_dropdown/menu_items/leave_channel/leave_channel.tsx from Class Component to Function Component (#26722)
* [MM-57721] Convert `./components/channel_header_dropdown/menu_items/leave_channel/leave_channel.tsx` from Class Component to Function Component * fix failing tests --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
bca4535150
Коммит
ede18a7c17
@@ -643,7 +643,7 @@ exports[`components/ChannelHeaderDropdown should match snapshot with no plugin i
|
|||||||
text="Convert to Private Channel"
|
text="Convert to Private Channel"
|
||||||
/>
|
/>
|
||||||
</Connect(Component)>
|
</Connect(Component)>
|
||||||
<Connect(LeaveChannel)
|
<Connect(Component)
|
||||||
channel={
|
channel={
|
||||||
Object {
|
Object {
|
||||||
"create_at": 0,
|
"create_at": 0,
|
||||||
@@ -1475,7 +1475,7 @@ exports[`components/ChannelHeaderDropdown should match snapshot with plugins 1`]
|
|||||||
text="Convert to Private Channel"
|
text="Convert to Private Channel"
|
||||||
/>
|
/>
|
||||||
</Connect(Component)>
|
</Connect(Component)>
|
||||||
<Connect(LeaveChannel)
|
<Connect(Component)
|
||||||
channel={
|
channel={
|
||||||
Object {
|
Object {
|
||||||
"create_at": 0,
|
"create_at": 0,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('components/ChannelHeaderDropdown/MenuItem.LeaveChannel', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
it('should match snapshot', () => {
|
it('should match snapshot', () => {
|
||||||
const wrapper = shallow<LeaveChannel>(<LeaveChannel {...baseProps}/>);
|
const wrapper = shallow(<LeaveChannel {...baseProps}/>);
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ describe('components/ChannelHeaderDropdown/MenuItem.LeaveChannel', () => {
|
|||||||
...baseProps,
|
...baseProps,
|
||||||
isDefault: true,
|
isDefault: true,
|
||||||
};
|
};
|
||||||
const wrapper = shallow<LeaveChannel>(<LeaveChannel {...props}/>);
|
const wrapper = shallow(<LeaveChannel {...props}/>);
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,7 +59,7 @@ describe('components/ChannelHeaderDropdown/MenuItem.LeaveChannel', () => {
|
|||||||
channel: {...baseProps.channel},
|
channel: {...baseProps.channel},
|
||||||
actions: {...baseProps.actions},
|
actions: {...baseProps.actions},
|
||||||
};
|
};
|
||||||
const wrapper = shallow<LeaveChannel>(<LeaveChannel {...props}/>);
|
const wrapper = shallow(<LeaveChannel {...props}/>);
|
||||||
|
|
||||||
wrapper.find(Menu.ItemAction).simulate('click', {
|
wrapper.find(Menu.ItemAction).simulate('click', {
|
||||||
preventDefault: jest.fn(),
|
preventDefault: jest.fn(),
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
// 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, useCallback} from 'react';
|
||||||
|
import {useIntl} from 'react-intl';
|
||||||
|
|
||||||
import type {Channel} from '@mattermost/types/channels';
|
import type {Channel} from '@mattermost/types/channels';
|
||||||
|
|
||||||
@@ -9,7 +10,6 @@ import LeaveChannelModal from 'components/leave_channel_modal';
|
|||||||
import Menu from 'components/widgets/menu/menu';
|
import Menu from 'components/widgets/menu/menu';
|
||||||
|
|
||||||
import {Constants, ModalIdentifiers} from 'utils/constants';
|
import {Constants, ModalIdentifiers} from 'utils/constants';
|
||||||
import {localizeMessage} from 'utils/utils';
|
|
||||||
|
|
||||||
import type {PropsFromRedux} from './index';
|
import type {PropsFromRedux} from './index';
|
||||||
|
|
||||||
@@ -36,23 +36,21 @@ interface Props extends PropsFromRedux {
|
|||||||
id?: string;
|
id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class LeaveChannel extends React.PureComponent<Props> {
|
const LeaveChannel = ({
|
||||||
static defaultProps = {
|
isDefault = true,
|
||||||
isDefault: true,
|
isGuestUser = false,
|
||||||
isGuestUser: false,
|
channel,
|
||||||
};
|
actions: {
|
||||||
|
leaveChannel,
|
||||||
|
openModal,
|
||||||
|
},
|
||||||
|
id,
|
||||||
|
}: Props) => {
|
||||||
|
const intl = useIntl();
|
||||||
|
|
||||||
handleLeave = (e: Event) => {
|
const handleLeave = useCallback((e: Event) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const {
|
|
||||||
channel,
|
|
||||||
actions: {
|
|
||||||
leaveChannel,
|
|
||||||
openModal,
|
|
||||||
},
|
|
||||||
} = this.props;
|
|
||||||
|
|
||||||
if (channel.type === Constants.PRIVATE_CHANNEL) {
|
if (channel.type === Constants.PRIVATE_CHANNEL) {
|
||||||
openModal({
|
openModal({
|
||||||
modalId: ModalIdentifiers.LEAVE_PRIVATE_CHANNEL_MODAL,
|
modalId: ModalIdentifiers.LEAVE_PRIVATE_CHANNEL_MODAL,
|
||||||
@@ -64,19 +62,17 @@ export default class LeaveChannel extends React.PureComponent<Props> {
|
|||||||
} else {
|
} else {
|
||||||
leaveChannel(channel.id);
|
leaveChannel(channel.id);
|
||||||
}
|
}
|
||||||
};
|
}, [channel, leaveChannel, openModal]);
|
||||||
|
|
||||||
render() {
|
return (
|
||||||
const {channel, isDefault, isGuestUser, id} = this.props;
|
<Menu.ItemAction
|
||||||
|
id={id}
|
||||||
|
show={(!isDefault || isGuestUser) && channel.type !== Constants.DM_CHANNEL && channel.type !== Constants.GM_CHANNEL}
|
||||||
|
onClick={handleLeave}
|
||||||
|
text={intl.formatMessage({id: 'channel_header.leave', defaultMessage: 'Leave Channel'})}
|
||||||
|
isDangerous={true}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
export default memo(LeaveChannel);
|
||||||
<Menu.ItemAction
|
|
||||||
id={id}
|
|
||||||
show={(!isDefault || isGuestUser) && channel.type !== Constants.DM_CHANNEL && channel.type !== Constants.GM_CHANNEL}
|
|
||||||
onClick={this.handleLeave}
|
|
||||||
text={localizeMessage('channel_header.leave', 'Leave Channel')}
|
|
||||||
isDangerous={true}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user