2021-09-04 01:27:46 +05:30
|
|
|
<script>
|
2023-01-13 00:05:48 +05:30
|
|
|
import { GlButton, GlIcon, GlLink, GlPopover, GlTooltipDirective } from '@gitlab/ui';
|
2022-04-04 11:22:00 +05:30
|
|
|
import { kebabCase, snakeCase } from 'lodash';
|
2022-11-25 23:54:43 +05:30
|
|
|
import { createAlert } from '~/flash';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { IssuableType } from '~/issues/constants';
|
2021-10-27 15:23:28 +05:30
|
|
|
import { timeFor } from '~/lib/utils/datetime_utility';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { __ } from '~/locale';
|
2022-10-11 01:57:18 +05:30
|
|
|
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2021-09-04 01:27:46 +05:30
|
|
|
import {
|
2022-01-26 12:08:38 +05:30
|
|
|
dropdowni18nText,
|
2022-11-25 23:54:43 +05:30
|
|
|
LocalizedIssuableAttributeType,
|
|
|
|
IssuableAttributeTypeKeyMap,
|
2021-09-04 01:27:46 +05:30
|
|
|
issuableAttributesQueries,
|
2023-01-13 00:05:48 +05:30
|
|
|
IssuableAttributeType,
|
|
|
|
Tracking,
|
2022-01-26 12:08:38 +05:30
|
|
|
} from 'ee_else_ce/sidebar/constants';
|
2023-01-13 00:05:48 +05:30
|
|
|
import SidebarDropdown from './sidebar_dropdown.vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import SidebarEditableItem from './sidebar_editable_item.vue';
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
i18n: {
|
2021-09-30 23:02:18 +05:30
|
|
|
expired: __('(expired)'),
|
2021-09-04 01:27:46 +05:30
|
|
|
none: __('None'),
|
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
GlLink,
|
|
|
|
GlIcon,
|
2022-10-11 01:57:18 +05:30
|
|
|
GlPopover,
|
|
|
|
GlButton,
|
2023-01-13 00:05:48 +05:30
|
|
|
SidebarDropdown,
|
|
|
|
SidebarEditableItem,
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
2022-10-11 01:57:18 +05:30
|
|
|
mixins: [glFeatureFlagMixin()],
|
2021-09-04 01:27:46 +05:30
|
|
|
inject: {
|
|
|
|
isClassicSidebar: {
|
|
|
|
default: false,
|
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
issuableAttributesQueries: {
|
|
|
|
default: issuableAttributesQueries,
|
|
|
|
},
|
|
|
|
widgetTitleText: {
|
|
|
|
default: {
|
|
|
|
[IssuableAttributeType.Milestone]: __('Milestone'),
|
|
|
|
expired: __('(expired)'),
|
|
|
|
none: __('None'),
|
|
|
|
},
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
props: {
|
|
|
|
issuableAttribute: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
workspacePath: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
iid: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
attrWorkspacePath: {
|
|
|
|
required: true,
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
issuableType: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
validator(value) {
|
2021-09-30 23:02:18 +05:30
|
|
|
return [IssuableType.Issue, IssuableType.MergeRequest].includes(value);
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: undefined,
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
currentAttribute: {
|
|
|
|
query() {
|
|
|
|
const { current } = this.issuableAttributeQuery;
|
|
|
|
const { query } = current[this.issuableType];
|
|
|
|
|
|
|
|
return query;
|
|
|
|
},
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
fullPath: this.workspacePath,
|
|
|
|
iid: this.iid,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update(data) {
|
2022-10-11 01:57:18 +05:30
|
|
|
if (this.glFeatures?.epicWidgetEditConfirmation && this.isEpic) {
|
|
|
|
this.hasCurrentAttribute = data?.workspace?.issuable.hasEpic;
|
|
|
|
}
|
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
return data?.workspace?.issuable.attribute;
|
|
|
|
},
|
|
|
|
error(error) {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-04 01:27:46 +05:30
|
|
|
message: this.i18n.currentFetchError,
|
|
|
|
captureError: true,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
updating: false,
|
|
|
|
selectedTitle: null,
|
|
|
|
currentAttribute: null,
|
2022-10-11 01:57:18 +05:30
|
|
|
hasCurrentAttribute: false,
|
|
|
|
editConfirmation: false,
|
2021-09-04 01:27:46 +05:30
|
|
|
tracking: {
|
2021-09-30 23:02:18 +05:30
|
|
|
event: Tracking.editEvent,
|
|
|
|
label: Tracking.rightSidebarLabel,
|
2021-09-04 01:27:46 +05:30
|
|
|
property: this.issuableAttribute,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
issuableAttributeQuery() {
|
2022-01-26 12:08:38 +05:30
|
|
|
return this.issuableAttributesQueries[this.issuableAttribute];
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
attributeTitle() {
|
|
|
|
return this.currentAttribute?.title || this.i18n.noAttribute;
|
|
|
|
},
|
|
|
|
attributeUrl() {
|
|
|
|
return this.currentAttribute?.webUrl;
|
|
|
|
},
|
|
|
|
loading() {
|
|
|
|
return this.$apollo.queries.currentAttribute.loading;
|
|
|
|
},
|
|
|
|
attributeTypeTitle() {
|
2022-01-26 12:08:38 +05:30
|
|
|
return this.widgetTitleText[this.issuableAttribute];
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
attributeTypeIcon() {
|
|
|
|
return this.icon || this.issuableAttribute;
|
|
|
|
},
|
2021-10-27 15:23:28 +05:30
|
|
|
tooltipText() {
|
|
|
|
return timeFor(this.currentAttribute?.dueDate);
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
i18n() {
|
2022-11-25 23:54:43 +05:30
|
|
|
const localizedAttribute =
|
|
|
|
LocalizedIssuableAttributeType[IssuableAttributeTypeKeyMap[this.issuableAttribute]];
|
|
|
|
return dropdowni18nText(localizedAttribute, this.issuableType);
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
2021-10-27 15:23:28 +05:30
|
|
|
isEpic() {
|
2022-01-26 12:08:38 +05:30
|
|
|
// MV to EE https://gitlab.com/gitlab-org/gitlab/-/issues/345311
|
2021-10-27 15:23:28 +05:30
|
|
|
return this.issuableAttribute === IssuableType.Epic;
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
formatIssuableAttribute() {
|
|
|
|
return {
|
|
|
|
kebab: kebabCase(this.issuableAttribute),
|
|
|
|
snake: snakeCase(this.issuableAttribute),
|
|
|
|
};
|
|
|
|
},
|
2022-10-11 01:57:18 +05:30
|
|
|
shouldShowConfirmationPopover() {
|
|
|
|
if (!this.glFeatures?.epicWidgetEditConfirmation) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.isEpic && this.currentAttribute === null && this.hasCurrentAttribute
|
|
|
|
? !this.editConfirmation
|
|
|
|
: false;
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
methods: {
|
2023-01-13 00:05:48 +05:30
|
|
|
updateAttribute({ id }) {
|
|
|
|
if (this.currentAttribute === null && id === null) return;
|
|
|
|
if (id === this.currentAttribute?.id) return;
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
this.updating = true;
|
|
|
|
|
|
|
|
const { current } = this.issuableAttributeQuery;
|
|
|
|
const { mutation } = current[this.issuableType];
|
|
|
|
|
|
|
|
this.$apollo
|
|
|
|
.mutate({
|
|
|
|
mutation,
|
|
|
|
variables: {
|
|
|
|
fullPath: this.workspacePath,
|
|
|
|
attributeId:
|
2021-09-30 23:02:18 +05:30
|
|
|
this.issuableAttribute === IssuableAttributeType.Milestone &&
|
|
|
|
this.issuableType === IssuableType.Issue
|
2023-01-13 00:05:48 +05:30
|
|
|
? getIdFromGraphQLId(id)
|
|
|
|
: id,
|
2021-09-04 01:27:46 +05:30
|
|
|
iid: this.iid,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
if (data.issuableSetAttribute?.errors?.length) {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({
|
2021-09-04 01:27:46 +05:30
|
|
|
message: data.issuableSetAttribute.errors[0],
|
|
|
|
captureError: true,
|
|
|
|
error: data.issuableSetAttribute.errors[0],
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.$emit('attribute-updated', data);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
2022-11-25 23:54:43 +05:30
|
|
|
createAlert({ message: this.i18n.updateError, captureError: true, error });
|
2021-09-04 01:27:46 +05:30
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.updating = false;
|
|
|
|
this.selectedTitle = null;
|
|
|
|
});
|
|
|
|
},
|
2021-09-30 23:02:18 +05:30
|
|
|
isAttributeOverdue(attribute) {
|
|
|
|
return this.issuableAttribute === IssuableAttributeType.Milestone
|
|
|
|
? attribute?.expired
|
|
|
|
: false;
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
showDropdown() {
|
2023-01-13 00:05:48 +05:30
|
|
|
this.$refs.dropdown.show();
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
2022-10-11 01:57:18 +05:30
|
|
|
handlePopoverClose() {
|
|
|
|
this.$refs.popover.$emit('close');
|
|
|
|
},
|
|
|
|
handlePopoverConfirm(cb) {
|
|
|
|
this.editConfirmation = true;
|
|
|
|
this.handlePopoverClose();
|
|
|
|
setTimeout(cb, 0);
|
|
|
|
},
|
|
|
|
handleEditConfirmation() {
|
|
|
|
this.$refs.popover.$emit('open');
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<sidebar-editable-item
|
|
|
|
ref="editable"
|
|
|
|
:title="attributeTypeTitle"
|
2022-04-04 11:22:00 +05:30
|
|
|
:data-testid="`${formatIssuableAttribute.kebab}-edit`"
|
2022-10-11 01:57:18 +05:30
|
|
|
:button-id="`${formatIssuableAttribute.kebab}-edit`"
|
2021-09-04 01:27:46 +05:30
|
|
|
:tracking="tracking"
|
2022-10-11 01:57:18 +05:30
|
|
|
:should-show-confirmation-popover="shouldShowConfirmationPopover"
|
2021-09-04 01:27:46 +05:30
|
|
|
:loading="updating || loading"
|
2023-01-13 00:05:48 +05:30
|
|
|
@open="showDropdown"
|
2022-10-11 01:57:18 +05:30
|
|
|
@edit-confirm="handleEditConfirmation"
|
2021-09-04 01:27:46 +05:30
|
|
|
>
|
|
|
|
<template #collapsed>
|
2022-04-04 11:22:00 +05:30
|
|
|
<slot name="value-collapsed" :current-attribute="currentAttribute">
|
|
|
|
<div
|
|
|
|
v-if="isClassicSidebar"
|
|
|
|
v-gl-tooltip.left.viewport
|
|
|
|
:title="attributeTypeTitle"
|
|
|
|
class="sidebar-collapsed-icon"
|
|
|
|
>
|
|
|
|
<gl-icon :aria-label="attributeTypeTitle" :name="attributeTypeIcon" />
|
2022-07-23 23:45:48 +05:30
|
|
|
<span class="collapse-truncated-title gl-pt-2 gl-px-3 gl-font-sm">
|
2022-04-04 11:22:00 +05:30
|
|
|
{{ attributeTitle }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</slot>
|
2021-09-04 01:27:46 +05:30
|
|
|
<div
|
2022-04-04 11:22:00 +05:30
|
|
|
:data-testid="`select-${formatIssuableAttribute.kebab}`"
|
2021-09-04 01:27:46 +05:30
|
|
|
:class="isClassicSidebar ? 'hide-collapsed' : 'gl-mt-3'"
|
|
|
|
>
|
2022-07-16 23:28:13 +05:30
|
|
|
<span v-if="updating">{{ selectedTitle }}</span>
|
2022-10-11 01:57:18 +05:30
|
|
|
<template v-else-if="!currentAttribute && hasCurrentAttribute">
|
|
|
|
<gl-icon name="warning" class="gl-text-orange-500" />
|
|
|
|
<span class="gl-text-gray-500">{{ i18n.noPermissionToView }}</span>
|
|
|
|
</template>
|
2021-09-04 01:27:46 +05:30
|
|
|
<span v-else-if="!currentAttribute" class="gl-text-gray-500">
|
|
|
|
{{ $options.i18n.none }}
|
|
|
|
</span>
|
|
|
|
<slot
|
|
|
|
v-else
|
|
|
|
name="value"
|
2022-07-16 23:28:13 +05:30
|
|
|
:attribute-title="attributeTitle"
|
|
|
|
:attribute-url="attributeUrl"
|
|
|
|
:current-attribute="currentAttribute"
|
2021-09-04 01:27:46 +05:30
|
|
|
>
|
2021-09-30 23:02:18 +05:30
|
|
|
<gl-link
|
2021-10-27 15:23:28 +05:30
|
|
|
v-gl-tooltip="tooltipText"
|
2022-10-11 01:57:18 +05:30
|
|
|
class="gl-reset-color gl-hover-text-blue-800"
|
2021-09-30 23:02:18 +05:30
|
|
|
:href="attributeUrl"
|
2022-04-04 11:22:00 +05:30
|
|
|
:data-qa-selector="`${formatIssuableAttribute.snake}_link`"
|
2021-09-30 23:02:18 +05:30
|
|
|
>
|
2021-09-04 01:27:46 +05:30
|
|
|
{{ attributeTitle }}
|
2021-09-30 23:02:18 +05:30
|
|
|
<span v-if="isAttributeOverdue(currentAttribute)">{{ $options.i18n.expired }}</span>
|
2021-09-04 01:27:46 +05:30
|
|
|
</gl-link>
|
|
|
|
</slot>
|
|
|
|
</div>
|
|
|
|
</template>
|
2022-10-11 01:57:18 +05:30
|
|
|
<template v-if="shouldShowConfirmationPopover" #default="{ toggle }">
|
|
|
|
<gl-popover
|
|
|
|
ref="popover"
|
|
|
|
:target="`${formatIssuableAttribute.kebab}-edit`"
|
|
|
|
placement="bottomleft"
|
|
|
|
boundary="viewport"
|
|
|
|
triggers="click"
|
|
|
|
>
|
|
|
|
<div class="gl-mb-4 gl-font-base">
|
|
|
|
{{ i18n.editConfirmation }}
|
|
|
|
</div>
|
|
|
|
<div class="gl-display-flex gl-align-items-center">
|
|
|
|
<gl-button
|
|
|
|
size="small"
|
|
|
|
variant="confirm"
|
|
|
|
category="primary"
|
|
|
|
data-testid="confirm-edit-cta"
|
|
|
|
@click.prevent="() => handlePopoverConfirm(toggle)"
|
|
|
|
>{{ i18n.editConfirmationCta }}</gl-button
|
|
|
|
>
|
|
|
|
<gl-button
|
|
|
|
class="gl-ml-auto"
|
|
|
|
size="small"
|
|
|
|
name="cancel"
|
|
|
|
variant="default"
|
|
|
|
category="primary"
|
|
|
|
data-testid="confirm-edit-cancel"
|
|
|
|
@click.prevent="handlePopoverClose"
|
|
|
|
>{{ i18n.editConfirmationCancel }}</gl-button
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</gl-popover>
|
|
|
|
</template>
|
|
|
|
<template v-else #default>
|
2023-01-13 00:05:48 +05:30
|
|
|
<sidebar-dropdown
|
|
|
|
ref="dropdown"
|
|
|
|
:attr-workspace-path="attrWorkspacePath"
|
|
|
|
:current-attribute="currentAttribute"
|
|
|
|
:issuable-attribute="issuableAttribute"
|
|
|
|
:issuable-type="issuableType"
|
|
|
|
@change="updateAttribute"
|
2021-09-04 01:27:46 +05:30
|
|
|
>
|
2023-01-13 00:05:48 +05:30
|
|
|
<template #list="{ attributesList, isAttributeChecked, updateAttribute: update }">
|
2021-09-04 01:27:46 +05:30
|
|
|
<slot
|
|
|
|
name="list"
|
2022-07-16 23:28:13 +05:30
|
|
|
:attributes-list="attributesList"
|
|
|
|
:is-attribute-checked="isAttributeChecked"
|
2023-01-13 00:05:48 +05:30
|
|
|
:update-attribute="update"
|
2021-09-04 01:27:46 +05:30
|
|
|
>
|
|
|
|
</slot>
|
|
|
|
</template>
|
2023-01-13 00:05:48 +05:30
|
|
|
</sidebar-dropdown>
|
2021-09-04 01:27:46 +05:30
|
|
|
</template>
|
|
|
|
</sidebar-editable-item>
|
|
|
|
</template>
|