[MM-57722] Convert ./components/admin_console/team_channel_settings/group/group_list.tsx from Class Component to Function Component (#26721)

* [MM-57722] Convert `./components/admin_console/team_channel_settings/group/group_list.tsx` from Class Component to Function Component

* :refactor: improve code structure
This commit is contained in:
Syed Ali Abbas Zaidi 2024-04-24 13:11:40 +05:00 committed by GitHub
parent af8bcc4c6d
commit 8ba157f284
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 28 deletions

View File

@ -58,7 +58,7 @@ exports[`admin_console/team_channel_settings/channel/ChannelGroups should match
} }
} }
> >
<Connect(GroupList) <Connect(Component)
channel={ channel={
Object { Object {
"group_constrained": false, "group_constrained": false,

View File

@ -34,12 +34,9 @@ exports[`admin_console/team_channel_settings/group/GroupList should match snapsh
noPadding={false} noPadding={false}
onGroupRemoved={[MockFunction]} onGroupRemoved={[MockFunction]}
onPageChangedCallback={[MockFunction]} onPageChangedCallback={[MockFunction]}
removeGroup={[MockFunction]}
renderRow={[Function]} renderRow={[Function]}
setNewGroupRole={[MockFunction]}
total={1} total={1}
totalGroups={0} totalGroups={0}
type="team"
/> />
`; `;
@ -512,11 +509,8 @@ exports[`admin_console/team_channel_settings/group/GroupList should match snapsh
noPadding={false} noPadding={false}
onGroupRemoved={[MockFunction]} onGroupRemoved={[MockFunction]}
onPageChangedCallback={[MockFunction]} onPageChangedCallback={[MockFunction]}
removeGroup={[MockFunction]}
renderRow={[Function]} renderRow={[Function]}
setNewGroupRole={[MockFunction]}
total={30} total={30}
totalGroups={0} totalGroups={0}
type="team"
/> />
`; `;

View File

@ -38,7 +38,7 @@ describe('admin_console/team_channel_settings/group/GroupList', () => {
type='team' type='team'
setNewGroupRole={jest.fn()} setNewGroupRole={jest.fn()}
/>); />);
wrapper.setState({loading: false});
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
@ -71,7 +71,7 @@ describe('admin_console/team_channel_settings/group/GroupList', () => {
removeGroup={jest.fn()} removeGroup={jest.fn()}
setNewGroupRole={jest.fn()} setNewGroupRole={jest.fn()}
/>); />);
wrapper.setState({loading: false});
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
}); });

View File

@ -1,7 +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 React from 'react'; import React, {memo, useCallback} from 'react';
import {FormattedMessage} from 'react-intl'; import {FormattedMessage} from 'react-intl';
import type {Group} from '@mattermost/types/groups'; import type {Group} from '@mattermost/types/groups';
@ -42,27 +42,33 @@ const Header = () => {
type Props = OwnProps & PropsFromRedux; type Props = OwnProps & PropsFromRedux;
export default class GroupList extends React.PureComponent<Props> { const GroupList = ({
renderRow = (item: Partial<Group>) => { removeGroup,
setNewGroupRole,
type,
isDisabled,
...restProps
}: Props) => {
const renderRow = useCallback((item: Partial<Group>) => {
return ( return (
<GroupRow <GroupRow
key={item.id} key={item.id}
group={item} group={item}
removeGroup={this.props.removeGroup} removeGroup={removeGroup}
setNewGroupRole={this.props.setNewGroupRole} setNewGroupRole={setNewGroupRole}
type={this.props.type} type={type}
isDisabled={this.props.isDisabled} isDisabled={isDisabled}
/> />
); );
}; }, [isDisabled, removeGroup, setNewGroupRole, type]);
render(): JSX.Element {
return ( return (
<AbstractList <AbstractList
header={<Header/>} header={<Header/>}
renderRow={this.renderRow} renderRow={renderRow}
{...this.props} {...restProps}
/> />
); );
} };
}
export default memo(GroupList);

View File

@ -77,7 +77,7 @@ exports[`admin_console/team_channel_settings/team/TeamGroups should match snapsh
} }
} }
> >
<Connect(GroupList) <Connect(Component)
groups={ groups={
Array [ Array [
Object { Object {