debian-mirror-gitlab/app/assets/javascripts/members/components/table/role_dropdown.vue

100 lines
2.5 KiB
Vue
Raw Normal View History

2021-01-03 14:25:43 +05:30
<script>
import { GlDropdown, GlDropdownItem } from '@gitlab/ui';
import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils';
import { mapActions } from 'vuex';
import { s__ } from '~/locale';
export default {
name: 'RoleDropdown',
components: {
GlDropdown,
GlDropdownItem,
2021-02-22 17:27:13 +05:30
LdapDropdownItem: () => import('ee_component/members/components/ldap/ldap_dropdown_item.vue'),
2021-01-03 14:25:43 +05:30
},
2021-04-29 21:17:54 +05:30
inject: ['namespace'],
2021-01-03 14:25:43 +05:30
props: {
member: {
type: Object,
required: true,
},
2021-01-29 00:20:46 +05:30
permissions: {
type: Object,
required: true,
},
2021-01-03 14:25:43 +05:30
},
data() {
return {
isDesktop: false,
busy: false,
};
},
2021-01-29 00:20:46 +05:30
computed: {
disabled() {
return this.busy || (this.permissions.canOverride && !this.member.isOverridden);
},
},
2021-01-03 14:25:43 +05:30
mounted() {
this.isDesktop = bp.isDesktop();
2021-01-29 00:20:46 +05:30
// Bootstrap Vue and GlDropdown to not support adding attributes to the dropdown toggle
// This can be changed once https://gitlab.com/gitlab-org/gitlab-ui/-/issues/1060 is implemented
const dropdownToggle = this.$refs.glDropdown.$el.querySelector('.dropdown-toggle');
if (dropdownToggle) {
dropdownToggle.setAttribute('data-qa-selector', 'access_level_dropdown');
}
2021-01-03 14:25:43 +05:30
},
methods: {
2021-04-29 21:17:54 +05:30
...mapActions({
updateMemberRole(dispatch, payload) {
return dispatch(`${this.namespace}/updateMemberRole`, payload);
},
}),
2021-01-03 14:25:43 +05:30
handleSelect(value, name) {
if (value === this.member.accessLevel.integerValue) {
return;
}
this.busy = true;
this.updateMemberRole({
memberId: this.member.id,
accessLevel: { integerValue: value, stringValue: name },
})
.then(() => {
this.$toast.show(s__('Members|Role updated successfully.'));
this.busy = false;
})
.catch(() => {
this.busy = false;
});
},
},
};
</script>
<template>
<gl-dropdown
2021-01-29 00:20:46 +05:30
ref="glDropdown"
2021-01-03 14:25:43 +05:30
:right="!isDesktop"
:text="member.accessLevel.stringValue"
:header-text="__('Change permissions')"
2021-01-29 00:20:46 +05:30
:disabled="disabled"
2021-01-03 14:25:43 +05:30
>
<gl-dropdown-item
v-for="(value, name) in member.validRoles"
:key="value"
is-check-item
:is-checked="value === member.accessLevel.integerValue"
2021-01-29 00:20:46 +05:30
data-qa-selector="access_level_link"
2021-01-03 14:25:43 +05:30
@click="handleSelect(value, name)"
>
{{ name }}
</gl-dropdown-item>
2021-01-29 00:20:46 +05:30
<ldap-dropdown-item
v-if="permissions.canOverride && member.isOverridden"
:member-id="member.id"
/>
2021-01-03 14:25:43 +05:30
</gl-dropdown>
</template>