Commit 5efd0be3 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch 'Migrate-deprecated-delete-milestone-modal-ab' into 'master'

Migrate DeprecatedModal to GitLab UI Modal

See merge request gitlab-org/gitlab!42113
parents 9d1d77b3 18dcb756
<script> <script>
import { GlSafeHtmlDirective as SafeHtml } from '@gitlab/ui'; import { GlSafeHtmlDirective as SafeHtml, GlModal } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { deprecatedCreateFlash as Flash } from '~/flash'; import { deprecatedCreateFlash as Flash } from '~/flash';
import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue'; import { __, n__, s__, sprintf } from '~/locale';
import { n__, s__, sprintf } from '~/locale';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo } from '~/lib/utils/url_utility';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
components: { components: {
DeprecatedModal, GlModal,
}, },
directives: { directives: {
SafeHtml, SafeHtml,
...@@ -115,20 +114,24 @@ Once deleted, it cannot be undone or recovered.`), ...@@ -115,20 +114,24 @@ Once deleted, it cannot be undone or recovered.`),
}); });
}, },
}, },
primaryProps: {
text: s__('Milestones|Delete milestone'),
attributes: [{ variant: 'danger' }, { category: 'primary' }],
},
cancelProps: {
text: __('Cancel'),
},
}; };
</script> </script>
<template> <template>
<deprecated-modal <gl-modal
id="delete-milestone-modal" modal-id="delete-milestone-modal"
:title="title" :title="title"
:text="text" :action-primary="$options.primaryProps"
:primary-button-label="s__('Milestones|Delete milestone')" :action-cancel="$options.cancelProps"
kind="danger" @primary="onSubmit"
@submit="onSubmit"
> >
<template #body="props"> <p v-safe-html="text"></p>
<p v-safe-html="props.text"></p> </gl-modal>
</template>
</deprecated-modal>
</template> </template>
import Vue from 'vue'; import Vue from 'vue';
import Translate from '~/vue_shared/translate'; import Translate from '~/vue_shared/translate';
import deleteMilestoneModal from './components/delete_milestone_modal.vue'; import DeleteMilestoneModal from './components/delete_milestone_modal.vue';
import eventHub from './event_hub'; import eventHub from './event_hub';
export default () => { export default () => {
...@@ -18,6 +18,8 @@ export default () => { ...@@ -18,6 +18,8 @@ export default () => {
button.querySelector('.js-loading-icon').classList.add('hidden'); button.querySelector('.js-loading-icon').classList.add('hidden');
}; };
const deleteMilestoneButtons = document.querySelectorAll('.js-delete-milestone-button');
const onRequestStarted = milestoneUrl => { const onRequestStarted = milestoneUrl => {
const button = document.querySelector( const button = document.querySelector(
`.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`, `.js-delete-milestone-button[data-milestone-url="${milestoneUrl}"]`,
...@@ -27,35 +29,8 @@ export default () => { ...@@ -27,35 +29,8 @@ export default () => {
eventHub.$once('deleteMilestoneModal.requestFinished', onRequestFinished); eventHub.$once('deleteMilestoneModal.requestFinished', onRequestFinished);
}; };
const onDeleteButtonClick = event => {
const button = event.currentTarget;
const modalProps = {
milestoneId: parseInt(button.dataset.milestoneId, 10),
milestoneTitle: button.dataset.milestoneTitle,
milestoneUrl: button.dataset.milestoneUrl,
issueCount: parseInt(button.dataset.milestoneIssueCount, 10),
mergeRequestCount: parseInt(button.dataset.milestoneMergeRequestCount, 10),
};
eventHub.$once('deleteMilestoneModal.requestStarted', onRequestStarted);
eventHub.$emit('deleteMilestoneModal.props', modalProps);
};
const deleteMilestoneButtons = document.querySelectorAll('.js-delete-milestone-button');
deleteMilestoneButtons.forEach(button => {
button.addEventListener('click', onDeleteButtonClick);
});
eventHub.$once('deleteMilestoneModal.mounted', () => {
deleteMilestoneButtons.forEach(button => {
button.removeAttribute('disabled');
});
});
return new Vue({ return new Vue({
el: '#delete-milestone-modal', el: '#js-delete-milestone-modal',
components: {
deleteMilestoneModal,
},
data() { data() {
return { return {
modalProps: { modalProps: {
...@@ -69,10 +44,21 @@ export default () => { ...@@ -69,10 +44,21 @@ export default () => {
}, },
mounted() { mounted() {
eventHub.$on('deleteMilestoneModal.props', this.setModalProps); eventHub.$on('deleteMilestoneModal.props', this.setModalProps);
eventHub.$emit('deleteMilestoneModal.mounted'); deleteMilestoneButtons.forEach(button => {
}, button.removeAttribute('disabled');
beforeDestroy() { button.addEventListener('click', () => {
eventHub.$off('deleteMilestoneModal.props', this.setModalProps); this.$root.$emit('bv::show::modal', 'delete-milestone-modal');
eventHub.$once('deleteMilestoneModal.requestStarted', onRequestStarted);
this.setModalProps({
milestoneId: parseInt(button.dataset.milestoneId, 10),
milestoneTitle: button.dataset.milestoneTitle,
milestoneUrl: button.dataset.milestoneUrl,
issueCount: parseInt(button.dataset.milestoneIssueCount, 10),
mergeRequestCount: parseInt(button.dataset.milestoneMergeRequestCount, 10),
});
});
});
}, },
methods: { methods: {
setModalProps(modalProps) { setModalProps(modalProps) {
...@@ -80,7 +66,7 @@ export default () => { ...@@ -80,7 +66,7 @@ export default () => {
}, },
}, },
render(createElement) { render(createElement) {
return createElement(deleteMilestoneModal, { return createElement(DeleteMilestoneModal, {
props: this.modalProps, props: this.modalProps,
}); });
}, },
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
= _('New milestone') = _('New milestone')
.milestones .milestones
#delete-milestone-modal #js-delete-milestone-modal
#promote-milestone-modal #promote-milestone-modal
%ul.content-list %ul.content-list
......
- milestone_url = @milestone.project_milestone? ? project_milestone_path(@project, @milestone) : group_milestone_path(@group, @milestone) - milestone_url = @milestone.project_milestone? ? project_milestone_path(@project, @milestone) : group_milestone_path(@group, @milestone)
%button.js-delete-milestone-button.btn.btn-grouped.btn-danger{ data: { toggle: 'modal', %button.js-delete-milestone-button.btn.btn-grouped.btn-danger{ data: { milestone_id: @milestone.id,
target: '#delete-milestone-modal',
milestone_id: @milestone.id,
milestone_title: markdown_field(@milestone, :title), milestone_title: markdown_field(@milestone, :title),
milestone_url: milestone_url, milestone_url: milestone_url,
milestone_issue_count: @milestone.issues.count, milestone_issue_count: @milestone.issues.count,
...@@ -11,4 +9,4 @@ ...@@ -11,4 +9,4 @@
= _('Delete') = _('Delete')
.spinner.js-loading-icon.hidden .spinner.js-loading-icon.hidden
#delete-milestone-modal #js-delete-milestone-modal
---
title: Migrate DeprecatedModal to GitLab UI Modal
merge_request: 42113
author:
type: changed
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