summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/diffs/components/diff_file_row.vue
blob: 2856e6ae8eb9284f9c945c2b4c96b781bdba990d (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
<script>
/**
 * This component is an iterative step towards refactoring and simplifying `vue_shared/components/file_row.vue`
 * https://gitlab.com/gitlab-org/gitlab/-/merge_requests/23720
 */
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import FileRow from '~/vue_shared/components/file_row.vue';
import ChangedFileIcon from '~/vue_shared/components/changed_file_icon.vue';
import FileRowStats from './file_row_stats.vue';

export default {
  name: 'DiffFileRow',
  components: {
    FileRow,
    FileRowStats,
    ChangedFileIcon,
  },
  mixins: [glFeatureFlagsMixin()],
  props: {
    file: {
      type: Object,
      required: true,
    },
    hideFileStats: {
      type: Boolean,
      required: true,
    },
    currentDiffFileId: {
      type: String,
      required: false,
      default: null,
    },
    viewedFiles: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  computed: {
    showFileRowStats() {
      return !this.hideFileStats && this.file.type === 'blob';
    },
    fileClasses() {
      if (!this.glFeatures.highlightCurrentDiffRow) {
        return '';
      }

      return this.file.type === 'blob' && !this.viewedFiles[this.file.fileHash]
        ? 'gl-font-weight-bold'
        : '';
    },
    isActive() {
      return this.currentDiffFileId === this.file.fileHash;
    },
  },
};
</script>

<template>
  <file-row
    :file="file"
    v-bind="$attrs"
    :class="{ 'is-active': isActive }"
    class="diff-file-row"
    :file-classes="fileClasses"
    v-on="$listeners"
  >
    <file-row-stats v-if="showFileRowStats" :file="file" class="mr-1" />
    <changed-file-icon :file="file" :size="16" :show-tooltip="true" />
  </file-row>
</template>