2021-10-19 12:12:07 +00:00
|
|
|
<script>
|
2022-03-10 06:09:00 +00:00
|
|
|
import { GlAlert, GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import { convertToGraphQLId } from '~/graphql_shared/utils';
|
2022-01-13 18:16:51 +00:00
|
|
|
import Tracking from '~/tracking';
|
2021-10-19 12:12:07 +00:00
|
|
|
import workItemQuery from '../graphql/work_item.query.graphql';
|
2021-12-08 12:13:04 +00:00
|
|
|
import updateWorkItemMutation from '../graphql/update_work_item.mutation.graphql';
|
2022-03-10 06:09:00 +00:00
|
|
|
import { WI_TITLE_TRACK_LABEL } from '../constants';
|
2021-10-19 12:12:07 +00:00
|
|
|
|
2021-12-08 12:13:04 +00:00
|
|
|
import ItemTitle from '../components/item_title.vue';
|
|
|
|
|
2022-01-13 18:16:51 +00:00
|
|
|
const trackingMixin = Tracking.mixin();
|
|
|
|
|
2021-10-19 12:12:07 +00:00
|
|
|
export default {
|
2022-01-13 18:16:51 +00:00
|
|
|
titleUpdatedEvent: 'updated_title',
|
2021-12-08 12:13:04 +00:00
|
|
|
components: {
|
|
|
|
ItemTitle,
|
|
|
|
GlAlert,
|
2022-03-10 06:09:00 +00:00
|
|
|
GlLoadingIcon,
|
2021-12-08 12:13:04 +00:00
|
|
|
},
|
2022-01-13 18:16:51 +00:00
|
|
|
mixins: [trackingMixin],
|
2021-10-19 12:12:07 +00:00
|
|
|
props: {
|
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-03-10 06:09:00 +00:00
|
|
|
workItem: {},
|
2021-12-08 12:13:04 +00:00
|
|
|
error: false,
|
2021-10-19 12:12:07 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
workItem: {
|
|
|
|
query: workItemQuery,
|
|
|
|
variables() {
|
|
|
|
return {
|
2022-03-10 06:09:00 +00:00
|
|
|
id: this.gid,
|
2021-10-19 12:12:07 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
computed: {
|
2022-01-13 18:16:51 +00:00
|
|
|
tracking() {
|
|
|
|
return {
|
|
|
|
category: 'workItems:show',
|
|
|
|
action: 'updated_title',
|
|
|
|
label: WI_TITLE_TRACK_LABEL,
|
|
|
|
property: '[type_work_item]',
|
|
|
|
};
|
|
|
|
},
|
2022-03-10 06:09:00 +00:00
|
|
|
gid() {
|
|
|
|
return convertToGraphQLId('WorkItem', this.id);
|
2021-10-19 12:12:07 +00:00
|
|
|
},
|
|
|
|
},
|
2021-12-08 12:13:04 +00:00
|
|
|
methods: {
|
2022-03-10 06:09:00 +00:00
|
|
|
async updateWorkItem(updatedTitle) {
|
2021-12-08 12:13:04 +00:00
|
|
|
try {
|
|
|
|
await this.$apollo.mutate({
|
|
|
|
mutation: updateWorkItemMutation,
|
|
|
|
variables: {
|
|
|
|
input: {
|
2022-03-10 06:09:00 +00:00
|
|
|
id: this.gid,
|
|
|
|
title: updatedTitle,
|
2021-12-08 12:13:04 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-01-13 18:16:51 +00:00
|
|
|
this.track();
|
2021-12-08 12:13:04 +00:00
|
|
|
} catch {
|
|
|
|
this.error = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2021-10-19 12:12:07 +00:00
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<section>
|
2021-12-08 12:13:04 +00:00
|
|
|
<gl-alert v-if="error" variant="danger" @dismiss="error = false">{{
|
|
|
|
__('Something went wrong while updating work item. Please try again')
|
|
|
|
}}</gl-alert>
|
2021-10-19 12:12:07 +00:00
|
|
|
<!-- Title widget placeholder -->
|
|
|
|
<div>
|
2022-03-10 06:09:00 +00:00
|
|
|
<gl-loading-icon
|
|
|
|
v-if="$apollo.queries.workItem.loading"
|
|
|
|
size="md"
|
|
|
|
data-testid="loading-types"
|
2021-12-08 12:13:04 +00:00
|
|
|
/>
|
2022-03-10 06:09:00 +00:00
|
|
|
<template v-else>
|
|
|
|
<item-title
|
|
|
|
:initial-title="workItem.title"
|
|
|
|
data-testid="title"
|
|
|
|
@title-changed="updateWorkItem"
|
|
|
|
/>
|
|
|
|
</template>
|
2021-10-19 12:12:07 +00:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</template>
|