summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/work_items/pages/work_item_root.vue
blob: 4262e169655377a840e0019d5016253c5ee81349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<script>
import { GlAlert } from '@gitlab/ui';
import Tracking from '~/tracking';
import workItemQuery from '../graphql/work_item.query.graphql';
import updateWorkItemMutation from '../graphql/update_work_item.mutation.graphql';
import { widgetTypes, WI_TITLE_TRACK_LABEL } from '../constants';

import ItemTitle from '../components/item_title.vue';

const trackingMixin = Tracking.mixin();

export default {
  titleUpdatedEvent: 'updated_title',
  components: {
    ItemTitle,
    GlAlert,
  },
  mixins: [trackingMixin],
  props: {
    id: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      workItem: null,
      error: false,
    };
  },
  apollo: {
    workItem: {
      query: workItemQuery,
      variables() {
        return {
          id: this.id,
        };
      },
    },
  },
  computed: {
    tracking() {
      return {
        category: 'workItems:show',
        action: 'updated_title',
        label: WI_TITLE_TRACK_LABEL,
        property: '[type_work_item]',
      };
    },
    titleWidgetData() {
      return this.workItem?.widgets?.nodes?.find((widget) => widget.type === widgetTypes.title);
    },
  },
  methods: {
    async updateWorkItem(title) {
      try {
        await this.$apollo.mutate({
          mutation: updateWorkItemMutation,
          variables: {
            input: {
              id: this.id,
              title,
            },
          },
        });
        this.track();
      } catch {
        this.error = true;
      }
    },
  },
};
</script>

<template>
  <section>
    <gl-alert v-if="error" variant="danger" @dismiss="error = false">{{
      __('Something went wrong while updating work item. Please try again')
    }}</gl-alert>
    <!-- Title widget placeholder -->
    <div>
      <item-title
        v-if="titleWidgetData"
        :initial-title="titleWidgetData.contentText"
        data-testid="title"
        @title-changed="updateWorkItem"
      />
    </div>
  </section>
</template>