Skip to content

Commit aa3e3ae

Browse files
Remove depricated registerPostDropdownMenuComponent (#599)
* Remove depricated registerPostDropdownMenuComponent * Updated the component * update filter function * removed unused comments * use store to dispatch action * removed unused dependency
1 parent c8b3165 commit aa3e3ae

File tree

4 files changed

+43
-104
lines changed

4 files changed

+43
-104
lines changed

webapp/src/components/post_options/attach_comment_to_issue.tsx

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,16 @@
11
// Copyright (c) 2019-present Mattermost, Inc. All Rights Reserved.
22
// See LICENSE.txt for license information.
33

4-
import React, {MouseEvent} from 'react';
5-
import PropTypes from 'prop-types';
6-
import {useDispatch, useSelector} from 'react-redux';
7-
import {getPost} from 'mattermost-redux/selectors/entities/posts';
8-
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
4+
import React from 'react';
95

106
import GitLabIcon from 'src/images/icons/gitlab';
11-
import {openAttachCommentToIssueModal} from 'src/actions';
12-
import {getConnected} from 'src/selectors';
13-
import {GlobalState} from 'src/types/store';
147

15-
interface PropTypes {
16-
postId: string;
17-
}
18-
19-
const AttachCommentToIssuePostMenuAction = ({postId}: PropTypes) => {
20-
const {show} = useSelector((state: GlobalState) => {
21-
const post = getPost(state, postId);
22-
const isPostSystemMessage = Boolean(!post || isSystemMessage(post));
23-
24-
return {
25-
show: getConnected(state) && !isPostSystemMessage,
26-
};
27-
});
28-
29-
const dispatch = useDispatch();
30-
31-
const handleClick = (e: MouseEvent<HTMLButtonElement> | Event) => {
32-
e.preventDefault();
33-
dispatch(openAttachCommentToIssueModal(postId));
34-
};
35-
36-
if (!show) {
37-
return null;
38-
}
39-
40-
const content = (
41-
<button
42-
className='style--none'
43-
role='presentation'
44-
onClick={handleClick}
45-
>
8+
const AttachCommentToIssuePostMenuAction = () => {
9+
return (
10+
<>
4611
<GitLabIcon type='menu'/>
4712
{'Attach to GitLab Issue'}
48-
</button>
49-
);
50-
51-
return (
52-
<li
53-
className='MenuItem'
54-
role='menuitem'
55-
>
56-
{content}
57-
</li>
13+
</>
5814
);
5915
};
6016

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

4-
import React, {MouseEvent} from 'react';
5-
import {useDispatch, useSelector} from 'react-redux';
6-
import {getPost} from 'mattermost-redux/selectors/entities/posts';
7-
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
4+
import React from 'react';
85

96
import GitLabIcon from 'src/images/icons/gitlab';
10-
import {openCreateIssueModal} from 'src/actions';
11-
import {getConnected} from 'src/selectors';
12-
import {GlobalState} from 'src/types/store';
137

14-
type PropTypes = {
15-
postId: string;
16-
}
17-
18-
const CreateIssuePostMenuAction = ({postId}: PropTypes) => {
19-
const {show} = useSelector((state: GlobalState) => {
20-
const post = getPost(state, postId);
21-
const isPostSystemMessage = Boolean(!post || isSystemMessage(post));
22-
23-
return {
24-
show: getConnected(state) && !isPostSystemMessage,
25-
};
26-
});
27-
28-
const dispatch = useDispatch();
29-
30-
const handleClick = (e: MouseEvent<HTMLButtonElement> | Event) => {
31-
e.preventDefault();
32-
dispatch(openCreateIssueModal(postId));
33-
};
34-
35-
if (!show) {
36-
return null;
37-
}
38-
39-
const content = (
40-
<button
41-
className='style--none'
42-
role='presentation'
43-
onClick={handleClick}
44-
>
8+
export default function CreateIssuePostMenuAction(): JSX.Element {
9+
return (
10+
<>
4511
<GitLabIcon type='menu'/>
4612
{'Create GitLab Issue'}
47-
</button>
48-
);
49-
50-
return (
51-
<li
52-
className='MenuItem'
53-
role='menuitem'
54-
>
55-
{content}
56-
</li>
13+
</>
5714
);
58-
};
59-
60-
export default CreateIssuePostMenuAction;
15+
}

webapp/src/index.ts

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import {getConfig} from 'mattermost-redux/selectors/entities/general';
55
import {Store, Action} from 'redux';
66

7+
import {getPost} from 'mattermost-redux/selectors/entities/posts';
8+
import {isSystemMessage} from 'mattermost-redux/utils/post_utils';
9+
10+
import {getConnected as getConnectedState, getPluginServerRoute} from './selectors';
711
import SidebarHeader from './components/sidebar_header';
812
import TeamSidebar from './components/team_sidebar';
913
import RHSSidebar from './components/rhs_sidebar';
@@ -18,7 +22,7 @@ import LinkTooltip from './components/link_tooltip';
1822
import {GlobalState} from './types/store';
1923

2024
import Reducer from './reducers';
21-
import {getConnected, setShowRHSAction} from './actions';
25+
import {getConnected, openAttachCommentToIssueModal, openCreateIssueModal, setShowRHSAction} from './actions';
2226
import {
2327
handleConnect,
2428
handleDisconnect,
@@ -29,7 +33,6 @@ import {
2933
} from './websocket';
3034
import manifest from './manifest';
3135
import Client from './client';
32-
import {getPluginServerRoute} from './selectors';
3336
import Hooks from './hooks';
3437

3538
import {FormatTextOptions, MessageHtmlToComponentOptions, PluginRegistry} from './types/mattermost-webapp';
@@ -52,9 +55,33 @@ class PluginClass {
5255
registry.registerBottomTeamSidebarComponent(TeamSidebar);
5356
registry.registerPopoverUserAttributesComponent(UserAttribute);
5457
registry.registerRootComponent(CreateIssueModal);
55-
registry.registerPostDropdownMenuComponent(CreateIssuePostMenuAction);
58+
registry.registerPostDropdownMenuAction({
59+
text: CreateIssuePostMenuAction,
60+
action: (postId: string) => {
61+
store.dispatch(openCreateIssueModal(postId));
62+
},
63+
filter: (postId: string): boolean => {
64+
const state: GlobalState = store.getState();
65+
const post = getPost(state, postId);
66+
const isPostSystemMessage = Boolean(!post || isSystemMessage(post));
67+
68+
return getConnectedState(state) && !isPostSystemMessage;
69+
},
70+
});
71+
registry.registerPostDropdownMenuAction({
72+
text: AttachCommentToIssuePostMenuAction,
73+
action: (postId: string) => {
74+
store.dispatch(openAttachCommentToIssueModal(postId));
75+
},
76+
filter: (postId: string): boolean => {
77+
const state: GlobalState = store.getState();
78+
const post = getPost(state, postId);
79+
const isPostSystemMessage = Boolean(!post || isSystemMessage(post));
80+
81+
return getConnectedState(state) && !isPostSystemMessage;
82+
},
83+
});
5684
registry.registerRootComponent(AttachCommentToIssueModal);
57-
registry.registerPostDropdownMenuComponent(AttachCommentToIssuePostMenuAction);
5885
registry.registerLinkTooltipComponent(LinkTooltip);
5986

6087
const hooks = new Hooks(store);

webapp/src/types/mattermost-webapp/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export interface PluginRegistry {
2727
registerLinkTooltipComponent(component: React.ReactNode)
2828
registerReconnectHandler(handler: any)
2929
registerPostDropdownMenuComponent(component: React.ReactNode)
30+
registerPostDropdownMenuAction(action: any)
3031
registerRootComponent(component: React.ElementType)
3132

3233
// Add more if needed from https://developers.mattermost.com/extend/plugins/webapp/reference

0 commit comments

Comments
 (0)