diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /app/assets/javascripts/vuex_shared | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'app/assets/javascripts/vuex_shared')
6 files changed, 86 insertions, 2 deletions
diff --git a/app/assets/javascripts/vuex_shared/modules/members/actions.js b/app/assets/javascripts/vuex_shared/modules/members/actions.js new file mode 100644 index 00000000000..f7fdddfd070 --- /dev/null +++ b/app/assets/javascripts/vuex_shared/modules/members/actions.js @@ -0,0 +1,25 @@ +import * as types from './mutation_types'; +import axios from '~/lib/utils/axios_utils'; + +export const updateMemberRole = async ({ state, commit }, { memberId, accessLevel }) => { + try { + await axios.put( + state.memberPath.replace(/:id$/, memberId), + state.requestFormatter({ accessLevel: accessLevel.integerValue }), + ); + + commit(types.RECEIVE_MEMBER_ROLE_SUCCESS, { memberId, accessLevel }); + } catch (error) { + commit(types.RECEIVE_MEMBER_ROLE_ERROR); + + throw error; + } +}; + +export const showRemoveGroupLinkModal = ({ commit }, groupLink) => { + commit(types.SHOW_REMOVE_GROUP_LINK_MODAL, groupLink); +}; + +export const hideRemoveGroupLinkModal = ({ commit }) => { + commit(types.HIDE_REMOVE_GROUP_LINK_MODAL); +}; diff --git a/app/assets/javascripts/vuex_shared/modules/members/index.js b/app/assets/javascripts/vuex_shared/modules/members/index.js index ec6a94178f3..682e85298ad 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/index.js +++ b/app/assets/javascripts/vuex_shared/modules/members/index.js @@ -1,6 +1,10 @@ -import createState from './state'; +import createState from 'ee_else_ce/vuex_shared/modules/members/state'; +import * as actions from './actions'; +import mutations from './mutations'; export default initialState => ({ namespaced: true, state: createState(initialState), + actions, + mutations, }); diff --git a/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js b/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js new file mode 100644 index 00000000000..00f4c910669 --- /dev/null +++ b/app/assets/javascripts/vuex_shared/modules/members/mutation_types.js @@ -0,0 +1,7 @@ +export const RECEIVE_MEMBER_ROLE_SUCCESS = 'RECEIVE_MEMBER_ROLE_SUCCESS'; +export const RECEIVE_MEMBER_ROLE_ERROR = 'RECEIVE_MEMBER_ROLE_ERROR'; + +export const HIDE_ERROR = 'HIDE_ERROR'; + +export const SHOW_REMOVE_GROUP_LINK_MODAL = 'SHOW_REMOVE_GROUP_LINK_MODAL'; +export const HIDE_REMOVE_GROUP_LINK_MODAL = 'HIDE_REMOVE_GROUP_LINK_MODAL'; diff --git a/app/assets/javascripts/vuex_shared/modules/members/mutations.js b/app/assets/javascripts/vuex_shared/modules/members/mutations.js new file mode 100644 index 00000000000..281c947e68f --- /dev/null +++ b/app/assets/javascripts/vuex_shared/modules/members/mutations.js @@ -0,0 +1,33 @@ +import Vue from 'vue'; +import { s__ } from '~/locale'; +import * as types from './mutation_types'; +import { findMember } from './utils'; + +export default { + [types.RECEIVE_MEMBER_ROLE_SUCCESS](state, { memberId, accessLevel }) { + const member = findMember(state, memberId); + + if (!member) { + return; + } + + Vue.set(member, 'accessLevel', accessLevel); + }, + [types.RECEIVE_MEMBER_ROLE_ERROR](state) { + state.errorMessage = s__( + "Members|An error occurred while updating the member's role, please try again.", + ); + state.showError = true; + }, + [types.HIDE_ERROR](state) { + state.showError = false; + state.errorMessage = ''; + }, + [types.SHOW_REMOVE_GROUP_LINK_MODAL](state, groupLink) { + state.removeGroupLinkModalVisible = true; + state.groupLinkToRemove = groupLink; + }, + [types.HIDE_REMOVE_GROUP_LINK_MODAL](state) { + state.removeGroupLinkModalVisible = false; + }, +}; diff --git a/app/assets/javascripts/vuex_shared/modules/members/state.js b/app/assets/javascripts/vuex_shared/modules/members/state.js index 1511961245c..e4867819e17 100644 --- a/app/assets/javascripts/vuex_shared/modules/members/state.js +++ b/app/assets/javascripts/vuex_shared/modules/members/state.js @@ -1,5 +1,19 @@ -export default ({ members, sourceId, currentUserId }) => ({ +export default ({ members, sourceId, currentUserId, + tableFields, + memberPath, + requestFormatter, +}) => ({ + members, + sourceId, + currentUserId, + tableFields, + memberPath, + requestFormatter, + showError: false, + errorMessage: '', + removeGroupLinkModalVisible: false, + groupLinkToRemove: null, }); diff --git a/app/assets/javascripts/vuex_shared/modules/members/utils.js b/app/assets/javascripts/vuex_shared/modules/members/utils.js new file mode 100644 index 00000000000..7dcd33111e8 --- /dev/null +++ b/app/assets/javascripts/vuex_shared/modules/members/utils.js @@ -0,0 +1 @@ +export const findMember = (state, memberId) => state.members.find(member => member.id === memberId); |