summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/compare_versions.vue
blob: 9bbf62c0eb67708e2c3f5625efafb5ae2509332d (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
<script>
import { mapActions, mapGetters, mapState } from 'vuex';
import Tooltip from '@gitlab-org/gitlab-ui/dist/directives/tooltip';
import { __ } from '~/locale';
import { getParameterValues, mergeUrlParams } from '~/lib/utils/url_utility';
import Icon from '~/vue_shared/components/icon.vue';
import CompareVersionsDropdown from './compare_versions_dropdown.vue';

export default {
  components: {
    CompareVersionsDropdown,
    Icon,
  },
  directives: {
    Tooltip,
  },
  props: {
    mergeRequestDiffs: {
      type: Array,
      required: true,
    },
    mergeRequestDiff: {
      type: Object,
      required: true,
    },
    startVersion: {
      type: Object,
      required: false,
      default: null,
    },
    targetBranch: {
      type: Object,
      required: false,
      default: null,
    },
  },
  computed: {
    ...mapState('diffs', ['commit', 'showTreeList']),
    ...mapGetters('diffs', ['isInlineView', 'isParallelView', 'areAllFilesCollapsed']),
    comparableDiffs() {
      return this.mergeRequestDiffs.slice(1);
    },
    isWhitespaceVisible() {
      return !getParameterValues('w')[0];
    },
    toggleWhitespaceText() {
      if (this.isWhitespaceVisible) {
        return __('Hide whitespace changes');
      }
      return __('Show whitespace changes');
    },
    toggleWhitespacePath() {
      if (this.isWhitespaceVisible) {
        return mergeUrlParams({ w: 1 }, window.location.href);
      }

      return mergeUrlParams({ w: 0 }, window.location.href);
    },
    showDropdowns() {
      return !this.commit && this.mergeRequestDiffs.length;
    },
  },
  methods: {
    ...mapActions('diffs', [
      'setInlineDiffViewType',
      'setParallelDiffViewType',
      'expandAllFiles',
      'toggleShowTreeList',
    ]),
  },
};
</script>

<template>
  <div class="mr-version-controls">
    <div
      class="mr-version-menus-container content-block"
    >
      <button
        v-tooltip.hover
        type="button"
        class="btn btn-default append-right-8 js-toggle-tree-list"
        :class="{
          active: showTreeList
        }"
        :title="__('Toggle file browser')"
        @click="toggleShowTreeList"
      >
        <icon
          name="hamburger"
        />
      </button>
      <div
        v-if="showDropdowns"
        class="d-flex align-items-center compare-versions-container"
      >
        Changes between
        <compare-versions-dropdown
          :other-versions="mergeRequestDiffs"
          :merge-request-version="mergeRequestDiff"
          :show-commit-count="true"
          class="mr-version-dropdown"
        />
        and
        <compare-versions-dropdown
          :other-versions="comparableDiffs"
          :start-version="startVersion"
          :target-branch="targetBranch"
          class="mr-version-compare-dropdown"
        />
      </div>
      <div
        class="inline-parallel-buttons d-none d-md-flex ml-auto"
      >
        <a
          v-if="areAllFilesCollapsed"
          class="btn btn-default"
          @click="expandAllFiles"
        >
          {{ __('Expand all') }}
        </a>
        <a
          :href="toggleWhitespacePath"
          class="btn btn-default"
        >
          {{ toggleWhitespaceText }}
        </a>
        <div class="btn-group prepend-left-8">
          <button
            id="inline-diff-btn"
            :class="{ active: isInlineView }"
            type="button"
            class="btn js-inline-diff-button"
            data-view-type="inline"
            @click="setInlineDiffViewType"
          >
            {{ __('Inline') }}
          </button>
          <button
            id="parallel-diff-btn"
            :class="{ active: isParallelView }"
            type="button"
            class="btn js-parallel-diff-button"
            data-view-type="parallel"
            @click="setParallelDiffViewType"
          >
            {{ __('Side-by-side') }}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>