-
Notifications
You must be signed in to change notification settings - Fork 2.7k
9091 migrated leave_team_modal component to redux #1514
Conversation
4e739da
to
20693f1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Should convert this as well to make use of
ToggleModalButtonRedux
- showLeaveTeamModal can be removed.
TOGGLE_LEAVE_TEAM_MODAL
can be removed as well
Great work on unit testing!
components/leave_team_modal/index.js
Outdated
import {emitLeaveTeam, toggleSideBarRightMenuAction} from 'actions/global_actions.jsx'; | ||
import {ModalIdentifiers} from 'utils/constants'; | ||
|
||
import {getIsBusy} from '../../selectors/webrtc'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change to selectors/webrtc
|
||
if (WebrtcStore.isBusy()) { | ||
if (this.props.isBusy) { | ||
WebrtcStore.emitChanged({action: WebrtcActionTypes.IN_PROGRESS}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest this to convert as well into redux action.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a question regarding this. Even if we convert this to redux action , I assume somewhere down the chain we need to emit
WebrtcStore.emitChanged({action: WebrtcActionTypes.IN_PROGRESS});
so that the webrtcStore can act on it.
Where will that happen ? Kindly clarify, if I am getting it wrong .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like on our offline DM, webrtcstore conversion to redux store is good to have in a separate PR. I'm good with not changing WebrtcStore.emitChanged
.
|
||
constructor(props) { | ||
super(props); | ||
this.handleSubmit = this.handleSubmit.bind(this); | ||
} | ||
|
||
handleSubmit(e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this into arrow function: handleSubmit = (e) => {...}
}), | ||
}; | ||
|
||
constructor(props) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may remove this constructor.
var currentUser = UserStore.getCurrentUser(); | ||
|
||
if (currentUser != null) { | ||
if (this.props.currentUser != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we don't need this condition check.
import thunk from 'redux-thunk'; | ||
|
||
import {updateBusyWebrtc, initWebrtc, closeWebrtc} from 'actions/views/webrtc'; | ||
import {ActionTypes} from '../../../../utils/constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should change to utils/constants
components/leave_team_modal/index.js
Outdated
const modalId = ModalIdentifiers.LEAVE_TEAM; | ||
const currentUser = getCurrentUser(state); | ||
const isBusy = getIsBusy(state); | ||
const show = state.views.modals.modalState[modalId] && state.views.modals.modalState[modalId].open; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add selector for open state of the modalId?
components/leave_team_modal/index.js
Outdated
import {connect} from 'react-redux'; | ||
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users'; | ||
|
||
import {emitLeaveTeam, toggleSideBarRightMenuAction} from 'actions/global_actions.jsx'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of using emitLeaveTeam
, please use directly the redux action import {removeUserFromTeam} from 'mattermost-redux/actions/teams';
Doing so, you may delete that global actions' emitLeaveTeam.
components/leave_team_modal/index.js
Outdated
const isBusy = getIsBusy(state); | ||
const show = state.views.modals.modalState[modalId] && state.views.modals.modalState[modalId].open; | ||
return { | ||
currentUser, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need to pass currentUserId
and teamId
@jasonblais I tested this locally and I found that hitting enter after opening the |
@saturninoabril thanks for the review.. Will work on the comments and let you know.. |
Thanks @pradeepmurugesan @jasonblais Tested the PR on the spinmint:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, just some comments.
Also, LeaveTeamModal on mobile browser's view (on sidebar right menu) is not working, you might have missed my last comments on that:
- Should convert this as well to make use of
ToggleModalButtonRedux
- showLeaveTeamModal can be removed.
TOGGLE_LEAVE_TEAM_MODAL
can be removed as well
<button | ||
type='button' | ||
className='btn btn-danger' | ||
onClick={this.handleSubmit.bind(this)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to bind and should be fine to change into: onClick={this.handleSubmit}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to bind since I am accessing this.props
inside handleSubmit . Without binding I am getting props undefined..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly let me know if I am missing something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work since you've already change it into arrow function (handleSubmit = (e) => {...}
) but I could be wrong in this case. Could you please try again and validate? Thanks
toggleSideBarRightMenu: PropTypes.func.isRequired, | ||
}), | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add event listener on keypress to make hitting enter
key works on this modal, could be like:
import WebrtcStore from 'stores/webrtc_store.jsx';
-import {WebrtcActionTypes} from 'utils/constants.jsx';
+import Constants, {WebrtcActionTypes} from 'utils/constants.jsx';
+import {isKeyPressed} from 'utils/utils.jsx';
class LeaveTeamModal extends React.PureComponent {
static propTypes = {
@@ -58,6 +59,22 @@ class LeaveTeamModal extends React.PureComponent {
}),
};
+ componentDidMount() {
+ if (this.props.show) {
+ document.addEventListener('keypress', this.handleKeyPress);
+ }
+ }
+
+ componentWillUnmount() {
+ document.removeEventListener('keypress', this.handleKeyPress);
+ }
+
+ handleKeyPress = (e) => {
+ if (isKeyPressed(e, Constants.KeyCodes.ENTER)) {
+ this.handleSubmit(e);
+ }
+ }
+
handleSubmit = (e) => {
this.props.onHide();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just one last bit :)
Thanks @pradeepmurugesan!
import WebrtcStore from 'stores/webrtc_store.jsx'; | ||
import {WebrtcActionTypes} from 'utils/constants.jsx'; | ||
import {isKeyPressed} from 'utils/utils'; | ||
import Constants from 'utils/constants'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utils/constants
is already declared above, should just combine those.
246e4c0
to
9009e95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
* 9140 migrated leave_team_modal component to redux * 9091 added tests for existing code * 9091 fixed code review comments * 9091 fixed the mobile view and added a key press listener * 9091 merged the duplicate import
Summary
migrated leave_team_modal component to redux
Ticket Link
mattermost/mattermost#9091
Checklist
[Place an '[x]' (no spaces) in all applicable fields. Please remove unrelated fields.]
make check-style
to check for style errors (required for all pull requests)make test
to ensure unit and component tests passed