summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/components/changed_file_icon.vue
blob: a4e06bbbe3c26e47bcce9d8e692c0026178f597f (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
<script>
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue';
import { pluralize } from '~/lib/utils/text_utility';
import { __, sprintf } from '~/locale';

export default {
  components: {
    Icon,
  },
  directives: {
    tooltip,
  },
  props: {
    file: {
      type: Object,
      required: true,
    },
    showTooltip: {
      type: Boolean,
      required: false,
      default: false,
    },
    showStagedIcon: {
      type: Boolean,
      required: false,
      default: false,
    },
    forceModifiedIcon: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    changedIcon() {
      const suffix = this.file.staged && !this.showStagedIcon ? '-solid' : '';
      return this.file.tempFile && !this.forceModifiedIcon
        ? `file-addition${suffix}`
        : `file-modified${suffix}`;
    },
    stagedIcon() {
      return `${this.changedIcon}-solid`;
    },
    changedIconClass() {
      return `multi-${this.changedIcon} float-left`;
    },
    tooltipTitle() {
      if (!this.showTooltip) return undefined;

      const type = this.file.tempFile ? 'addition' : 'modification';

      if (this.file.changed && !this.file.staged) {
        return sprintf(__('Unstaged %{type}'), {
          type,
        });
      } else if (!this.file.changed && this.file.staged) {
        return sprintf(__('Staged %{type}'), {
          type,
        });
      } else if (this.file.changed && this.file.staged) {
        return sprintf(__('Unstaged and staged %{type}'), {
          type: pluralize(type),
        });
      }

      return undefined;
    },
  },
};
</script>

<template>
  <span
    v-tooltip
    :title="tooltipTitle"
    data-container="body"
    data-placement="right"
    class="ide-file-changed-icon"
  >
    <icon
      v-if="file.changed || file.tempFile || file.staged"
      :name="changedIcon"
      :size="12"
      :css-classes="changedIconClass"
    />
  </span>
</template>