Commit 4c3a6eff authored by Mark Florian's avatar Mark Florian

Merge branch '267118-simplify-delete-user-modal-init' into 'master'

Simplify user modal manager implementation

See merge request gitlab-org/gitlab!48815
parents 87998dce ae89149e
<script> <script>
import DeleteUserModal from './delete_user_modal.vue';
export default { export default {
components: { DeleteUserModal },
props: { props: {
modalConfiguration: { modalConfiguration: {
required: true, required: true,
type: Object, type: Object,
}, },
actionModals: {
required: true,
type: Object,
},
csrfToken: { csrfToken: {
required: true, required: true,
type: String, type: String,
...@@ -21,10 +20,7 @@ export default { ...@@ -21,10 +20,7 @@ export default {
}, },
computed: { computed: {
activeModal() { activeModal() {
if (!this.currentModalData) return null; return Boolean(this.currentModalData);
const { glModalAction: action } = this.currentModalData;
return this.actionModals[action];
}, },
modalProps() { modalProps() {
...@@ -56,9 +52,7 @@ export default { ...@@ -56,9 +52,7 @@ export default {
show(modalData) { show(modalData) {
const { glModalAction: requestedAction } = modalData; const { glModalAction: requestedAction } = modalData;
if (!this.actionModals[requestedAction]) {
throw new Error(`Requested non-existing modal action ${requestedAction}`);
}
if (!this.modalConfiguration[requestedAction]) { if (!this.modalConfiguration[requestedAction]) {
throw new Error(`Modal action ${requestedAction} has no configuration in HTML`); throw new Error(`Modal action ${requestedAction} has no configuration in HTML`);
} }
...@@ -73,5 +67,5 @@ export default { ...@@ -73,5 +67,5 @@ export default {
}; };
</script> </script>
<template> <template>
<div :is="activeModal" v-if="activeModal" ref="modal" v-bind="modalProps" /> <delete-user-modal v-if="activeModal" ref="modal" v-bind="modalProps" />
</template> </template>
...@@ -2,16 +2,11 @@ import Vue from 'vue'; ...@@ -2,16 +2,11 @@ import Vue from 'vue';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import ModalManager from './components/user_modal_manager.vue'; import ModalManager from './components/user_modal_manager.vue';
import DeleteUserModal from './components/delete_user_modal.vue';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
import initConfirmModal from '~/confirm_modal'; import initConfirmModal from '~/confirm_modal';
const MODAL_TEXTS_CONTAINER_SELECTOR = '#modal-texts'; const MODAL_TEXTS_CONTAINER_SELECTOR = '#js-modal-texts';
const MODAL_MANAGER_SELECTOR = '#user-modal'; const MODAL_MANAGER_SELECTOR = '#js-delete-user-modal';
const ACTION_MODALS = {
delete: DeleteUserModal,
'delete-with-contributions': DeleteUserModal,
};
function loadModalsConfigurationFromHtml(modalsElement) { function loadModalsConfigurationFromHtml(modalsElement) {
const modalsConfiguration = {}; const modalsConfiguration = {};
...@@ -54,7 +49,6 @@ document.addEventListener('DOMContentLoaded', () => { ...@@ -54,7 +49,6 @@ document.addEventListener('DOMContentLoaded', () => {
ref: 'manager', ref: 'manager',
props: { props: {
modalConfiguration, modalConfiguration,
actionModals: ACTION_MODALS,
csrfToken: csrf.token, csrfToken: csrf.token,
}, },
}); });
......
#user-modal #js-delete-user-modal
#modal-texts.hidden{ "hidden": true, "aria-hidden": true } #js-modal-texts.hidden{ "hidden": true, "aria-hidden": true }
%div{ data: { modal: "delete", %div{ data: { modal: "delete",
title: s_("AdminUsers|Delete User %{username}?"), title: s_("AdminUsers|Delete User %{username}?"),
action: s_('AdminUsers|Delete user'), action: s_('AdminUsers|Delete user'),
......
...@@ -14,21 +14,18 @@ describe('Users admin page Modal Manager', () => { ...@@ -14,21 +14,18 @@ describe('Users admin page Modal Manager', () => {
}, },
}; };
const actionModals = {
action1: ModalStub,
action2: ModalStub,
};
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = (props = {}) => {
wrapper = mount(UserModalManager, { wrapper = mount(UserModalManager, {
propsData: { propsData: {
actionModals,
modalConfiguration, modalConfiguration,
csrfToken: 'dummyCSRF', csrfToken: 'dummyCSRF',
...props, ...props,
}, },
stubs: {
DeleteUserModal: ModalStub,
},
}); });
}; };
...@@ -43,11 +40,6 @@ describe('Users admin page Modal Manager', () => { ...@@ -43,11 +40,6 @@ describe('Users admin page Modal Manager', () => {
expect(wrapper.find({ ref: 'modal' }).exists()).toBeFalsy(); expect(wrapper.find({ ref: 'modal' }).exists()).toBeFalsy();
}); });
it('throws if non-existing action is requested', () => {
createComponent();
expect(() => wrapper.vm.show({ glModalAction: 'non-existing' })).toThrow();
});
it('throws if action has no proper configuration', () => { it('throws if action has no proper configuration', () => {
createComponent({ createComponent({
modalConfiguration: {}, modalConfiguration: {},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment