index.vue 3.0 KB
Newer Older
1
<script>
2
import { GlSkeletonLoading } from '@gitlab/ui';
3 4
import { sprintf, __ } from '../../../locale';
import getRefMixin from '../../mixins/get_ref';
5
import projectPathQuery from '../../queries/project_path.query.graphql';
6
import TableHeader from './header.vue';
P
Phil Hughes 已提交
7
import TableRow from './row.vue';
8
import ParentRow from './parent_row.vue';
9 10 11

export default {
  components: {
12
    GlSkeletonLoading,
13
    TableHeader,
P
Phil Hughes 已提交
14
    TableRow,
15
    ParentRow,
16 17 18
  },
  mixins: [getRefMixin],
  apollo: {
19
    projectPath: {
20
      query: projectPathQuery,
21 22 23 24 25 26 27
    },
  },
  props: {
    path: {
      type: String,
      required: true,
    },
28 29 30 31 32 33 34 35 36
    entries: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    isLoading: {
      type: Boolean,
      required: true,
    },
37 38 39 40 41
    loadingPath: {
      type: String,
      required: false,
      default: '',
    },
42 43 44
  },
  data() {
    return {
45
      projectPath: '',
46 47 48 49
    };
  },
  computed: {
    tableCaption() {
50
      if (this.isLoading) {
51 52 53 54 55 56 57 58
        return sprintf(
          __(
            'Loading files, directories, and submodules in the path %{path} for commit reference %{ref}',
          ),
          { path: this.path, ref: this.ref },
        );
      }

59 60 61 62 63
      return sprintf(
        __('Files, directories, and submodules in the path %{path} for commit reference %{ref}'),
        { path: this.path, ref: this.ref },
      );
    },
64
    showParentRow() {
65
      return !this.isLoading && ['', '/'].indexOf(this.path) === -1;
66 67 68 69 70 71 72 73
    },
  },
};
</script>

<template>
  <div class="tree-content-holder">
    <div class="table-holder bordered-box">
74 75 76 77 78 79
      <table
        :aria-label="tableCaption"
        class="table tree-table"
        aria-live="polite"
        data-qa-selector="file_tree_table"
      >
80
        <table-header v-once />
P
Phil Hughes 已提交
81
        <tbody>
82
          <parent-row
83
            v-if="showParentRow"
84
            :commit-ref="escapedRef"
85 86 87
            :path="path"
            :loading-path="loadingPath"
          />
88 89 90 91 92
          <template v-for="val in entries">
            <table-row
              v-for="entry in val"
              :id="entry.id"
              :key="`${entry.flatPath}-${entry.id}`"
93
              :sha="entry.sha"
94
              :project-path="projectPath"
95
              :current-path="path"
96
              :name="entry.name"
97 98
              :path="entry.flatPath"
              :type="entry.type"
99
              :url="entry.webUrl || entry.webPath"
100
              :mode="entry.mode"
101
              :submodule-tree-url="entry.treeUrl"
102
              :lfs-oid="entry.lfsOid"
103
              :loading-path="loadingPath"
104 105
            />
          </template>
106
          <template v-if="isLoading">
107 108 109 110 111 112
            <tr v-for="i in 5" :key="i" aria-hidden="true">
              <td><gl-skeleton-loading :lines="1" class="h-auto" /></td>
              <td><gl-skeleton-loading :lines="1" class="h-auto" /></td>
              <td><gl-skeleton-loading :lines="1" class="ml-auto h-auto w-50" /></td>
            </tr>
          </template>
P
Phil Hughes 已提交
113
        </tbody>
114 115 116 117
      </table>
    </div>
  </div>
</template>