From 816bc9d992d181abeb1929c3935b4e7592f865a1 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 29 Jan 2018 20:09:10 +0100 Subject: [PATCH] drop getCurrentUserFromStore (#2993) --- .../js/app/utils/getCurrentUserFromStore.js | 30 ------------------- .../__snapshots__/IssueAssign-test.js.snap | 4 +-- .../issue/popups/SetAssigneePopup.js | 27 +++++++++++------ 3 files changed, 20 insertions(+), 41 deletions(-) delete mode 100644 server/sonar-web/src/main/js/app/utils/getCurrentUserFromStore.js diff --git a/server/sonar-web/src/main/js/app/utils/getCurrentUserFromStore.js b/server/sonar-web/src/main/js/app/utils/getCurrentUserFromStore.js deleted file mode 100644 index 9fa5b90e3d0..00000000000 --- a/server/sonar-web/src/main/js/app/utils/getCurrentUserFromStore.js +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -// @flow -import { getCurrentUser } from '../../store/rootReducer'; - -// TODO remove my usages -const getCurrentUserFromStore = () => { - const getStore = require('./getStore').default; - const store = getStore(); - return getCurrentUser(store.getState()); -}; - -export default getCurrentUserFromStore; diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueAssign-test.js.snap b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueAssign-test.js.snap index a95bb5a84c5..d4ff90579c6 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueAssign-test.js.snap +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueAssign-test.js.snap @@ -22,7 +22,7 @@ exports[`should open the popup when the button is clicked 2`] = ` void, onSelect: string => void, @@ -60,20 +62,21 @@ type State = { const LIST_SIZE = 10; -export default class SetAssigneePopup extends React.PureComponent { +class SetAssigneePopup extends React.PureComponent { /*:: defaultUsersArray: Array; */ - /*:: organizationEnabled: boolean; */ /*:: props: Props; */ /*:: state: State; */ + static contextTypes = { + organizationsEnabled: PropTypes.bool + }; + constructor(props /*: Props */) { super(props); - this.organizationEnabled = areThereCustomOrganizations(); this.defaultUsersArray = [{ login: '', name: translate('unassigned') }]; - const currentUser = getCurrentUserFromStore(); - if (currentUser.isLoggedIn) { - this.defaultUsersArray = [currentUser, ...this.defaultUsersArray]; + if (props.currentUser.isLoggedIn) { + this.defaultUsersArray = [props.currentUser, ...this.defaultUsersArray]; } this.state = { @@ -110,7 +113,7 @@ export default class SetAssigneePopup extends React.PureComponent { }); } else { this.setState({ query }); - if (this.organizationEnabled) { + if (this.context.organizationsEnabled) { this.searchMembers(query); } else { this.searchUsers(query); @@ -155,3 +158,9 @@ export default class SetAssigneePopup extends React.PureComponent { ); } } + +const mapStateToProps = state => ({ + currentUser: getCurrentUser(state) +}); + +export default connect(mapStateToProps)(SetAssigneePopup); -- 2.39.5