2021-06-02 15:09:59 +00:00
|
|
|
<script>
|
2021-09-03 12:09:03 +00:00
|
|
|
import { GlButton, GlDropdown, GlDropdownItem, GlLink } from '@gitlab/ui';
|
2021-09-29 03:12:00 +00:00
|
|
|
import { __, s__, sprintf } from '~/locale';
|
2021-06-02 15:09:59 +00:00
|
|
|
import DropdownContentsCreateView from './dropdown_contents_create_view.vue';
|
|
|
|
import DropdownContentsLabelsView from './dropdown_contents_labels_view.vue';
|
2021-10-11 15:13:01 +00:00
|
|
|
import { isDropdownVariantStandalone, isDropdownVariantSidebar } from './utils';
|
2021-06-02 15:09:59 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
DropdownContentsLabelsView,
|
|
|
|
DropdownContentsCreateView,
|
2021-06-16 12:10:18 +00:00
|
|
|
GlButton,
|
2021-09-03 12:09:03 +00:00
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlLink,
|
2021-06-02 15:09:59 +00:00
|
|
|
},
|
2021-09-03 12:09:03 +00:00
|
|
|
inject: ['allowLabelCreate', 'labelsManagePath'],
|
2021-06-02 15:09:59 +00:00
|
|
|
props: {
|
2021-06-16 12:10:18 +00:00
|
|
|
labelsCreateTitle: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-08-12 12:11:05 +00:00
|
|
|
selectedLabels: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
allowMultiselect: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
labelsListTitle: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-09-10 06:09:03 +00:00
|
|
|
dropdownButtonText: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-08-12 12:11:05 +00:00
|
|
|
footerCreateLabelTitle: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
footerManageLabelTitle: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-09-10 06:09:03 +00:00
|
|
|
variant: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-09-29 03:12:00 +00:00
|
|
|
issuableType: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-10-11 15:13:01 +00:00
|
|
|
isVisible: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2021-10-13 12:12:20 +00:00
|
|
|
fullPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
attrWorkspacePath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: undefined,
|
|
|
|
},
|
2021-09-10 06:09:03 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
showDropdownContentsCreateView: false,
|
2021-09-29 03:12:00 +00:00
|
|
|
localSelectedLabels: [...this.selectedLabels],
|
2021-10-11 15:13:01 +00:00
|
|
|
isDirty: false,
|
2021-09-10 06:09:03 +00:00
|
|
|
};
|
2021-06-02 15:09:59 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
dropdownContentsView() {
|
|
|
|
if (this.showDropdownContentsCreateView) {
|
|
|
|
return 'dropdown-contents-create-view';
|
|
|
|
}
|
|
|
|
return 'dropdown-contents-labels-view';
|
|
|
|
},
|
2021-06-16 12:10:18 +00:00
|
|
|
dropdownTitle() {
|
|
|
|
return this.showDropdownContentsCreateView ? this.labelsCreateTitle : this.labelsListTitle;
|
|
|
|
},
|
2021-09-29 03:12:00 +00:00
|
|
|
buttonText() {
|
|
|
|
if (!this.localSelectedLabels.length) {
|
|
|
|
return this.dropdownButtonText || __('Label');
|
|
|
|
} else if (this.localSelectedLabels.length > 1) {
|
|
|
|
return sprintf(s__('LabelSelect|%{firstLabelName} +%{remainingLabelCount} more'), {
|
|
|
|
firstLabelName: this.localSelectedLabels[0].title,
|
|
|
|
remainingLabelCount: this.localSelectedLabels.length - 1,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return this.localSelectedLabels[0].title;
|
|
|
|
},
|
2021-09-03 12:09:03 +00:00
|
|
|
showDropdownFooter() {
|
2021-09-29 03:12:00 +00:00
|
|
|
return !this.showDropdownContentsCreateView && !this.isStandalone;
|
2021-09-03 12:09:03 +00:00
|
|
|
},
|
2021-09-29 03:12:00 +00:00
|
|
|
isStandalone() {
|
|
|
|
return isDropdownVariantStandalone(this.variant);
|
|
|
|
},
|
|
|
|
},
|
2021-10-11 15:13:01 +00:00
|
|
|
watch: {
|
|
|
|
localSelectedLabels: {
|
|
|
|
handler() {
|
|
|
|
this.isDirty = true;
|
|
|
|
},
|
|
|
|
deep: true,
|
|
|
|
},
|
|
|
|
isVisible(newVal) {
|
|
|
|
if (newVal) {
|
|
|
|
this.$refs.dropdown.show();
|
|
|
|
this.isDirty = false;
|
|
|
|
} else {
|
|
|
|
this.$refs.dropdown.hide();
|
|
|
|
this.setLabels();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
selectedLabels(newVal) {
|
|
|
|
this.localSelectedLabels = newVal;
|
|
|
|
},
|
|
|
|
},
|
2021-06-16 12:10:18 +00:00
|
|
|
methods: {
|
2021-09-10 06:09:03 +00:00
|
|
|
toggleDropdownContentsCreateView() {
|
|
|
|
this.showDropdownContentsCreateView = !this.showDropdownContentsCreateView;
|
|
|
|
},
|
2021-09-03 12:09:03 +00:00
|
|
|
toggleDropdownContent() {
|
|
|
|
this.toggleDropdownContentsCreateView();
|
|
|
|
// Required to recalculate dropdown position as its size changes
|
2021-09-29 03:12:00 +00:00
|
|
|
if (this.$refs.dropdown?.$refs.dropdown) {
|
|
|
|
this.$refs.dropdown.$refs.dropdown.$_popper.scheduleUpdate();
|
|
|
|
}
|
|
|
|
},
|
2021-10-11 15:13:01 +00:00
|
|
|
setLabels() {
|
|
|
|
if (!this.isDirty) {
|
|
|
|
return;
|
|
|
|
}
|
2021-09-29 03:12:00 +00:00
|
|
|
this.$emit('setLabels', this.localSelectedLabels);
|
2021-10-11 15:13:01 +00:00
|
|
|
},
|
|
|
|
handleDropdownHide() {
|
|
|
|
if (!isDropdownVariantSidebar(this.variant)) {
|
|
|
|
this.setLabels();
|
|
|
|
}
|
2021-09-03 12:09:03 +00:00
|
|
|
},
|
2021-06-02 15:09:59 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-09-03 12:09:03 +00:00
|
|
|
<gl-dropdown
|
|
|
|
ref="dropdown"
|
2021-09-29 03:12:00 +00:00
|
|
|
:text="buttonText"
|
2021-09-03 12:09:03 +00:00
|
|
|
class="gl-w-full gl-mt-2"
|
2021-06-02 15:09:59 +00:00
|
|
|
data-qa-selector="labels_dropdown_content"
|
2021-10-11 15:13:01 +00:00
|
|
|
@hide="handleDropdownHide"
|
2021-06-02 15:09:59 +00:00
|
|
|
>
|
2021-09-03 12:09:03 +00:00
|
|
|
<template #header>
|
|
|
|
<div
|
2021-09-29 03:12:00 +00:00
|
|
|
v-if="!isStandalone"
|
2021-09-03 12:09:03 +00:00
|
|
|
class="dropdown-title gl-display-flex gl-align-items-center gl-pt-0 gl-pb-3!"
|
2021-09-29 03:12:00 +00:00
|
|
|
data-testid="dropdown-header"
|
2021-09-03 12:09:03 +00:00
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
v-if="showDropdownContentsCreateView"
|
|
|
|
:aria-label="__('Go back')"
|
|
|
|
variant="link"
|
|
|
|
size="small"
|
|
|
|
class="js-btn-back dropdown-header-button gl-p-0"
|
|
|
|
icon="arrow-left"
|
|
|
|
data-testid="go-back-button"
|
|
|
|
@click.stop="toggleDropdownContent"
|
|
|
|
/>
|
|
|
|
<span class="gl-flex-grow-1">{{ dropdownTitle }}</span>
|
|
|
|
<gl-button
|
|
|
|
:aria-label="__('Close')"
|
|
|
|
variant="link"
|
|
|
|
size="small"
|
|
|
|
class="dropdown-header-button gl-p-0!"
|
|
|
|
icon="close"
|
2021-09-29 03:12:00 +00:00
|
|
|
data-testid="close-button"
|
2021-10-11 15:13:01 +00:00
|
|
|
@click="$emit('closeDropdown')"
|
2021-09-03 12:09:03 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|
2021-09-29 03:12:00 +00:00
|
|
|
<template #default>
|
|
|
|
<component
|
|
|
|
:is="dropdownContentsView"
|
|
|
|
v-model="localSelectedLabels"
|
|
|
|
:selected-labels="selectedLabels"
|
|
|
|
:allow-multiselect="allowMultiselect"
|
|
|
|
:issuable-type="issuableType"
|
2021-10-13 12:12:20 +00:00
|
|
|
:full-path="fullPath"
|
|
|
|
:attr-workspace-path="attrWorkspacePath"
|
2021-09-29 03:12:00 +00:00
|
|
|
@hideCreateView="toggleDropdownContentsCreateView"
|
|
|
|
/>
|
|
|
|
</template>
|
2021-09-03 12:09:03 +00:00
|
|
|
<template #footer>
|
|
|
|
<div v-if="showDropdownFooter" data-testid="dropdown-footer">
|
|
|
|
<gl-dropdown-item
|
|
|
|
v-if="allowLabelCreate"
|
|
|
|
data-testid="create-label-button"
|
2021-09-29 03:12:00 +00:00
|
|
|
@click.capture.native.stop="toggleDropdownContent"
|
2021-09-03 12:09:03 +00:00
|
|
|
>
|
|
|
|
{{ footerCreateLabelTitle }}
|
|
|
|
</gl-dropdown-item>
|
2021-09-29 03:12:00 +00:00
|
|
|
<gl-dropdown-item :href="labelsManagePath" @click.capture.native.stop>
|
2021-09-03 12:09:03 +00:00
|
|
|
{{ footerManageLabelTitle }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</gl-dropdown>
|
2021-06-02 15:09:59 +00:00
|
|
|
</template>
|