All files / app/assets/javascripts/vue_shared/components changed_file_icon.vue

100% Statements 14/14
100% Branches 13/13
100% Functions 4/4
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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      18x                                                                             24x   24x     24x     27x 8x   19x 2x   17x 3x   14x 10x     4x     27x                                                                              
<script>
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
import getCommitIconMap from '~/ide/commit_icon';
import { __ } from '~/locale';
 
export default {
  components: {
    GlIcon,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    file: {
      type: Object,
      required: true,
    },
    showTooltip: {
      type: Boolean,
      required: false,
      default: false,
    },
    showStagedIcon: {
      type: Boolean,
      required: false,
      default: true,
    },
    size: {
      type: Number,
      required: false,
      default: 12,
    },
    isCentered: {
      type: Boolean,
      required: false,
      default: true,
    },
  },
  computed: {
    changedIcon() {
      // False positive i18n lint: https://gitlab.com/gitlab-org/frontend/eslint-plugin-i18n/issues/26
      // eslint-disable-next-line @gitlab/require-i18n-strings
      const suffix = this.file.staged && this.showStagedIcon ? '-solid' : '';
 
      return `${getCommitIconMap(this.file).icon}${suffix}`;
    },
    changedIconClass() {
      return `${this.changedIcon} float-left d-block`;
    },
    tooltipTitle() {
      if (!this.showTooltip) {
        return undefined;
      }
      if (this.file.deleted) {
        return __('Deleted');
      }
      if (this.file.tempFile) {
        return __('Added');
      }
      if (this.file.changed) {
        return __('Modified');
      }
 
      return undefined;
    },
    showIcon() {
      return (
        this.file.changed ||
        this.file.tempFile ||
        this.file.staged ||
        this.file.deleted ||
        this.file.prevPath
      );
    },
  },
};
</script>
 
<template>
  <span
    v-gl-tooltip.right
    :title="tooltipTitle"
    :class="{ 'ml-auto': isCentered }"
    class="file-changed-icon d-inline-block"
  >
    <gl-icon v-if="showIcon" :name="changedIcon" :size="size" :class="changedIconClass" />
  </span>
</template>
 
<style>
.file-addition,
.file-addition-solid {
  color: #1aaa55;
}
 
.file-modified,
.file-modified-solid {
  color: #fc9403;
}
 
.file-deletion,
.file-deletion-solid {
  color: #db3b21;
}
</style>