Commit 9188bf0e authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Minor refactor tree_helper logic

Minor clean up modal logic

Minor update to use the v-model attribute
for the gl-modal.
parent 082b8f12
...@@ -15,8 +15,12 @@ export default { ...@@ -15,8 +15,12 @@ export default {
components: { components: {
GlModal, GlModal,
}, },
model: {
prop: 'visible',
event: 'change',
},
props: { props: {
isVisible: { visible: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: false,
...@@ -46,23 +50,18 @@ export default { ...@@ -46,23 +50,18 @@ export default {
}; };
}, },
}, },
methods: {
handleHide() {
this.$emit('hide');
},
},
i18n, i18n,
}; };
</script> </script>
<template> <template>
<gl-modal <gl-modal
:visible="visible"
data-qa-selector="confirm_fork_modal" data-qa-selector="confirm_fork_modal"
:visible="isVisible"
:modal-id="modalId" :modal-id="modalId"
:title="$options.i18n.title" :title="$options.i18n.title"
:action-primary="btnActions.primary" :action-primary="btnActions.primary"
:action-cancel="btnActions.cancel" :action-cancel="btnActions.cancel"
@hide="handleHide" @change="$emit('change', $event)"
> >
<p>{{ $options.i18n.message }}</p> <p>{{ $options.i18n.message }}</p>
</gl-modal> </gl-modal>
......
...@@ -293,10 +293,9 @@ export default { ...@@ -293,10 +293,9 @@ export default {
</gl-modal> </gl-modal>
<confirm-fork-modal <confirm-fork-modal
v-if="showWebIdeButton || showEditButton" v-if="showWebIdeButton || showEditButton"
:is-visible="showForkModal" v-model="showForkModal"
:modal-id="forkModalId" :modal-id="forkModalId"
:fork-path="forkPath" :fork-path="forkPath"
@hide="showForkModal = false"
/> />
</div> </div>
</template> </template>
...@@ -179,9 +179,7 @@ module TreeHelper ...@@ -179,9 +179,7 @@ module TreeHelper
if show_edit_button?({ blob: blob }) if show_edit_button?({ blob: blob })
fork_path = fork_and_edit_path(project, ref, path) fork_path = fork_and_edit_path(project, ref, path)
fork_modal_id = "modal-confirm-fork-edit" fork_modal_id = "modal-confirm-fork-edit"
end elsif show_web_ide_button?
if show_web_ide_button?
fork_path = ide_fork_and_edit_path(project, ref, path) fork_path = ide_fork_and_edit_path(project, ref, path)
fork_modal_id = "modal-confirm-fork-webide" fork_modal_id = "modal-confirm-fork-webide"
end end
......
...@@ -2,4 +2,4 @@ ...@@ -2,4 +2,4 @@
- button_data = web_ide_button_data({ blob: blob }) - button_data = web_ide_button_data({ blob: blob })
- fork_options = fork_modal_options(@project, @ref, @path, blob) - fork_options = fork_modal_options(@project, @ref, @path, blob)
.d-inline-block{ data: { options: button_data.merge(fork_options).to_json }, id: "js-#{type}-web-ide-link" } .gl-display-inline-block{ data: { options: button_data.merge(fork_options).to_json }, id: "js-#{type}-web-ide-link" }
...@@ -25,7 +25,7 @@ describe('vue_shared/components/confirm_fork_modal', () => { ...@@ -25,7 +25,7 @@ describe('vue_shared/components/confirm_fork_modal', () => {
wrapper.destroy(); wrapper.destroy();
}); });
describe('isVisible = false', () => { describe('visible = false', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
}); });
...@@ -60,21 +60,21 @@ describe('vue_shared/components/confirm_fork_modal', () => { ...@@ -60,21 +60,21 @@ describe('vue_shared/components/confirm_fork_modal', () => {
}); });
}); });
describe('isVisible = true', () => { describe('visible = true', () => {
beforeEach(() => { beforeEach(() => {
wrapper = createComponent({ isVisible: true }); wrapper = createComponent({ visible: true });
}); });
it('sets the visible prop to `true`', () => { it('sets the visible prop to `true`', () => {
expect(findModalProp('visible')).toBe(true); expect(findModalProp('visible')).toBe(true);
}); });
it('emits the `hide` event if the modal is hidden', () => { it('emits the `change` event if the modal is hidden', () => {
expect(wrapper.emitted('hide')).toBeUndefined(); expect(wrapper.emitted('change')).toBeUndefined();
findModal().vm.$emit('hide'); findModal().vm.$emit('change', false);
expect(wrapper.emitted('hide')).toHaveLength(1); expect(wrapper.emitted('change')).toEqual([[false]]);
}); });
}); });
}); });
...@@ -272,7 +272,7 @@ describe('Web IDE link component', () => { ...@@ -272,7 +272,7 @@ describe('Web IDE link component', () => {
expect(findForkConfirmModal().exists()).toBe(true); expect(findForkConfirmModal().exists()).toBe(true);
expect(findForkConfirmModal().props()).toEqual({ expect(findForkConfirmModal().props()).toEqual({
isVisible: false, visible: false,
forkPath, forkPath,
modalId: props.forkModalId, modalId: props.forkModalId,
}); });
...@@ -284,7 +284,7 @@ describe('Web IDE link component', () => { ...@@ -284,7 +284,7 @@ describe('Web IDE link component', () => {
await findActionsButton().trigger('click'); await findActionsButton().trigger('click');
expect(findForkConfirmModal().props()).toEqual({ expect(findForkConfirmModal().props()).toEqual({
isVisible: true, visible: true,
forkPath, forkPath,
modalId: props.forkModalId, modalId: props.forkModalId,
}); });
......
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