summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/components/board_add_new_column.vue
blob: 3c7c792b787b803da396ac10e4b09021b3284117 (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
<script>
import {
  GlFormRadio,
  GlFormRadioGroup,
  GlLabel,
  GlTooltipDirective as GlTooltip,
} from '@gitlab/ui';
import { mapActions, mapGetters, mapState } from 'vuex';
import BoardAddNewColumnForm from '~/boards/components/board_add_new_column_form.vue';
import { ListType } from '~/boards/constants';
import boardsStore from '~/boards/stores/boards_store';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { isScopedLabel } from '~/lib/utils/common_utils';

export default {
  components: {
    BoardAddNewColumnForm,
    GlFormRadio,
    GlFormRadioGroup,
    GlLabel,
  },
  directives: {
    GlTooltip,
  },
  inject: ['scopedLabelsAvailable'],
  data() {
    return {
      selectedId: null,
    };
  },
  computed: {
    ...mapState(['labels', 'labelsLoading']),
    ...mapGetters(['getListByLabelId', 'shouldUseGraphQL']),
    selectedLabel() {
      if (!this.selectedId) {
        return null;
      }
      return this.labels.find(({ id }) => id === this.selectedId);
    },
    columnForSelected() {
      return this.getListByLabelId(this.selectedId);
    },
  },
  created() {
    this.filterItems();
  },
  methods: {
    ...mapActions(['createList', 'fetchLabels', 'highlightList', 'setAddColumnFormVisibility']),
    highlight(listId) {
      if (this.shouldUseGraphQL) {
        this.highlightList(listId);
      } else {
        const list = boardsStore.state.lists.find(({ id }) => id === listId);
        list.highlighted = true;
        setTimeout(() => {
          list.highlighted = false;
        }, 2000);
      }
    },
    addList() {
      if (!this.selectedLabel) {
        return;
      }

      this.setAddColumnFormVisibility(false);

      if (this.columnForSelected) {
        const listId = this.columnForSelected.id;
        this.highlight(listId);
        return;
      }

      if (this.shouldUseGraphQL) {
        this.createList({ labelId: this.selectedId });
      } else {
        const listObj = {
          labelId: getIdFromGraphQLId(this.selectedId),
          title: this.selectedLabel.title,
          position: boardsStore.state.lists.length - 2,
          list_type: ListType.label,
          label: this.selectedLabel,
        };

        boardsStore.new(listObj);
      }
    },

    filterItems(searchTerm) {
      this.fetchLabels(searchTerm);
    },

    showScopedLabels(label) {
      return this.scopedLabelsAvailable && isScopedLabel(label);
    },
  },
};
</script>

<template>
  <board-add-new-column-form
    :loading="labelsLoading"
    :form-description="__('A label list displays issues with the selected label.')"
    :search-label="__('Select label')"
    :search-placeholder="__('Search labels')"
    :selected-id="selectedId"
    @filter-items="filterItems"
    @add-list="addList"
  >
    <template slot="selected">
      <gl-label
        v-if="selectedLabel"
        v-gl-tooltip
        :title="selectedLabel.title"
        :description="selectedLabel.description"
        :background-color="selectedLabel.color"
        :scoped="showScopedLabels(selectedLabel)"
      />
    </template>

    <template slot="items">
      <gl-form-radio-group
        v-if="labels.length > 0"
        v-model="selectedId"
        class="gl-overflow-y-auto gl-px-5 gl-pt-3"
      >
        <label
          v-for="label in labels"
          :key="label.id"
          class="gl-display-flex gl-flex-align-items-center gl-mb-5 gl-font-weight-normal"
        >
          <gl-form-radio :value="label.id" class="gl-mb-0" />
          <span
            class="dropdown-label-box gl-top-0"
            :style="{
              backgroundColor: label.color,
            }"
          ></span>
          <span>{{ label.title }}</span>
        </label>
      </gl-form-radio-group>
    </template>
  </board-add-new-column-form>
</template>