summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/notes/components/discussion_counter.vue
blob: c28ac94b3ed1aac99f1fb81454dd0f63b1ac52be (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
<script>
import { mapGetters, mapActions } from 'vuex';
import { GlTooltipDirective } from '@gitlab/ui';
import Icon from '~/vue_shared/components/icon.vue';
import discussionNavigation from '../mixins/discussion_navigation';

export default {
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  components: {
    Icon,
  },
  mixins: [discussionNavigation],
  computed: {
    ...mapGetters([
      'getUserData',
      'getNoteableData',
      'resolvableDiscussionsCount',
      'unresolvedDiscussionsCount',
      'discussions',
    ]),
    isLoggedIn() {
      return this.getUserData.id;
    },
    allResolved() {
      return this.unresolvedDiscussionsCount === 0;
    },
    resolveAllDiscussionsIssuePath() {
      return this.getNoteableData.create_issue_to_resolve_discussions_path;
    },
    resolvedDiscussionsCount() {
      return this.resolvableDiscussionsCount - this.unresolvedDiscussionsCount;
    },
    toggeableDiscussions() {
      return this.discussions.filter(discussion => !discussion.individual_note);
    },
    allExpanded() {
      return this.toggeableDiscussions.every(discussion => discussion.expanded);
    },
  },
  methods: {
    ...mapActions(['setExpandDiscussions']),
    handleExpandDiscussions() {
      this.setExpandDiscussions({
        discussionIds: this.toggeableDiscussions.map(discussion => discussion.id),
        expanded: !this.allExpanded,
      });
    },
  },
};
</script>

<template>
  <div
    v-if="resolvableDiscussionsCount > 0"
    ref="discussionCounter"
    class="line-resolve-all-container full-width-mobile"
  >
    <div class="full-width-mobile d-flex d-sm-flex">
      <div class="line-resolve-all">
        <span
          :class="{ 'is-active': allResolved }"
          class="line-resolve-btn is-disabled"
          type="button"
        >
          <icon :name="allResolved ? 'check-circle-filled' : 'check-circle'" />
        </span>
        <span class="line-resolve-text">
          {{ resolvedDiscussionsCount }}/{{ resolvableDiscussionsCount }}
          {{ n__('thread resolved', 'threads resolved', resolvableDiscussionsCount) }}
        </span>
      </div>
      <div
        v-if="resolveAllDiscussionsIssuePath && !allResolved"
        class="btn-group btn-group-sm"
        role="group"
      >
        <a
          v-gl-tooltip
          :href="resolveAllDiscussionsIssuePath"
          :title="s__('Resolve all threads in new issue')"
          class="new-issue-for-discussion btn btn-default discussion-create-issue-btn"
        >
          <icon name="issue-new" />
        </a>
      </div>
      <div v-if="isLoggedIn && !allResolved" class="btn-group btn-group-sm" role="group">
        <button
          v-gl-tooltip
          :title="__('Jump to next unresolved thread')"
          class="btn btn-default discussion-next-btn"
          data-track-event="click_button"
          data-track-label="mr_next_unresolved_thread"
          data-track-property="click_next_unresolved_thread_top"
          @click="jumpToNextDiscussion"
        >
          <icon name="comment-next" />
        </button>
      </div>
      <div v-if="isLoggedIn" class="btn-group btn-group-sm" role="group">
        <button
          v-gl-tooltip
          :title="__('Toggle all threads')"
          class="btn btn-default toggle-all-discussions-btn"
          @click="handleExpandDiscussions"
        >
          <icon :name="allExpanded ? 'angle-up' : 'angle-down'" />
        </button>
      </div>
    </div>
  </div>
</template>