2019-09-04 21:01:54 +05:30
|
|
|
<script>
|
|
|
|
import { GlLoadingIcon } from '@gitlab/ui';
|
|
|
|
import createFlash from '~/flash';
|
|
|
|
import { sprintf, __ } from '../../../locale';
|
|
|
|
import getRefMixin from '../../mixins/get_ref';
|
2019-09-30 21:07:59 +05:30
|
|
|
import getFiles from '../../queries/getFiles.query.graphql';
|
|
|
|
import getProjectPath from '../../queries/getProjectPath.query.graphql';
|
2019-09-04 21:01:54 +05:30
|
|
|
import TableHeader from './header.vue';
|
|
|
|
import TableRow from './row.vue';
|
|
|
|
import ParentRow from './parent_row.vue';
|
|
|
|
|
|
|
|
const PAGE_SIZE = 100;
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlLoadingIcon,
|
|
|
|
TableHeader,
|
|
|
|
TableRow,
|
|
|
|
ParentRow,
|
|
|
|
},
|
|
|
|
mixins: [getRefMixin],
|
|
|
|
apollo: {
|
|
|
|
projectPath: {
|
|
|
|
query: getProjectPath,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
path: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
projectPath: '',
|
|
|
|
nextPageCursor: '',
|
|
|
|
entries: {
|
|
|
|
trees: [],
|
|
|
|
submodules: [],
|
|
|
|
blobs: [],
|
|
|
|
},
|
|
|
|
isLoadingFiles: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
tableCaption() {
|
|
|
|
return sprintf(
|
|
|
|
__('Files, directories, and submodules in the path %{path} for commit reference %{ref}'),
|
|
|
|
{ path: this.path, ref: this.ref },
|
|
|
|
);
|
|
|
|
},
|
|
|
|
showParentRow() {
|
|
|
|
return !this.isLoadingFiles && ['', '/'].indexOf(this.path) === -1;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
$route: function routeChange() {
|
|
|
|
this.entries.trees = [];
|
|
|
|
this.entries.submodules = [];
|
|
|
|
this.entries.blobs = [];
|
|
|
|
this.nextPageCursor = '';
|
|
|
|
this.fetchFiles();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
// We need to wait for `ref` and `projectPath` to be set
|
|
|
|
this.$nextTick(() => this.fetchFiles());
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
fetchFiles() {
|
|
|
|
this.isLoadingFiles = true;
|
|
|
|
|
|
|
|
return this.$apollo
|
|
|
|
.query({
|
|
|
|
query: getFiles,
|
|
|
|
variables: {
|
|
|
|
projectPath: this.projectPath,
|
|
|
|
ref: this.ref,
|
2019-09-30 21:07:59 +05:30
|
|
|
path: this.path || '/',
|
2019-09-04 21:01:54 +05:30
|
|
|
nextPageCursor: this.nextPageCursor,
|
|
|
|
pageSize: PAGE_SIZE,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
if (!data) return;
|
|
|
|
|
|
|
|
const pageInfo = this.hasNextPage(data.project.repository.tree);
|
|
|
|
|
|
|
|
this.isLoadingFiles = false;
|
|
|
|
this.entries = Object.keys(this.entries).reduce(
|
|
|
|
(acc, key) => ({
|
|
|
|
...acc,
|
|
|
|
[key]: this.normalizeData(key, data.project.repository.tree[key].edges),
|
|
|
|
}),
|
|
|
|
{},
|
|
|
|
);
|
|
|
|
|
|
|
|
if (pageInfo && pageInfo.hasNextPage) {
|
|
|
|
this.nextPageCursor = pageInfo.endCursor;
|
|
|
|
this.fetchFiles();
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => createFlash(__('An error occurred while fetching folder content.')));
|
|
|
|
},
|
|
|
|
normalizeData(key, data) {
|
|
|
|
return this.entries[key].concat(data.map(({ node }) => node));
|
|
|
|
},
|
|
|
|
hasNextPage(data) {
|
|
|
|
return []
|
|
|
|
.concat(data.trees.pageInfo, data.submodules.pageInfo, data.blobs.pageInfo)
|
|
|
|
.find(({ hasNextPage }) => hasNextPage);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="tree-content-holder">
|
|
|
|
<div class="table-holder bordered-box">
|
|
|
|
<table class="table tree-table qa-file-tree" aria-live="polite">
|
|
|
|
<caption class="sr-only">
|
|
|
|
{{
|
|
|
|
tableCaption
|
|
|
|
}}
|
|
|
|
</caption>
|
|
|
|
<table-header v-once />
|
|
|
|
<tbody>
|
|
|
|
<parent-row v-show="showParentRow" :commit-ref="ref" :path="path" />
|
|
|
|
<template v-for="val in entries">
|
|
|
|
<table-row
|
|
|
|
v-for="entry in val"
|
|
|
|
:id="entry.id"
|
|
|
|
:key="`${entry.flatPath}-${entry.id}`"
|
2019-09-30 21:07:59 +05:30
|
|
|
:project-path="projectPath"
|
2019-09-04 21:01:54 +05:30
|
|
|
:current-path="path"
|
2019-09-30 21:07:59 +05:30
|
|
|
:name="entry.name"
|
2019-09-04 21:01:54 +05:30
|
|
|
:path="entry.flatPath"
|
|
|
|
:type="entry.type"
|
|
|
|
:url="entry.webUrl"
|
2019-09-30 21:07:59 +05:30
|
|
|
:submodule-tree-url="entry.treeUrl"
|
2019-09-04 21:01:54 +05:30
|
|
|
:lfs-oid="entry.lfsOid"
|
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
<gl-loading-icon v-show="isLoadingFiles" class="my-3" size="md" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|