row.vue 2.08 KB
Newer Older
1
<script>
2
import { GlBadge } from '@gitlab/ui';
3
import { visitUrl } from '~/lib/utils/url_utility';
4 5 6 7
import { getIconName } from '../../utils/icon';
import getRefMixin from '../../mixins/get_ref';

export default {
8 9 10
  components: {
    GlBadge,
  },
11 12 13
  mixins: [getRefMixin],
  props: {
    id: {
14 15 16 17 18
      type: String,
      required: true,
    },
    currentPath: {
      type: String,
19 20 21 22 23 24 25 26 27 28
      required: true,
    },
    path: {
      type: String,
      required: true,
    },
    type: {
      type: String,
      required: true,
    },
29 30 31 32 33
    url: {
      type: String,
      required: false,
      default: null,
    },
34 35 36 37 38
    lfsOid: {
      type: String,
      required: false,
      default: null,
    },
39 40 41 42 43 44 45 46 47
  },
  computed: {
    routerLinkTo() {
      return this.isFolder ? { path: `/tree/${this.ref}/${this.path}` } : null;
    },
    iconName() {
      return `fa-${getIconName(this.type, this.path)}`;
    },
    isFolder() {
48
      return this.type === 'tree';
49 50 51 52 53 54 55
    },
    isSubmodule() {
      return this.type === 'commit';
    },
    linkComponent() {
      return this.isFolder ? 'router-link' : 'a';
    },
56 57 58 59 60 61
    fullPath() {
      return this.path.replace(new RegExp(`^${this.currentPath}/`), '');
    },
    shortSha() {
      return this.id.slice(0, 8);
    },
62 63 64 65 66
  },
  methods: {
    openRow() {
      if (this.isFolder) {
        this.$router.push(this.routerLinkTo);
67 68
      } else {
        visitUrl(this.url);
69 70 71 72 73 74 75 76 77 78
      }
    },
  },
};
</script>

<template>
  <tr v-once :class="`file_${id}`" class="tree-item" @click="openRow">
    <td class="tree-item-file-name">
      <i :aria-label="type" role="img" :class="iconName" class="fa fa-fw"></i>
79
      <component :is="linkComponent" :to="routerLinkTo" :href="url" class="str-truncated">
80 81
        {{ fullPath }}
      </component>
82 83 84
      <gl-badge v-if="lfsOid" variant="default" class="label-lfs ml-1">
        LFS
      </gl-badge>
85
      <template v-if="isSubmodule">
86
        @ <a href="#" class="commit-sha">{{ shortSha }}</a>
87 88 89 90 91 92
      </template>
    </td>
    <td class="d-none d-sm-table-cell tree-commit"></td>
    <td class="tree-time-ago text-right"></td>
  </tr>
</template>