summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/file_row_extra.vue
blob: fb0d00dc6a1e77ce5eb2d38163baf8a4fc11f9e4 (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
<script>
import { mapGetters } from 'vuex';
import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { n__ } from '~/locale';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
import NewDropdown from './new_dropdown/index.vue';
import MrFileIcon from './mr_file_icon.vue';

export default {
  name: 'FileRowExtra',
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  components: {
    GlIcon,
    NewDropdown,
    ChangedFileIcon,
    MrFileIcon,
  },
  props: {
    file: {
      type: Object,
      required: true,
    },
    dropdownOpen: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    ...mapGetters([
      'getChangesInFolder',
      'getUnstagedFilesCountForPath',
      'getStagedFilesCountForPath',
    ]),
    isTree() {
      return this.file.type === 'tree';
    },
    folderUnstagedCount() {
      return this.getUnstagedFilesCountForPath(this.file.path);
    },
    folderStagedCount() {
      return this.getStagedFilesCountForPath(this.file.path);
    },
    changesCount() {
      return this.getChangesInFolder(this.file.path);
    },
    folderChangesTooltip() {
      if (this.changesCount === 0) return undefined;

      return n__('%d changed file', '%d changed files', this.changesCount);
    },
    showTreeChangesCount() {
      return this.isTree && this.changesCount > 0 && !this.file.opened;
    },
    isModified() {
      return this.file.changed || this.file.tempFile || this.file.staged || this.file.prevPath;
    },
    showChangedFileIcon() {
      return !this.isTree && this.isModified;
    },
  },
};
</script>

<template>
  <div class="float-right ide-file-icon-holder">
    <mr-file-icon v-if="file.mrChange" />
    <span v-if="showTreeChangesCount" class="ide-tree-changes">
      {{ changesCount }}
      <gl-icon
        v-gl-tooltip.left.viewport
        :title="folderChangesTooltip"
        :size="12"
        data-container="body"
        data-placement="right"
        name="file-modified"
        class="gl-ml-2 ide-file-modified"
      />
    </span>
    <changed-file-icon
      v-else-if="showChangedFileIcon"
      :file="file"
      :show-tooltip="true"
      :show-staged-icon="false"
    />
    <new-dropdown
      :type="file.type"
      :path="file.path"
      :is-open="dropdownOpen"
      class="gl-ml-3"
      v-on="$listeners"
    />
  </div>
</template>