Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

9091 migrated leave_team_modal component to redux #1514

Merged
merged 5 commits into from
Aug 13, 2018

Conversation

pradeepmurugesan
Copy link
Contributor

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.]

  • Ran make check-style to check for style errors (required for all pull requests)
  • Ran make test to ensure unit and component tests passed
  • Added or updated unit tests (required for all new features)
  • Has server changes (please link)
  • Has redux changes (please link)
  • Has UI changes
  • Includes text changes and localization file (.../i18n/en.json) updates
  • Touches critical sections of the codebase (auth, posting, etc.)

@pradeepmurugesan pradeepmurugesan changed the title [WIP] - 9140 migrated leave_team_modal component to redux 9140 migrated leave_team_modal component to redux Aug 3, 2018
@jasonblais jasonblais added the 2: Dev Review Requires review by a core commiter label Aug 3, 2018
Copy link
Member

@saturninoabril saturninoabril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on unit testing!

import {emitLeaveTeam, toggleSideBarRightMenuAction} from 'actions/global_actions.jsx';
import {ModalIdentifiers} from 'utils/constants';

import {getIsBusy} from '../../selectors/webrtc';
Copy link
Member

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});
Copy link
Member

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.

Copy link
Contributor Author

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 .

Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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';
Copy link
Member

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

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;
Copy link
Member

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?

import {connect} from 'react-redux';
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';

import {emitLeaveTeam, toggleSideBarRightMenuAction} from 'actions/global_actions.jsx';
Copy link
Member

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.

const isBusy = getIsBusy(state);
const show = state.views.modals.modalState[modalId] && state.views.modals.modalState[modalId].open;
return {
currentUser,
Copy link
Member

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

@saturninoabril
Copy link
Member

@jasonblais I tested this locally and I found that hitting enter after opening the LeaveTeamModal does nothing. Current behavior makes the Yes button event and fires up action in leaving a team. You might want to give a quick smoke test just in case. Thanks!

@pradeepmurugesan
Copy link
Contributor Author

@saturninoabril thanks for the review.. Will work on the comments and let you know..

@pradeepmurugesan pradeepmurugesan changed the title 9140 migrated leave_team_modal component to redux 9091 migrated leave_team_modal component to redux Aug 6, 2018
@jasonblais jasonblais added 3: QA Review Requires review by a QA tester Setup Old Test Server Triggers the creation of a test server labels Aug 6, 2018
@lindy65
Copy link
Contributor

lindy65 commented Aug 6, 2018

Thanks @pradeepmurugesan @jasonblais

Tested the PR on the spinmint:

  • as the sysadmin and as user-1

  • Working as expected:

    • Clicking on Yes to confirm leaving the team
    • Clicking on No to cancel out of leaving the team
    • If Allow any user with an account on this server to join this team was set to yes, I am able to rejoin the team from the Join another team menu option as well as by clicking on the + in the team sidebar.
    • If Allow any user with an account on this server to join this team was set to no, I do not see the team in the list of teams available to join from the Join another team menu option or when clicking on the + in the team sidebar.
  • Issue found:

    • same issue as saturninoabril where hitting enter after opening the LeaveTeamModal does nothing

@lindy65 lindy65 removed the 3: QA Review Requires review by a QA tester label Aug 6, 2018
@saturninoabril saturninoabril removed the Setup Old Test Server Triggers the creation of a test server label Aug 7, 2018
@mattermost mattermost deleted a comment from mattermod Aug 7, 2018
@mattermost mattermost deleted a comment from mattermod Aug 7, 2018
@mattermost mattermost deleted a comment from mattermod Aug 7, 2018
Copy link
Member

@saturninoabril saturninoabril left a 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:

<button
type='button'
className='btn btn-danger'
onClick={this.handleSubmit.bind(this)}
Copy link
Member

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}

Copy link
Contributor Author

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..

Copy link
Contributor Author

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

Copy link
Member

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,
}),
};

Copy link
Member

@saturninoabril saturninoabril Aug 7, 2018

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();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure 👍

Copy link
Member

@saturninoabril saturninoabril left a 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';
Copy link
Member

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.

Copy link
Member

@jwilander jwilander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@jwilander jwilander added 4: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core commiter labels Aug 13, 2018
@jwilander jwilander merged commit 6c4eb13 into mattermost:master Aug 13, 2018
@lindalumitchell lindalumitchell added the Tests/Not Needed Does not require new release tests label Aug 14, 2018
@amyblais amyblais added Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation labels Aug 17, 2018
fincha pushed a commit to fincha/mattermost-webapp that referenced this pull request Oct 21, 2018
* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
4: Reviews Complete All reviewers have approved the pull request Changelog/Not Needed Does not require a changelog entry Docs/Not Needed Does not require documentation Tests/Not Needed Does not require new release tests
Projects
None yet
7 participants