summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/work_items/components/work_item_links/work_item_tree_children.vue
blob: 71de686768067551d11399764bdb7ca4a0fe450b (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
<script>
import { createAlert } from '~/flash';
import { s__ } from '~/locale';

import updateWorkItemMutation from '../../graphql/update_work_item.mutation.graphql';

export default {
  components: {
    WorkItemLinkChild: () => import('./work_item_link_child.vue'),
  },
  props: {
    workItemType: {
      type: String,
      required: true,
    },
    workItemId: {
      type: String,
      required: true,
    },
    children: {
      type: Array,
      required: false,
      default: () => [],
    },
    canUpdate: {
      type: Boolean,
      required: false,
      default: false,
    },
    projectPath: {
      type: String,
      required: true,
    },
  },
  methods: {
    async updateWorkItem(childId) {
      try {
        await this.$apollo.mutate({
          mutation: updateWorkItemMutation,
          variables: { input: { id: childId, hierarchyWidget: { parentId: null } } },
        });
        this.$emit('removeChild');
      } catch (error) {
        createAlert({
          message: s__('Hierarchy|Something went wrong while removing a child item.'),
          captureError: true,
          error,
        });
      }
    },
  },
};
</script>

<template>
  <div class="gl-ml-6">
    <work-item-link-child
      v-for="child in children"
      :key="child.id"
      :project-path="projectPath"
      :can-update="canUpdate"
      :issuable-gid="workItemId"
      :child-item="child"
      :work-item-type="workItemType"
      @removeChild="updateWorkItem"
      @click="$emit('click', Object.assign($event, { childItem: child }))"
    />
  </div>
</template>