debian-mirror-gitlab/app/assets/javascripts/repository/components/table/index.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

191 lines
5.1 KiB
Vue
Raw Normal View History

2019-09-04 21:01:54 +05:30
<script>
2022-07-23 23:45:48 +05:30
import { GlSkeletonLoader, GlButton } from '@gitlab/ui';
2021-11-18 22:05:49 +05:30
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
2022-06-21 17:19:12 +05:30
import { sprintf, __ } from '~/locale';
2019-09-04 21:01:54 +05:30
import getRefMixin from '../../mixins/get_ref';
2020-10-24 23:57:45 +05:30
import projectPathQuery from '../../queries/project_path.query.graphql';
2019-09-04 21:01:54 +05:30
import TableHeader from './header.vue';
import ParentRow from './parent_row.vue';
2021-03-11 19:13:27 +05:30
import TableRow from './row.vue';
2019-09-04 21:01:54 +05:30
export default {
components: {
2022-07-23 23:45:48 +05:30
GlSkeletonLoader,
2019-09-04 21:01:54 +05:30
TableHeader,
TableRow,
ParentRow,
2020-11-24 15:15:51 +05:30
GlButton,
2019-09-04 21:01:54 +05:30
},
2021-11-18 22:05:49 +05:30
mixins: [getRefMixin, glFeatureFlagMixin()],
2019-09-04 21:01:54 +05:30
apollo: {
projectPath: {
2020-10-24 23:57:45 +05:30
query: projectPathQuery,
2019-09-04 21:01:54 +05:30
},
},
props: {
2021-11-18 22:05:49 +05:30
commits: {
type: Array,
required: false,
default: () => [],
},
2019-09-04 21:01:54 +05:30
path: {
type: String,
required: true,
},
2019-12-26 22:10:19 +05:30
entries: {
type: Object,
required: false,
default: () => ({}),
},
isLoading: {
type: Boolean,
required: true,
},
2020-03-13 15:44:24 +05:30
loadingPath: {
type: String,
required: false,
default: '',
},
2020-11-24 15:15:51 +05:30
hasMore: {
type: Boolean,
required: true,
},
2019-09-04 21:01:54 +05:30
},
data() {
return {
projectPath: '',
2021-11-18 22:05:49 +05:30
rowNumbers: {},
2019-09-04 21:01:54 +05:30
};
},
computed: {
2021-09-04 01:27:46 +05:30
totalEntries() {
return Object.values(this.entries).flat().length;
},
2019-09-04 21:01:54 +05:30
tableCaption() {
2019-12-26 22:10:19 +05:30
if (this.isLoading) {
return sprintf(
__(
'Loading files, directories, and submodules in the path %{path} for commit reference %{ref}',
),
{ path: this.path, ref: this.ref },
);
}
2019-09-04 21:01:54 +05:30
return sprintf(
__('Files, directories, and submodules in the path %{path} for commit reference %{ref}'),
{ path: this.path, ref: this.ref },
);
},
showParentRow() {
2021-09-30 23:02:18 +05:30
return ['', '/'].indexOf(this.path) === -1;
2019-09-04 21:01:54 +05:30
},
},
2021-11-18 22:05:49 +05:30
watch: {
$route: function routeChange() {
this.$options.totalRowsLoaded = -1;
},
},
totalRowsLoaded: -1,
2020-11-24 15:15:51 +05:30
methods: {
showMore() {
this.$emit('showMore');
},
2021-11-18 22:05:49 +05:30
generateRowNumber(path, id, index) {
const key = `${path}-${id}-${index}`;
if (!this.glFeatures.lazyLoadCommits) {
return 0;
}
if (!this.rowNumbers[key] && this.rowNumbers[key] !== 0) {
this.$options.totalRowsLoaded += 1;
this.rowNumbers[key] = this.$options.totalRowsLoaded;
}
return this.rowNumbers[key];
},
getCommit(fileName, type) {
if (!this.glFeatures.lazyLoadCommits) {
return {};
}
return this.commits.find(
(commitEntry) => commitEntry.fileName === fileName && commitEntry.type === type,
);
},
2020-11-24 15:15:51 +05:30
},
2019-09-04 21:01:54 +05:30
};
</script>
<template>
<div class="tree-content-holder">
<div class="table-holder bordered-box">
2020-03-13 15:44:24 +05:30
<table
:aria-label="tableCaption"
class="table tree-table"
2021-11-18 22:05:49 +05:30
:class="{ 'gl-table-layout-fixed': !showParentRow }"
2020-03-13 15:44:24 +05:30
aria-live="polite"
data-qa-selector="file_tree_table"
>
2019-09-04 21:01:54 +05:30
<table-header v-once />
<tbody>
2020-03-13 15:44:24 +05:30
<parent-row
2020-07-28 23:09:34 +05:30
v-if="showParentRow"
2020-05-05 14:28:15 +05:30
:commit-ref="escapedRef"
2020-03-13 15:44:24 +05:30
:path="path"
:loading-path="loadingPath"
/>
2019-09-04 21:01:54 +05:30
<template v-for="val in entries">
<table-row
2021-11-11 11:23:49 +05:30
v-for="(entry, index) in val"
2019-09-04 21:01:54 +05:30
:id="entry.id"
2021-11-11 11:23:49 +05:30
:key="`${entry.flatPath}-${entry.id}-${index}`"
2019-12-26 22:10:19 +05:30
:sha="entry.sha"
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"
2020-10-24 23:57:45 +05:30
:url="entry.webUrl || entry.webPath"
2020-07-28 23:09:34 +05:30
:mode="entry.mode"
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"
2020-03-13 15:44:24 +05:30
:loading-path="loadingPath"
2021-09-04 01:27:46 +05:30
:total-entries="totalEntries"
2021-11-18 22:05:49 +05:30
:row-number="generateRowNumber(entry.flatPath, entry.id, index)"
:commit-info="getCommit(entry.name, entry.type)"
v-on="$listeners"
2019-09-04 21:01:54 +05:30
/>
</template>
2019-12-26 22:10:19 +05:30
<template v-if="isLoading">
<tr v-for="i in 5" :key="i" aria-hidden="true">
2022-07-23 23:45:48 +05:30
<td><gl-skeleton-loader :lines="1" /></td>
2021-11-18 22:05:49 +05:30
<td class="gl-display-none gl-sm-display-block">
2022-07-23 23:45:48 +05:30
<gl-skeleton-loader :lines="1" />
</td>
<td>
<div class="gl-display-flex gl-lg-justify-content-end">
<gl-skeleton-loader :equal-width-lines="true" :lines="1" />
</div>
2021-11-18 22:05:49 +05:30
</td>
2019-12-26 22:10:19 +05:30
</tr>
</template>
2020-11-24 15:15:51 +05:30
<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>
2019-09-04 21:01:54 +05:30
</tbody>
</table>
</div>
</div>
</template>