2021-06-08 05:09:56 -04:00
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
GlLink,
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownText,
|
|
|
|
GlSearchBoxByType,
|
|
|
|
GlDropdownDivider,
|
|
|
|
GlLoadingIcon,
|
|
|
|
GlIcon,
|
|
|
|
GlTooltipDirective,
|
|
|
|
} from '@gitlab/ui';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
|
|
|
import { IssuableType } from '~/issue_show/constants';
|
2021-08-13 08:10:58 -04:00
|
|
|
import { timeFor } from '~/lib/utils/datetime_utility';
|
2021-06-08 05:09:56 -04:00
|
|
|
import { __, s__, sprintf } from '~/locale';
|
|
|
|
import SidebarEditableItem from '~/sidebar/components/sidebar_editable_item.vue';
|
|
|
|
import {
|
2021-07-09 02:08:14 -04:00
|
|
|
Tracking,
|
2021-06-08 05:09:56 -04:00
|
|
|
IssuableAttributeState,
|
|
|
|
IssuableAttributeType,
|
|
|
|
issuableAttributesQueries,
|
|
|
|
noAttributeId,
|
2021-06-21 17:08:33 -04:00
|
|
|
defaultEpicSort,
|
2021-07-27 11:09:49 -04:00
|
|
|
epicIidPattern,
|
2021-07-09 02:08:14 -04:00
|
|
|
} from '~/sidebar/constants';
|
2021-06-08 05:09:56 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
noAttributeId,
|
|
|
|
IssuableAttributeState,
|
|
|
|
issuableAttributesQueries,
|
|
|
|
i18n: {
|
|
|
|
[IssuableAttributeType.Milestone]: __('Milestone'),
|
2021-07-07 14:08:30 -04:00
|
|
|
expired: __('(expired)'),
|
2021-06-08 05:09:56 -04:00
|
|
|
none: __('None'),
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
SidebarEditableItem,
|
|
|
|
GlLink,
|
|
|
|
GlDropdown,
|
|
|
|
GlDropdownItem,
|
|
|
|
GlDropdownText,
|
|
|
|
GlDropdownDivider,
|
|
|
|
GlSearchBoxByType,
|
|
|
|
GlIcon,
|
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
|
|
|
inject: {
|
|
|
|
isClassicSidebar: {
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
issuableAttribute: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
validator(value) {
|
|
|
|
return [IssuableAttributeType.Milestone].includes(value);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
workspacePath: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
iid: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
attrWorkspacePath: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
issuableType: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
validator(value) {
|
2021-07-07 14:08:30 -04:00
|
|
|
return [IssuableType.Issue, IssuableType.MergeRequest].includes(value);
|
2021-06-08 05:09:56 -04:00
|
|
|
},
|
|
|
|
},
|
2021-07-07 14:08:30 -04:00
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: undefined,
|
|
|
|
},
|
2021-06-08 05:09:56 -04:00
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
currentAttribute: {
|
|
|
|
query() {
|
|
|
|
const { current } = this.issuableAttributeQuery;
|
|
|
|
const { query } = current[this.issuableType];
|
|
|
|
|
|
|
|
return query;
|
|
|
|
},
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
fullPath: this.workspacePath,
|
|
|
|
iid: this.iid,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
|
|
|
return data?.workspace?.issuable.attribute;
|
|
|
|
},
|
|
|
|
error(error) {
|
|
|
|
createFlash({
|
|
|
|
message: this.i18n.currentFetchError,
|
|
|
|
captureError: true,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
attributesList: {
|
|
|
|
query() {
|
|
|
|
const { list } = this.issuableAttributeQuery;
|
|
|
|
const { query } = list[this.issuableType];
|
|
|
|
|
|
|
|
return query;
|
|
|
|
},
|
|
|
|
skip() {
|
2021-07-27 11:09:49 -04:00
|
|
|
if (this.isEpic && this.searchTerm.startsWith('&') && this.searchTerm.length < 2) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-08 05:09:56 -04:00
|
|
|
return !this.editing;
|
|
|
|
},
|
|
|
|
debounce: 250,
|
|
|
|
variables() {
|
2021-07-27 11:09:49 -04:00
|
|
|
if (!this.isEpic) {
|
|
|
|
return {
|
|
|
|
fullPath: this.attrWorkspacePath,
|
|
|
|
title: this.searchTerm,
|
|
|
|
state: this.$options.IssuableAttributeState[this.issuableAttribute],
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const variables = {
|
2021-06-08 05:09:56 -04:00
|
|
|
fullPath: this.attrWorkspacePath,
|
|
|
|
state: this.$options.IssuableAttributeState[this.issuableAttribute],
|
2021-07-27 11:09:49 -04:00
|
|
|
sort: defaultEpicSort,
|
2021-06-08 05:09:56 -04:00
|
|
|
};
|
2021-07-27 11:09:49 -04:00
|
|
|
|
|
|
|
if (epicIidPattern.test(this.searchTerm)) {
|
|
|
|
const matches = this.searchTerm.match(epicIidPattern);
|
|
|
|
variables.iidStartsWith = matches.groups.iid;
|
|
|
|
} else if (this.searchTerm !== '') {
|
|
|
|
variables.in = 'TITLE';
|
|
|
|
variables.title = this.searchTerm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return variables;
|
2021-06-08 05:09:56 -04:00
|
|
|
},
|
|
|
|
update(data) {
|
|
|
|
if (data?.workspace) {
|
|
|
|
return data?.workspace?.attributes.nodes;
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
error(error) {
|
|
|
|
createFlash({ message: this.i18n.listFetchError, captureError: true, error });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
searchTerm: '',
|
|
|
|
editing: false,
|
|
|
|
updating: false,
|
|
|
|
selectedTitle: null,
|
|
|
|
currentAttribute: null,
|
|
|
|
attributesList: [],
|
|
|
|
tracking: {
|
2021-07-09 02:08:14 -04:00
|
|
|
event: Tracking.editEvent,
|
|
|
|
label: Tracking.rightSidebarLabel,
|
2021-06-08 05:09:56 -04:00
|
|
|
property: this.issuableAttribute,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
issuableAttributeQuery() {
|
|
|
|
return this.$options.issuableAttributesQueries[this.issuableAttribute];
|
|
|
|
},
|
|
|
|
attributeTitle() {
|
|
|
|
return this.currentAttribute?.title || this.i18n.noAttribute;
|
|
|
|
},
|
|
|
|
attributeUrl() {
|
|
|
|
return this.currentAttribute?.webUrl;
|
|
|
|
},
|
|
|
|
dropdownText() {
|
|
|
|
return this.currentAttribute
|
|
|
|
? this.currentAttribute?.title
|
|
|
|
: this.$options.i18n[this.issuableAttribute];
|
|
|
|
},
|
|
|
|
loading() {
|
|
|
|
return this.$apollo.queries.currentAttribute.loading;
|
|
|
|
},
|
|
|
|
emptyPropsList() {
|
|
|
|
return this.attributesList.length === 0;
|
|
|
|
},
|
|
|
|
attributeTypeTitle() {
|
|
|
|
return this.$options.i18n[this.issuableAttribute];
|
|
|
|
},
|
2021-07-07 14:08:30 -04:00
|
|
|
attributeTypeIcon() {
|
|
|
|
return this.icon || this.issuableAttribute;
|
|
|
|
},
|
2021-08-13 08:10:58 -04:00
|
|
|
tooltipText() {
|
|
|
|
return timeFor(this.currentAttribute?.dueDate);
|
|
|
|
},
|
2021-06-08 05:09:56 -04:00
|
|
|
i18n() {
|
|
|
|
return {
|
|
|
|
noAttribute: sprintf(s__('DropdownWidget|No %{issuableAttribute}'), {
|
|
|
|
issuableAttribute: this.issuableAttribute,
|
|
|
|
}),
|
|
|
|
assignAttribute: sprintf(s__('DropdownWidget|Assign %{issuableAttribute}'), {
|
|
|
|
issuableAttribute: this.issuableAttribute,
|
|
|
|
}),
|
|
|
|
noAttributesFound: sprintf(s__('DropdownWidget|No %{issuableAttribute} found'), {
|
|
|
|
issuableAttribute: this.issuableAttribute,
|
|
|
|
}),
|
|
|
|
updateError: sprintf(
|
|
|
|
s__(
|
|
|
|
'DropdownWidget|Failed to set %{issuableAttribute} on this %{issuableType}. Please try again.',
|
|
|
|
),
|
|
|
|
{ issuableAttribute: this.issuableAttribute, issuableType: this.issuableType },
|
|
|
|
),
|
|
|
|
listFetchError: sprintf(
|
|
|
|
s__(
|
|
|
|
'DropdownWidget|Failed to fetch the %{issuableAttribute} for this %{issuableType}. Please try again.',
|
|
|
|
),
|
|
|
|
{ issuableAttribute: this.issuableAttribute, issuableType: this.issuableType },
|
|
|
|
),
|
|
|
|
currentFetchError: sprintf(
|
|
|
|
s__(
|
|
|
|
'DropdownWidget|An error occurred while fetching the assigned %{issuableAttribute} of the selected %{issuableType}.',
|
|
|
|
),
|
|
|
|
{ issuableAttribute: this.issuableAttribute, issuableType: this.issuableType },
|
|
|
|
),
|
|
|
|
};
|
|
|
|
},
|
2021-07-27 11:09:49 -04:00
|
|
|
isEpic() {
|
|
|
|
return this.issuableAttribute === IssuableType.Epic;
|
|
|
|
},
|
2021-06-08 05:09:56 -04:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
updateAttribute(attributeId) {
|
|
|
|
if (this.currentAttribute === null && attributeId === null) return;
|
|
|
|
if (attributeId === this.currentAttribute?.id) return;
|
|
|
|
|
|
|
|
this.updating = true;
|
|
|
|
|
|
|
|
const selectedAttribute =
|
|
|
|
Boolean(attributeId) && this.attributesList.find((p) => p.id === attributeId);
|
|
|
|
this.selectedTitle = selectedAttribute ? selectedAttribute.title : this.$options.i18n.none;
|
|
|
|
|
|
|
|
const { current } = this.issuableAttributeQuery;
|
|
|
|
const { mutation } = current[this.issuableType];
|
|
|
|
|
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
|
|
|
mutation,
|
|
|
|
variables: {
|
|
|
|
fullPath: this.workspacePath,
|
|
|
|
attributeId:
|
2021-07-07 14:08:30 -04:00
|
|
|
this.issuableAttribute === IssuableAttributeType.Milestone &&
|
|
|
|
this.issuableType === IssuableType.Issue
|
2021-06-08 05:09:56 -04:00
|
|
|
? getIdFromGraphQLId(attributeId)
|
|
|
|
: attributeId,
|
|
|
|
iid: this.iid,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
if (data.issuableSetAttribute?.errors?.length) {
|
|
|
|
createFlash({
|
|
|
|
message: data.issuableSetAttribute.errors[0],
|
|
|
|
captureError: true,
|
|
|
|
error: data.issuableSetAttribute.errors[0],
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$emit('attribute-updated', data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
createFlash({ message: this.i18n.updateError, captureError: true, error });
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.updating = false;
|
|
|
|
this.searchTerm = '';
|
|
|
|
this.selectedTitle = null;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
isAttributeChecked(attributeId = undefined) {
|
|
|
|
return (
|
|
|
|
attributeId === this.currentAttribute?.id || (!this.currentAttribute?.id && !attributeId)
|
|
|
|
);
|
|
|
|
},
|
2021-07-07 14:08:30 -04:00
|
|
|
isAttributeOverdue(attribute) {
|
|
|
|
return this.issuableAttribute === IssuableAttributeType.Milestone
|
|
|
|
? attribute?.expired
|
|
|
|
: false;
|
|
|
|
},
|
2021-06-08 05:09:56 -04:00
|
|
|
showDropdown() {
|
|
|
|
this.$refs.newDropdown.show();
|
|
|
|
},
|
|
|
|
handleOpen() {
|
|
|
|
this.editing = true;
|
|
|
|
this.showDropdown();
|
|
|
|
},
|
|
|
|
handleClose() {
|
|
|
|
this.editing = false;
|
|
|
|
},
|
|
|
|
setFocus() {
|
|
|
|
this.$refs.search.focusInput();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<sidebar-editable-item
|
|
|
|
ref="editable"
|
|
|
|
:title="attributeTypeTitle"
|
|
|
|
:data-testid="`${issuableAttribute}-edit`"
|
|
|
|
:tracking="tracking"
|
|
|
|
:loading="updating || loading"
|
|
|
|
@open="handleOpen"
|
|
|
|
@close="handleClose"
|
|
|
|
>
|
|
|
|
<template #collapsed>
|
|
|
|
<div v-if="isClassicSidebar" v-gl-tooltip class="sidebar-collapsed-icon">
|
2021-07-07 14:08:30 -04:00
|
|
|
<gl-icon :size="16" :aria-label="attributeTypeTitle" :name="attributeTypeIcon" />
|
|
|
|
<span class="collapse-truncated-title">
|
|
|
|
{{ attributeTitle }}
|
|
|
|
</span>
|
2021-06-08 05:09:56 -04:00
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
:data-testid="`select-${issuableAttribute}`"
|
|
|
|
:class="isClassicSidebar ? 'hide-collapsed' : 'gl-mt-3'"
|
|
|
|
>
|
|
|
|
<span v-if="updating" class="gl-font-weight-bold">{{ selectedTitle }}</span>
|
|
|
|
<span v-else-if="!currentAttribute" class="gl-text-gray-500">
|
|
|
|
{{ $options.i18n.none }}
|
|
|
|
</span>
|
2021-06-14 11:09:48 -04:00
|
|
|
<slot
|
|
|
|
v-else
|
|
|
|
name="value"
|
|
|
|
:attributeTitle="attributeTitle"
|
|
|
|
:attributeUrl="attributeUrl"
|
|
|
|
:currentAttribute="currentAttribute"
|
|
|
|
>
|
2021-06-17 17:10:25 -04:00
|
|
|
<gl-link
|
2021-08-13 08:10:58 -04:00
|
|
|
v-gl-tooltip="tooltipText"
|
2021-06-17 17:10:25 -04:00
|
|
|
class="gl-text-gray-900! gl-font-weight-bold"
|
|
|
|
:href="attributeUrl"
|
|
|
|
:data-qa-selector="`${issuableAttribute}_link`"
|
|
|
|
>
|
2021-06-14 11:09:48 -04:00
|
|
|
{{ attributeTitle }}
|
2021-07-07 14:08:30 -04:00
|
|
|
<span v-if="isAttributeOverdue(currentAttribute)">{{ $options.i18n.expired }}</span>
|
2021-06-14 11:09:48 -04:00
|
|
|
</gl-link>
|
|
|
|
</slot>
|
2021-06-08 05:09:56 -04:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template #default>
|
|
|
|
<gl-dropdown
|
|
|
|
ref="newDropdown"
|
|
|
|
lazy
|
|
|
|
:header-text="i18n.assignAttribute"
|
|
|
|
:text="dropdownText"
|
|
|
|
:loading="loading"
|
|
|
|
class="gl-w-full"
|
2021-09-07 11:11:06 -04:00
|
|
|
toggle-class="gl-max-w-100"
|
2021-11-12 16:12:01 -05:00
|
|
|
block
|
2021-06-08 05:09:56 -04:00
|
|
|
@shown="setFocus"
|
|
|
|
>
|
|
|
|
<gl-search-box-by-type ref="search" v-model="searchTerm" />
|
|
|
|
<gl-dropdown-item
|
|
|
|
:data-testid="`no-${issuableAttribute}-item`"
|
|
|
|
:is-check-item="true"
|
|
|
|
:is-checked="isAttributeChecked($options.noAttributeId)"
|
|
|
|
@click="updateAttribute($options.noAttributeId)"
|
|
|
|
>
|
|
|
|
{{ i18n.noAttribute }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-divider />
|
|
|
|
<gl-loading-icon
|
|
|
|
v-if="$apollo.queries.attributesList.loading"
|
2021-07-07 05:08:35 -04:00
|
|
|
size="sm"
|
2021-06-08 05:09:56 -04:00
|
|
|
class="gl-py-4"
|
|
|
|
data-testid="loading-icon-dropdown"
|
|
|
|
/>
|
|
|
|
<template v-else>
|
|
|
|
<gl-dropdown-text v-if="emptyPropsList">
|
|
|
|
{{ i18n.noAttributesFound }}
|
|
|
|
</gl-dropdown-text>
|
2021-06-14 11:09:48 -04:00
|
|
|
<slot
|
|
|
|
v-else
|
|
|
|
name="list"
|
|
|
|
:attributesList="attributesList"
|
|
|
|
:isAttributeChecked="isAttributeChecked"
|
|
|
|
:updateAttribute="updateAttribute"
|
2021-06-08 05:09:56 -04:00
|
|
|
>
|
2021-06-14 11:09:48 -04:00
|
|
|
<gl-dropdown-item
|
|
|
|
v-for="attrItem in attributesList"
|
|
|
|
:key="attrItem.id"
|
|
|
|
:is-check-item="true"
|
|
|
|
:is-checked="isAttributeChecked(attrItem.id)"
|
|
|
|
:data-testid="`${issuableAttribute}-items`"
|
|
|
|
@click="updateAttribute(attrItem.id)"
|
|
|
|
>
|
|
|
|
{{ attrItem.title }}
|
2021-07-07 14:08:30 -04:00
|
|
|
<span v-if="isAttributeOverdue(attrItem)">{{ $options.i18n.expired }}</span>
|
2021-06-14 11:09:48 -04:00
|
|
|
</gl-dropdown-item>
|
|
|
|
</slot>
|
2021-06-08 05:09:56 -04:00
|
|
|
</template>
|
|
|
|
</gl-dropdown>
|
|
|
|
</template>
|
|
|
|
</sidebar-editable-item>
|
|
|
|
</template>
|