Welcome to mirror list, hosted at ThFree Co, Russian Federation.

work_item_links.vue « work_item_links « components « work_items « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 89f086cfca5a4a39843f8ebafa79aee150c14165 (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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<script>
import { GlButton, GlBadge, GlIcon, GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { TYPE_WORK_ITEM } from '~/graphql_shared/constants';
import {
  STATE_OPEN,
  WIDGET_ICONS,
  WORK_ITEM_STATUS_TEXT,
  WIDGET_TYPE_HIERARCHY,
} from '../../constants';
import getWorkItemLinksQuery from '../../graphql/work_item_links.query.graphql';
import WorkItemLinksForm from './work_item_links_form.vue';
import WorkItemLinksMenu from './work_item_links_menu.vue';

export default {
  components: {
    GlButton,
    GlBadge,
    GlIcon,
    GlLoadingIcon,
    WorkItemLinksForm,
    WorkItemLinksMenu,
  },
  props: {
    workItemId: {
      type: String,
      required: false,
      default: null,
    },
    issuableId: {
      type: Number,
      required: false,
      default: null,
    },
  },
  apollo: {
    children: {
      query: getWorkItemLinksQuery,
      variables() {
        return {
          id: this.issuableGid,
        };
      },
      update(data) {
        return (
          data.workItem.widgets.find((widget) => widget.type === WIDGET_TYPE_HIERARCHY)?.children
            .nodes ?? []
        );
      },
      skip() {
        return !this.issuableId;
      },
    },
  },
  data() {
    return {
      isShownAddForm: false,
      isOpen: true,
      children: [],
    };
  },
  computed: {
    // Only used for children for now but should be extended later to support parents and siblings
    isChildrenEmpty() {
      return this.children?.length === 0;
    },
    toggleIcon() {
      return this.isOpen ? 'chevron-lg-up' : 'chevron-lg-down';
    },
    toggleLabel() {
      return this.isOpen
        ? s__('WorkItem|Collapse child items')
        : s__('WorkItem|Expand child items');
    },
    issuableGid() {
      return this.issuableId ? convertToGraphQLId(TYPE_WORK_ITEM, this.issuableId) : null;
    },
    isLoading() {
      return this.$apollo.queries.children.loading;
    },
    childrenIds() {
      return this.children.map((c) => c.id);
    },
  },
  methods: {
    badgeVariant(state) {
      return state === STATE_OPEN ? 'success' : 'info';
    },
    toggle() {
      this.isOpen = !this.isOpen;
    },
    toggleAddForm() {
      this.isShownAddForm = !this.isShownAddForm;
    },
    addChild(child) {
      this.children = [child, ...this.children];
    },
  },
  i18n: {
    title: s__('WorkItem|Child items'),
    emptyStateMessage: s__(
      'WorkItem|No child items are currently assigned. Use child items to prioritize tasks that your team should complete in order to accomplish your goals!',
    ),
    addChildButtonLabel: s__('WorkItem|Add a task'),
  },
  WIDGET_TYPE_TASK_ICON: WIDGET_ICONS.TASK,
  WORK_ITEM_STATUS_TEXT,
};
</script>

<template>
  <div class="gl-rounded-base gl-border-1 gl-border-solid gl-border-gray-100 gl-bg-gray-10">
    <div
      class="gl-p-4 gl-display-flex gl-justify-content-space-between"
      :class="{ 'gl-border-b-1 gl-border-b-solid gl-border-b-gray-100': isOpen }"
    >
      <h5 class="gl-m-0 gl-line-height-32 gl-flex-grow-1">{{ $options.i18n.title }}</h5>
      <gl-button
        v-if="!isShownAddForm"
        category="secondary"
        data-testid="toggle-add-form"
        @click="toggleAddForm"
      >
        {{ $options.i18n.addChildButtonLabel }}
      </gl-button>
      <div class="gl-border-l-1 gl-border-l-solid gl-border-l-gray-50 gl-pl-4 gl-ml-3">
        <gl-button
          category="tertiary"
          :icon="toggleIcon"
          :aria-label="toggleLabel"
          data-testid="toggle-links"
          @click="toggle"
        />
      </div>
    </div>
    <div
      v-if="isOpen"
      class="gl-bg-gray-10 gl-p-4 gl-rounded-bottom-left-base gl-rounded-bottom-right-base"
      data-testid="links-body"
    >
      <gl-loading-icon v-if="isLoading" color="dark" class="gl-my-3" />

      <template v-else>
        <div v-if="isChildrenEmpty && !isShownAddForm" data-testid="links-empty">
          <p class="gl-my-3">
            {{ $options.i18n.emptyStateMessage }}
          </p>
        </div>
        <work-item-links-form
          v-if="isShownAddForm"
          data-testid="add-links-form"
          :issuable-gid="issuableGid"
          :children-ids="childrenIds"
          @cancel="toggleAddForm"
          @addWorkItemChild="addChild"
        />
        <div
          v-for="child in children"
          :key="child.id"
          class="gl-relative gl-display-flex gl-flex-direction-column gl-sm-flex-direction-row gl-overflow-break-word gl-min-w-0 gl-bg-white gl-mb-3 gl-py-3 gl-px-4 gl-border gl-border-gray-100 gl-rounded-base gl-line-height-32"
          data-testid="links-child"
        >
          <div>
            <gl-icon :name="$options.WIDGET_TYPE_TASK_ICON" class="gl-mr-3 gl-text-gray-700" />
            <span class="gl-word-break-all">{{ child.title }}</span>
          </div>
          <div
            class="gl-ml-0 gl-sm-ml-auto! gl-mt-3 gl-sm-mt-0 gl-display-inline-flex gl-align-items-center"
          >
            <gl-badge :variant="badgeVariant(child.state)">
              <span class="gl-sm-display-block">{{
                $options.WORK_ITEM_STATUS_TEXT[child.state]
              }}</span>
            </gl-badge>
            <work-item-links-menu :work-item-id="child.id" :parent-work-item-id="issuableGid" />
          </div>
        </div>
      </template>
    </div>
  </div>
</template>