aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/store
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-12-13 13:44:12 +0100
committerStas Vilchik <stas.vilchik@sonarsource.com>2018-01-02 10:38:10 +0100
commit027514e6f94607fcd7df8e69e668fe32aeb2873e (patch)
treeb73db22c100713df85f1a790c4a772300b41a7f5 /server/sonar-web/src/main/js/store
parent492cd3de03d14aaf91b54e96531d77079c0db7f1 (diff)
downloadsonarqube-027514e6f94607fcd7df8e69e668fe32aeb2873e.tar.gz
sonarqube-027514e6f94607fcd7df8e69e668fe32aeb2873e.zip
SONAR-10182 Users should be able to choose their homepage
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r--server/sonar-web/src/main/js/store/users/actions.ts (renamed from server/sonar-web/src/main/js/store/users/actions.js)23
-rw-r--r--server/sonar-web/src/main/js/store/users/reducer.ts (renamed from server/sonar-web/src/main/js/store/users/reducer.js)36
2 files changed, 44 insertions, 15 deletions
diff --git a/server/sonar-web/src/main/js/store/users/actions.js b/server/sonar-web/src/main/js/store/users/actions.ts
index aaee4498138..c55fff019c9 100644
--- a/server/sonar-web/src/main/js/store/users/actions.js
+++ b/server/sonar-web/src/main/js/store/users/actions.ts
@@ -17,23 +17,36 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { getCurrentUser } from '../../api/users';
+import { Dispatch } from 'redux';
+import * as api from '../../api/users';
+import { CurrentUser, HomePage } from '../../app/types';
export const RECEIVE_CURRENT_USER = 'RECEIVE_CURRENT_USER';
export const RECEIVE_USER = 'RECEIVE_USER';
export const SKIP_ONBOARDING = 'SKIP_ONBOARDING';
+export const SET_HOMEPAGE = 'SET_HOMEPAGE';
-export const receiveCurrentUser = user => ({
+export const receiveCurrentUser = (user: CurrentUser) => ({
type: RECEIVE_CURRENT_USER,
user
});
-export const receiveUser = user => ({
+export const receiveUser = (user: any) => ({
type: RECEIVE_USER,
user
});
export const skipOnboarding = () => ({ type: SKIP_ONBOARDING });
-export const fetchCurrentUser = () => dispatch =>
- getCurrentUser().then(user => dispatch(receiveCurrentUser(user)));
+export const fetchCurrentUser = () => (dispatch: Dispatch<any>) => {
+ return api.getCurrentUser().then(user => dispatch(receiveCurrentUser(user)));
+};
+
+export const setHomePage = (homepage: HomePage) => (dispatch: Dispatch<any>) => {
+ api.setHomePage(homepage).then(
+ () => {
+ dispatch({ type: SET_HOMEPAGE, homepage });
+ },
+ () => {}
+ );
+};
diff --git a/server/sonar-web/src/main/js/store/users/reducer.js b/server/sonar-web/src/main/js/store/users/reducer.ts
index 79472f1f8d3..1cee5bae5e9 100644
--- a/server/sonar-web/src/main/js/store/users/reducer.js
+++ b/server/sonar-web/src/main/js/store/users/reducer.ts
@@ -19,10 +19,15 @@
*/
import { combineReducers } from 'redux';
import { uniq, keyBy } from 'lodash';
-import { RECEIVE_CURRENT_USER, RECEIVE_USER, SKIP_ONBOARDING } from './actions';
+import { RECEIVE_CURRENT_USER, RECEIVE_USER, SKIP_ONBOARDING, SET_HOMEPAGE } from './actions';
import { actions as membersActions } from '../organizationsMembers/actions';
+import { CurrentUser } from '../../app/types';
-const usersByLogin = (state = {}, action = {}) => {
+interface UsersByLogin {
+ [login: string]: any;
+}
+
+const usersByLogin = (state: UsersByLogin = {}, action: any = {}) => {
switch (action.type) {
case RECEIVE_CURRENT_USER:
case RECEIVE_USER:
@@ -37,14 +42,16 @@ const usersByLogin = (state = {}, action = {}) => {
}
};
-const userLogins = (state = [], action = {}) => {
+type UserLogins = string[];
+
+const userLogins = (state: UserLogins = [], action: any = {}) => {
switch (action.type) {
case RECEIVE_CURRENT_USER:
case RECEIVE_USER:
return uniq([...state, action.user.login]);
case membersActions.RECEIVE_MEMBERS:
case membersActions.RECEIVE_MORE_MEMBERS:
- return uniq([...state, action.members.map(member => member.login)]);
+ return uniq([...state, action.members.map((member: any) => member.login)]);
case membersActions.ADD_MEMBER: {
return uniq([...state, action.member.login]).sort();
}
@@ -53,21 +60,30 @@ const userLogins = (state = [], action = {}) => {
}
};
-const currentUser = (state = null, action = {}) => {
+const currentUser = (state: CurrentUser | null = null, action: any = {}) => {
if (action.type === RECEIVE_CURRENT_USER) {
return action.user;
}
if (action.type === SKIP_ONBOARDING) {
return state ? { ...state, showOnboardingTutorial: false } : null;
}
+ if (action.type === SET_HOMEPAGE) {
+ return state && { ...state, homepage: action.homepage };
+ }
return state;
};
+interface State {
+ usersByLogin: UsersByLogin;
+ userLogins: UserLogins;
+ currentUser: CurrentUser | null;
+}
+
export default combineReducers({ usersByLogin, userLogins, currentUser });
-export const getCurrentUser = state => state.currentUser;
-export const getUserLogins = state => state.userLogins;
-export const getUserByLogin = (state, login) => state.usersByLogin[login];
-export const getUsersByLogins = (state, logins) =>
+export const getCurrentUser = (state: State) => state.currentUser!;
+export const getUserLogins = (state: State) => state.userLogins;
+export const getUserByLogin = (state: State, login: string) => state.usersByLogin[login];
+export const getUsersByLogins = (state: State, logins: string[]) =>
logins.map(login => getUserByLogin(state, login));
-export const getUsers = state => getUsersByLogins(state, getUserLogins(state));
+export const getUsers = (state: State) => getUsersByLogins(state, getUserLogins(state));