Commit 69bb87c5 authored by Amy Qualls's avatar Amy Qualls Committed by Sarah Groff Hennigh-Palermo

Attempt to migrate the 'promote label' modal

Best first attempt to start migrating the 'promote label' modals
to the new system.
parent 3803fff4
<script> <script>
import { GlSprintf } from '@gitlab/ui'; import { GlSprintf, GlModal } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { deprecatedCreateFlash as createFlash } from '~/flash'; import { deprecatedCreateFlash as createFlash } from '~/flash';
import DeprecatedModal2 from '~/vue_shared/components/deprecated_modal_2.vue'; import { s__, __, sprintf } from '~/locale';
import { s__, sprintf } from '~/locale';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
primaryProps: {
text: s__('Labels|Promote Label'),
attributes: [{ variant: 'warning' }, { category: 'primary' }],
},
cancelProps: {
text: __('Cancel'),
},
components: { components: {
GlModal: DeprecatedModal2, GlModal,
GlSprintf, GlSprintf,
}, },
props: { props: {
...@@ -72,12 +78,12 @@ export default { ...@@ -72,12 +78,12 @@ export default {
</script> </script>
<template> <template>
<gl-modal <gl-modal
id="promote-label-modal" modal-id="promote-label-modal"
:footer-primary-button-text="s__('Labels|Promote Label')" :action-primary="$options.primaryProps"
footer-primary-button-variant="warning" :action-cancel="$options.cancelProps"
@submit="onSubmit" @primary="onSubmit"
> >
<div slot="title" class="modal-title-with-label"> <div slot="modal-title" class="modal-title-with-label">
<gl-sprintf <gl-sprintf
:message=" :message="
s__( s__(
......
...@@ -27,71 +27,55 @@ const initLabelIndex = () => { ...@@ -27,71 +27,55 @@ const initLabelIndex = () => {
eventHub.$once('promoteLabelModal.requestFinished', onRequestFinished); eventHub.$once('promoteLabelModal.requestFinished', onRequestFinished);
}; };
const onDeleteButtonClick = event => {
const button = event.currentTarget;
const modalProps = {
labelTitle: button.dataset.labelTitle,
labelColor: button.dataset.labelColor,
labelTextColor: button.dataset.labelTextColor,
url: button.dataset.url,
groupName: button.dataset.groupName,
};
eventHub.$once('promoteLabelModal.requestStarted', onRequestStarted);
eventHub.$emit('promoteLabelModal.props', modalProps);
};
const promoteLabelButtons = document.querySelectorAll('.js-promote-project-label-button'); const promoteLabelButtons = document.querySelectorAll('.js-promote-project-label-button');
promoteLabelButtons.forEach(button => {
button.addEventListener('click', onDeleteButtonClick);
});
eventHub.$once('promoteLabelModal.mounted', () => { return new Vue({
promoteLabelButtons.forEach(button => { el: '#js-promote-label-modal',
button.removeAttribute('disabled'); data() {
}); return {
}); modalProps: {
labelTitle: '',
labelColor: '',
labelTextColor: '',
url: '',
groupName: '',
},
};
},
mounted() {
eventHub.$on('promoteLabelModal.props', this.setModalProps);
eventHub.$emit('promoteLabelModal.mounted');
const promoteLabelModal = document.getElementById('promote-label-modal'); promoteLabelButtons.forEach(button => {
let promoteLabelModalComponent; button.removeAttribute('disabled');
button.addEventListener('click', () => {
this.$root.$emit('bv::show::modal', 'promote-label-modal');
eventHub.$once('promoteLabelModal.requestStarted', onRequestStarted);
if (promoteLabelModal) { this.setModalProps({
promoteLabelModalComponent = new Vue({ labelTitle: button.dataset.labelTitle,
el: promoteLabelModal, labelColor: button.dataset.labelColor,
components: { labelTextColor: button.dataset.labelTextColor,
PromoteLabelModal, url: button.dataset.url,
}, groupName: button.dataset.groupName,
data() { });
return {
modalProps: {
labelTitle: '',
labelColor: '',
labelTextColor: '',
url: '',
groupName: '',
},
};
},
mounted() {
eventHub.$on('promoteLabelModal.props', this.setModalProps);
eventHub.$emit('promoteLabelModal.mounted');
},
beforeDestroy() {
eventHub.$off('promoteLabelModal.props', this.setModalProps);
},
methods: {
setModalProps(modalProps) {
this.modalProps = modalProps;
},
},
render(createElement) {
return createElement('promote-label-modal', {
props: this.modalProps,
}); });
});
},
beforeDestroy() {
eventHub.$off('promoteLabelModal.props', this.setModalProps);
},
methods: {
setModalProps(modalProps) {
this.modalProps = modalProps;
}, },
}); },
} render(createElement) {
return createElement(PromoteLabelModal, {
return promoteLabelModalComponent; props: this.modalProps,
});
},
});
}; };
document.addEventListener('DOMContentLoaded', initLabelIndex); document.addEventListener('DOMContentLoaded', initLabelIndex);
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- labels_or_filters = @labels.exists? || search.present? || subscribed.present? - labels_or_filters = @labels.exists? || search.present? || subscribed.present?
- if labels_or_filters - if labels_or_filters
#promote-label-modal #js-promote-label-modal
= render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label = render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label
.labels-container.gl-mt-2 .labels-container.gl-mt-2
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- labels_or_filters = @labels.exists? || @prioritized_labels.exists? || search.present? || subscribed.present? - labels_or_filters = @labels.exists? || @prioritized_labels.exists? || search.present? || subscribed.present?
- if labels_or_filters - if labels_or_filters
#promote-label-modal #js-promote-label-modal
= render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label = render 'shared/labels/nav', labels_or_filters: labels_or_filters, can_admin_label: can_admin_label
.labels-container.gl-mt-3 .labels-container.gl-mt-3
......
...@@ -34,10 +34,7 @@ ...@@ -34,10 +34,7 @@
label_title: label.title, label_title: label.title,
label_color: label.color, label_color: label.color,
label_text_color: label.text_color, label_text_color: label.text_color,
group_name: label.project.group.name, group_name: label.project.group.name } }
target: '#promote-label-modal',
container: 'body',
toggle: 'modal' } }
= _('Promote to group label') = _('Promote to group label')
- if can?(current_user, :admin_label, label) - if can?(current_user, :admin_label, label)
%li %li
......
---
title: Migrate DeprecatedModal to GitLab UI Modal for promoted labels
merge_request: 46047
author:
type: changed
...@@ -32,10 +32,9 @@ describe('Promote label modal', () => { ...@@ -32,10 +32,9 @@ describe('Promote label modal', () => {
}); });
it('contains a label span with the color', () => { it('contains a label span with the color', () => {
const labelFromTitle = vm.$el.querySelector('.modal-header .label.color-label'); expect(vm.labelColor).not.toBe(null);
expect(vm.labelColor).toBe(labelMockData.labelColor);
expect(labelFromTitle.style.backgroundColor).not.toBe(null); expect(vm.labelTitle).toBe(labelMockData.labelTitle);
expect(labelFromTitle.textContent).toContain(vm.labelTitle);
}); });
}); });
......
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