]> source.dussan.org Git - sonarqube.git/commitdiff
drop getCurrentUserFromStore (#2993)
authorStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 29 Jan 2018 19:09:10 +0000 (20:09 +0100)
committerGitHub <noreply@github.com>
Mon, 29 Jan 2018 19:09:10 +0000 (20:09 +0100)
server/sonar-web/src/main/js/app/utils/getCurrentUserFromStore.js [deleted file]
server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueAssign-test.js.snap
server/sonar-web/src/main/js/components/issue/popups/SetAssigneePopup.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 (file)
index 9fa5b90..0000000
+++ /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;
index a95bb5a84c54429213e3f2dd167525b3bd19af35..d4ff90579c60de7d529e86ebdf3ba96469f1ca65 100644 (file)
@@ -22,7 +22,7 @@ exports[`should open the popup when the button is clicked 2`] = `
 <BubblePopupHelper
   isOpen={true}
   popup={
-    <SetAssigneePopup
+    <Connect(SetAssigneePopup)
       issue={
         Object {
           "assignee": "john",
@@ -69,7 +69,7 @@ exports[`should render with the action 1`] = `
 <BubblePopupHelper
   isOpen={false}
   popup={
-    <SetAssigneePopup
+    <Connect(SetAssigneePopup)
       issue={
         Object {
           "assignee": "john",
index a5c2530f862f84af6cb2ffb20c412ac83548d10a..75013a4c6ef6ed111926dd08df12f5c32b060256 100644 (file)
 // @flow
 import React from 'react';
 import { map } from 'lodash';
+import { connect } from 'react-redux';
+import * as PropTypes from 'prop-types';
 import Avatar from '../../../components/ui/Avatar';
 import BubblePopup from '../../../components/common/BubblePopup';
 import SelectList from '../../../components/common/SelectList';
 import SelectListItem from '../../../components/common/SelectListItem';
 import SearchBox from '../../../components/controls/SearchBox';
-import getCurrentUserFromStore from '../../../app/utils/getCurrentUserFromStore';
-import { areThereCustomOrganizations } from '../../../store/organizations/utils';
 import { searchMembers } from '../../../api/organizations';
 import { searchUsers } from '../../../api/users';
 import { translate } from '../../../helpers/l10n';
+import { getCurrentUser } from '../../../store/rootReducer';
 /*:: import type { Issue } from '../types'; */
 
 /*::
@@ -43,6 +44,7 @@ type User = {
 
 /*::
 type Props = {
+  currentUser: User,
   issue: Issue,
   onFail: Error => 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<User>; */
-  /*:: 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);