Skip to content

Commit 8ef1e43

Browse files
Remove depricated registerPostDropdownMenuComponent (#921)
* Remove depricated registerPostDropdownMenuComponent * Fix deprecated hook replacement * updated the component * use store to dispatch function
1 parent 0deffcf commit 8ef1e43

File tree

5 files changed

+50
-145
lines changed

5 files changed

+50
-145
lines changed
Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,15 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4-
import React, {PureComponent} from 'react';
5-
import PropTypes from 'prop-types';
4+
import React from 'react';
65

76
import GitHubIcon from '../../icon';
87

9-
export default class CreateIssuePostMenuAction extends PureComponent {
10-
static propTypes = {
11-
show: PropTypes.bool.isRequired,
12-
open: PropTypes.func.isRequired,
13-
postId: PropTypes.string,
14-
};
15-
16-
static defaultTypes = {
17-
locale: 'en',
18-
};
19-
20-
handleClick = (e) => {
21-
const {open, postId} = this.props;
22-
e.preventDefault();
23-
open(postId);
24-
};
25-
26-
render() {
27-
if (!this.props.show) {
28-
return null;
29-
}
30-
31-
const content = (
32-
<button
33-
className='style--none'
34-
role='presentation'
35-
onClick={this.handleClick}
36-
>
37-
<GitHubIcon type='menu'/>
38-
{'Create GitHub Issue'}
39-
</button>
40-
);
41-
42-
return (
43-
<li
44-
className='MenuItem'
45-
role='menuitem'
46-
>
47-
{content}
48-
</li>
49-
);
50-
}
8+
export default function CreateIssuePostMenuAction() {
9+
return (
10+
<>
11+
<GitHubIcon type='menu'/>
12+
{'Create GitHub Issue'}
13+
</>
14+
);
5115
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4-
import {connect} from 'react-redux';
5-
import {bindActionCreators} from 'redux';
6-
import {getPost} from 'mattermost-redux/selectors/entities/posts';
7-
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
8-
9-
import manifest from '@/manifest';
10-
11-
import {openCreateIssueModal} from '@/actions';
12-
134
import CreateIssuePostMenuAction from './create_issue';
145

15-
const mapStateToProps = (state, ownProps) => {
16-
const post = getPost(state, ownProps.postId);
17-
const systemMessage = post ? isSystemMessage(post) : true;
18-
19-
return {
20-
show: state[`plugins-${manifest.id}`].connected && !systemMessage,
21-
};
22-
};
23-
24-
const mapDispatchToProps = (dispatch) => bindActionCreators({
25-
open: openCreateIssueModal,
26-
}, dispatch);
27-
28-
export default connect(mapStateToProps, mapDispatchToProps)(CreateIssuePostMenuAction);
6+
export default CreateIssuePostMenuAction;
Lines changed: 8 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,15 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4-
import React, {PureComponent} from 'react';
5-
import PropTypes from 'prop-types';
4+
import React from 'react';
65

7-
import manifest from '../../../manifest';
86
import GitHubIcon from '../../icon';
97

10-
export default class AttachCommentToIssuePostMenuAction extends PureComponent {
11-
static propTypes = {
12-
isSystemMessage: PropTypes.bool.isRequired,
13-
open: PropTypes.func.isRequired,
14-
postId: PropTypes.string,
15-
connected: PropTypes.bool.isRequired,
16-
};
17-
18-
static defaultTypes = {
19-
locale: 'en',
20-
};
21-
22-
handleClick = (e) => {
23-
const {open, postId} = this.props;
24-
e.preventDefault();
25-
open(postId);
26-
};
27-
28-
connectClick = () => {
29-
window.open('/plugins/' + manifest.id + '/user/connect', '_blank');
30-
};
31-
32-
render() {
33-
if (this.props.isSystemMessage || !this.props.connected) {
34-
return null;
35-
}
36-
37-
const content = (
38-
<button
39-
className='style--none'
40-
role='presentation'
41-
onClick={this.handleClick}
42-
>
43-
<GitHubIcon type='menu'/>
44-
{'Attach to GitHub Issue'}
45-
</button>
46-
);
47-
48-
return (
49-
<li
50-
className='MenuItem'
51-
role='menuitem'
52-
>
53-
{content}
54-
</li>
55-
);
56-
}
8+
export default function AttachCommentToIssuePostMenuAction() {
9+
return (
10+
<>
11+
<GitHubIcon type='menu'/>
12+
{'Attach to GitHub Issue'}
13+
</>
14+
);
5715
}
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
3-
4-
import {connect} from 'react-redux';
5-
import {bindActionCreators} from 'redux';
6-
import {getPost} from 'mattermost-redux/selectors/entities/posts';
7-
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
8-
9-
import manifest from '@/manifest';
10-
11-
import {openAttachCommentToIssueModal} from '@/actions';
12-
133
import AttachCommentToIssuePostMenuAction from './attach_comment_to_issue';
144

15-
const mapStateToProps = (state, ownProps) => {
16-
const post = getPost(state, ownProps.postId);
17-
const systemMessage = post ? isSystemMessage(post) : true;
18-
19-
return {
20-
isSystemMessage: systemMessage,
21-
connected: state[`plugins-${manifest.id}`].connected,
22-
};
23-
};
24-
25-
const mapDispatchToProps = (dispatch) => bindActionCreators({
26-
open: openAttachCommentToIssueModal,
27-
}, dispatch);
28-
29-
export default connect(mapStateToProps, mapDispatchToProps)(AttachCommentToIssuePostMenuAction);
5+
export default AttachCommentToIssuePostMenuAction;

webapp/src/index.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4+
import {getPost} from 'mattermost-redux/selectors/entities/posts';
5+
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
6+
47
import AttachCommentToIssuePostMenuAction from '@/components/post_menu_actions/attach_comment_to_issue';
58
import AttachCommentToIssueModal from '@/components/modals/attach_comment_to_issue';
69

10+
import {getConnected, openAttachCommentToIssueModal, openCreateIssueModal, setShowRHSAction} from '@/actions';
11+
712
import CreateIssueModal from './components/modals/create_issue';
813
import CreateIssuePostMenuAction from './components/post_menu_action/create_issue';
914
import SidebarHeader from './components/sidebar_header';
@@ -13,7 +18,7 @@ import SidebarRight from './components/sidebar_right';
1318
import LinkTooltip from './components/link_tooltip';
1419
import Reducer from './reducers';
1520
import Client from './client';
16-
import {getConnected, setShowRHSAction} from './actions';
21+
1722
import {handleConnect, handleDisconnect, handleConfigurationUpdate, handleOpenCreateIssueModal, handleReconnect, handleRefresh} from './websocket';
1823
import {getServerRoute} from './selectors';
1924
import manifest from './manifest';
@@ -34,9 +39,33 @@ class PluginClass {
3439
registry.registerBottomTeamSidebarComponent(TeamSidebar);
3540
registry.registerPopoverUserAttributesComponent(UserAttribute);
3641
registry.registerRootComponent(CreateIssueModal);
37-
registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction);
42+
registry.registerPostDropdownMenuAction({
43+
text: CreateIssuePostMenuAction,
44+
action: (postId) => {
45+
store.dispatch(openCreateIssueModal(postId));
46+
},
47+
filter: (postId) => {
48+
const state = store.getState();
49+
const post = getPost(state, postId);
50+
const systemMessage = post ? isSystemMessage(post) : true;
51+
52+
return state[`plugins-${manifest.id}`].connected && !systemMessage;
53+
},
54+
});
3855
registry.registerRootComponent(AttachCommentToIssueModal);
39-
registry.registerPostDropdownMenuComponent(AttachCommentToIssuePostMenuAction);
56+
registry.registerPostDropdownMenuAction({
57+
text: AttachCommentToIssuePostMenuAction,
58+
action: (postId) => {
59+
store.dispatch(openAttachCommentToIssueModal(postId));
60+
},
61+
filter: (postId) => {
62+
const state = store.getState();
63+
const post = getPost(state, postId);
64+
const systemMessage = post ? isSystemMessage(post) : true;
65+
66+
return state[`plugins-${manifest.id}`].connected && !systemMessage;
67+
},
68+
});
4069
registry.registerLinkTooltipComponent(LinkTooltip);
4170

4271
const {showRHSPlugin} = registry.registerRightHandSidebarComponent(SidebarRight, 'GitHub');

0 commit comments

Comments
 (0)