index.vue 3.6 KB
Newer Older
1
<script>
2
import { GlDeprecatedSkeletonLoading as GlSkeletonLoading, GlButton } 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
    GlButton,
17 18 19
  },
  mixins: [getRefMixin],
  apollo: {
20
    projectPath: {
21
      query: projectPathQuery,
22 23 24 25 26 27 28
    },
  },
  props: {
    path: {
      type: String,
      required: true,
    },
29 30 31 32 33 34 35 36 37
    entries: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    isLoading: {
      type: Boolean,
      required: true,
    },
38 39 40 41 42
    loadingPath: {
      type: String,
      required: false,
      default: '',
    },
43 44 45 46
    hasMore: {
      type: Boolean,
      required: true,
    },
47 48 49
  },
  data() {
    return {
50
      projectPath: '',
51 52 53 54
    };
  },
  computed: {
    tableCaption() {
55
      if (this.isLoading) {
56 57 58 59 60 61 62 63
        return sprintf(
          __(
            'Loading files, directories, and submodules in the path %{path} for commit reference %{ref}',
          ),
          { path: this.path, ref: this.ref },
        );
      }

64 65 66 67 68
      return sprintf(
        __('Files, directories, and submodules in the path %{path} for commit reference %{ref}'),
        { path: this.path, ref: this.ref },
      );
    },
69
    showParentRow() {
70
      return !this.isLoading && ['', '/'].indexOf(this.path) === -1;
71 72
    },
  },
73 74 75 76 77
  methods: {
    showMore() {
      this.$emit('showMore');
    },
  },
78 79 80 81 82 83
};
</script>

<template>
  <div class="tree-content-holder">
    <div class="table-holder bordered-box">
84 85 86 87 88 89
      <table
        :aria-label="tableCaption"
        class="table tree-table"
        aria-live="polite"
        data-qa-selector="file_tree_table"
      >
90
        <table-header v-once />
P
Phil Hughes 已提交
91
        <tbody>
92
          <parent-row
93
            v-if="showParentRow"
94
            :commit-ref="escapedRef"
95 96 97
            :path="path"
            :loading-path="loadingPath"
          />
98 99 100 101 102
          <template v-for="val in entries">
            <table-row
              v-for="entry in val"
              :id="entry.id"
              :key="`${entry.flatPath}-${entry.id}`"
103
              :sha="entry.sha"
104
              :project-path="projectPath"
105
              :current-path="path"
106
              :name="entry.name"
107 108
              :path="entry.flatPath"
              :type="entry.type"
109
              :url="entry.webUrl || entry.webPath"
110
              :mode="entry.mode"
111
              :submodule-tree-url="entry.treeUrl"
112
              :lfs-oid="entry.lfsOid"
113
              :loading-path="loadingPath"
114 115
            />
          </template>
116
          <template v-if="isLoading">
117 118 119 120 121 122
            <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>
123 124 125 126 127 128 129 130 131 132 133 134 135 136
          <template v-if="hasMore">
            <tr>
              <td align="center" colspan="3" class="gl-p-0!">
                <gl-button
                  variant="link"
                  class="gl-display-flex gl-w-full gl-py-4!"
                  :loading="isLoading"
                  @click="showMore"
                >
                  {{ s__('ProjectFileTree|Show more') }}
                </gl-button>
              </td>
            </tr>
          </template>
P
Phil Hughes 已提交
137
        </tbody>
138 139 140 141
      </table>
    </div>
  </div>
</template>