aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/store
diff options
context:
space:
mode:
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>2017-03-28 11:58:01 +0200
committerGrégoire Aubert <gregaubert@users.noreply.github.com>2017-03-31 10:29:27 +0200
commit4b2cf358d38ad0e1931246530d3ff6ada7467079 (patch)
tree6cc4745b769dc225cf26cbf76801ad0b303d17f7 /server/sonar-web/src/main/js/store
parente4af315006ebfb8e6a606d2a29d1aff5706b7452 (diff)
downloadsonarqube-4b2cf358d38ad0e1931246530d3ff6ada7467079.tar.gz
sonarqube-4b2cf358d38ad0e1931246530d3ff6ada7467079.zip
SONAR-8992 Add a member to an organization
Diffstat (limited to 'server/sonar-web/src/main/js/store')
-rw-r--r--server/sonar-web/src/main/js/store/organizationsMembers/actions.js14
-rw-r--r--server/sonar-web/src/main/js/store/organizationsMembers/reducer.js12
-rw-r--r--server/sonar-web/src/main/js/store/users/reducer.js5
3 files changed, 27 insertions, 4 deletions
diff --git a/server/sonar-web/src/main/js/store/organizationsMembers/actions.js b/server/sonar-web/src/main/js/store/organizationsMembers/actions.js
index 44de107c3f8..08425dafc76 100644
--- a/server/sonar-web/src/main/js/store/organizationsMembers/actions.js
+++ b/server/sonar-web/src/main/js/store/organizationsMembers/actions.js
@@ -21,8 +21,9 @@
export type Member = {
login: string,
name: string,
- avatar: string,
- groupCount: number
+ avatar?: string,
+ email?: string,
+ groupCount?: number
};
type MembersState = {
@@ -35,7 +36,8 @@ type MembersState = {
export const actions = {
UPDATE_STATE: 'organizations/UPDATE_STATE',
RECEIVE_MEMBERS: 'organizations/RECEIVE_MEMBERS',
- RECEIVE_MORE_MEMBERS: 'organizations/RECEIVE_MORE_MEMBERS'
+ RECEIVE_MORE_MEMBERS: 'organizations/RECEIVE_MORE_MEMBERS',
+ ADD_MEMBER: 'organizations/ADD_MEMBER',
};
export const receiveMembers = (organizationKey: string, members: Array<Member>, stateChanges: MembersState) => ({
@@ -52,6 +54,12 @@ export const receiveMoreMembers = (organizationKey: string, members: Array<Membe
stateChanges
});
+export const addMember = (organizationKey: string, member: Member) => ({
+ type: actions.ADD_MEMBER,
+ organization: organizationKey,
+ member
+});
+
export const updateState = (
organizationKey: string,
stateChanges: MembersState
diff --git a/server/sonar-web/src/main/js/store/organizationsMembers/reducer.js b/server/sonar-web/src/main/js/store/organizationsMembers/reducer.js
index 1e7e5094945..3e635f21dbc 100644
--- a/server/sonar-web/src/main/js/store/organizationsMembers/reducer.js
+++ b/server/sonar-web/src/main/js/store/organizationsMembers/reducer.js
@@ -31,6 +31,7 @@ export const getOrganizationMembersState = (state, organization) =>
organization && state[organization] ? state[organization] : {};
const organizationMembers = (state = {}, action = {}) => {
+ const members = state.members || [];
switch (action.type) {
case actions.UPDATE_STATE:
return { ...state, ...action.stateChanges };
@@ -40,8 +41,16 @@ const organizationMembers = (state = {}, action = {}) => {
return {
...state,
...action.stateChanges,
- members: uniq((state.members || []).concat(action.members.map(member => member.login)))
+ members: uniq(members.concat(action.members.map(member => member.login)))
};
+ case actions.ADD_MEMBER: {
+ const withNew = [...members, action.member.login].sort();
+ return {
+ ...state,
+ total: withNew.length,
+ members: withNew
+ };
+ }
default:
return state;
}
@@ -53,6 +62,7 @@ const organizationsMembers = (state = {}, action = {}) => {
case actions.UPDATE_STATE:
case actions.RECEIVE_MEMBERS:
case actions.RECEIVE_MORE_MEMBERS:
+ case actions.ADD_MEMBER:
return {
...state,
[action.organization]: organizationMembers(organization, action)
diff --git a/server/sonar-web/src/main/js/store/users/reducer.js b/server/sonar-web/src/main/js/store/users/reducer.js
index a6206ffca58..5a943db98f7 100644
--- a/server/sonar-web/src/main/js/store/users/reducer.js
+++ b/server/sonar-web/src/main/js/store/users/reducer.js
@@ -29,6 +29,8 @@ const usersByLogin = (state = {}, action = {}) => {
case membersActions.RECEIVE_MEMBERS:
case membersActions.RECEIVE_MORE_MEMBERS:
return { ...state, ...keyBy(action.members, 'login') };
+ case membersActions.ADD_MEMBER:
+ return { ...state, [action.member.login]: action.member };
default:
return state;
}
@@ -41,6 +43,9 @@ const userLogins = (state = [], action = {}) => {
case membersActions.RECEIVE_MEMBERS:
case membersActions.RECEIVE_MORE_MEMBERS:
return uniq([...state, action.members.map(member => member.login)]);
+ case membersActions.ADD_MEMBER: {
+ return uniq([...state, action.member.login]).sort();
+ }
default:
return state;
}