2019-09-04 21:01:54 +05:30
|
|
|
<script>
|
2020-11-24 15:15:51 +05:30
|
|
|
/* eslint-disable vue/no-v-html */
|
2020-04-22 19:07:51 +05:30
|
|
|
import {
|
|
|
|
GlBadge,
|
|
|
|
GlLink,
|
2020-11-24 15:15:51 +05:30
|
|
|
GlDeprecatedSkeletonLoading as GlSkeletonLoading,
|
2020-04-22 19:07:51 +05:30
|
|
|
GlTooltipDirective,
|
|
|
|
GlLoadingIcon,
|
|
|
|
GlIcon,
|
2021-09-04 01:27:46 +05:30
|
|
|
GlHoverLoadDirective,
|
2020-04-22 19:07:51 +05:30
|
|
|
} from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { escapeRegExp } from 'lodash';
|
2021-09-04 01:27:46 +05:30
|
|
|
import filesQuery from 'shared_queries/repository/files.query.graphql';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { escapeFileUrl } from '~/lib/utils/url_utility';
|
2021-09-04 01:27:46 +05:30
|
|
|
import { TREE_PAGE_SIZE } from '~/repository/constants';
|
2020-04-22 19:07:51 +05:30
|
|
|
import FileIcon from '~/vue_shared/components/file_icon.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2019-09-04 21:01:54 +05:30
|
|
|
import getRefMixin from '../../mixins/get_ref';
|
2021-09-04 01:27:46 +05:30
|
|
|
import blobInfoQuery from '../../queries/blob_info.query.graphql';
|
2020-10-24 23:57:45 +05:30
|
|
|
import commitQuery from '../../queries/commit.query.graphql';
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlBadge,
|
2019-09-30 21:07:59 +05:30
|
|
|
GlLink,
|
|
|
|
GlSkeletonLoading,
|
2020-03-13 15:44:24 +05:30
|
|
|
GlLoadingIcon,
|
2020-04-22 19:07:51 +05:30
|
|
|
GlIcon,
|
2019-09-30 21:07:59 +05:30
|
|
|
TimeagoTooltip,
|
2020-04-22 19:07:51 +05:30
|
|
|
FileIcon,
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
2021-09-04 01:27:46 +05:30
|
|
|
GlHoverLoad: GlHoverLoadDirective,
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
commit: {
|
2020-10-24 23:57:45 +05:30
|
|
|
query: commitQuery,
|
2019-09-30 21:07:59 +05:30
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
fileName: this.name,
|
|
|
|
type: this.type,
|
|
|
|
path: this.currentPath,
|
|
|
|
projectPath: this.projectPath,
|
2021-09-04 01:27:46 +05:30
|
|
|
maxOffset: this.totalEntries,
|
2019-09-30 21:07:59 +05:30
|
|
|
};
|
|
|
|
},
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
mixins: [getRefMixin, glFeatureFlagMixin()],
|
2019-09-04 21:01:54 +05:30
|
|
|
props: {
|
2021-09-04 01:27:46 +05:30
|
|
|
totalEntries: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
id: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
sha: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
currentPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
path: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2020-07-28 23:09:34 +05:30
|
|
|
mode: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
type: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
url: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
lfsOid: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
submoduleTreeUrl: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
2020-03-13 15:44:24 +05:30
|
|
|
loadingPath: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
commit: null,
|
|
|
|
};
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
computed: {
|
2021-04-29 21:17:54 +05:30
|
|
|
refactorBlobViewerEnabled() {
|
|
|
|
return this.glFeatures.refactorBlobViewer;
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
routerLinkTo() {
|
2021-04-29 21:17:54 +05:30
|
|
|
const blobRouteConfig = { path: `/-/blob/${this.escapedRef}/${escapeFileUrl(this.path)}` };
|
|
|
|
const treeRouteConfig = { path: `/-/tree/${this.escapedRef}/${escapeFileUrl(this.path)}` };
|
|
|
|
|
|
|
|
if (this.refactorBlobViewerEnabled && this.isBlob) {
|
|
|
|
return blobRouteConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.isFolder ? treeRouteConfig : null;
|
|
|
|
},
|
|
|
|
isBlob() {
|
|
|
|
return this.type === 'blob';
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
isFolder() {
|
|
|
|
return this.type === 'tree';
|
|
|
|
},
|
|
|
|
isSubmodule() {
|
|
|
|
return this.type === 'commit';
|
|
|
|
},
|
|
|
|
linkComponent() {
|
2021-04-29 21:17:54 +05:30
|
|
|
return this.isFolder || (this.refactorBlobViewerEnabled && this.isBlob) ? 'router-link' : 'a';
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
fullPath() {
|
2020-03-13 15:44:24 +05:30
|
|
|
return this.path.replace(new RegExp(`^${escapeRegExp(this.currentPath)}/`), '');
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
shortSha() {
|
2019-12-26 22:10:19 +05:30
|
|
|
return this.sha.slice(0, 8);
|
|
|
|
},
|
|
|
|
hasLockLabel() {
|
|
|
|
return this.commit && this.commit.lockLabel;
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
methods: {
|
|
|
|
handlePreload() {
|
|
|
|
return this.isFolder ? this.loadFolder() : this.loadBlob();
|
|
|
|
},
|
|
|
|
loadFolder() {
|
|
|
|
this.apolloQuery(filesQuery, {
|
|
|
|
projectPath: this.projectPath,
|
|
|
|
ref: this.ref,
|
|
|
|
path: this.path,
|
|
|
|
nextPageCursor: '',
|
|
|
|
pageSize: TREE_PAGE_SIZE,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
loadBlob() {
|
|
|
|
if (!this.refactorBlobViewerEnabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.apolloQuery(blobInfoQuery, {
|
|
|
|
projectPath: this.projectPath,
|
|
|
|
filePath: this.path,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
apolloQuery(query, variables) {
|
|
|
|
this.$apollo.query({ query, variables });
|
|
|
|
},
|
|
|
|
},
|
2019-09-04 21:01:54 +05:30
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2020-04-22 19:07:51 +05:30
|
|
|
<tr class="tree-item">
|
|
|
|
<td class="tree-item-file-name cursor-default position-relative">
|
2020-03-13 15:44:24 +05:30
|
|
|
<component
|
|
|
|
:is="linkComponent"
|
|
|
|
ref="link"
|
2021-09-04 01:27:46 +05:30
|
|
|
v-gl-hover-load="handlePreload"
|
2020-03-13 15:44:24 +05:30
|
|
|
:to="routerLinkTo"
|
|
|
|
:href="url"
|
2020-04-22 19:07:51 +05:30
|
|
|
:class="{
|
|
|
|
'is-submodule': isSubmodule,
|
|
|
|
}"
|
|
|
|
class="tree-item-link str-truncated"
|
2020-03-13 15:44:24 +05:30
|
|
|
data-qa-selector="file_name_link"
|
|
|
|
>
|
2020-04-22 19:07:51 +05:30
|
|
|
<file-icon
|
|
|
|
:file-name="fullPath"
|
2020-07-28 23:09:34 +05:30
|
|
|
:file-mode="mode"
|
2020-04-22 19:07:51 +05:30
|
|
|
:folder="isFolder"
|
|
|
|
:submodule="isSubmodule"
|
|
|
|
:loading="path === loadingPath"
|
|
|
|
css-classes="position-relative file-icon"
|
|
|
|
class="mr-1 position-relative text-secondary"
|
|
|
|
/><span class="position-relative">{{ fullPath }}</span>
|
2019-09-04 21:01:54 +05:30
|
|
|
</component>
|
2020-06-23 00:09:42 +05:30
|
|
|
<!-- eslint-disable @gitlab/vue-require-i18n-strings -->
|
|
|
|
<gl-badge v-if="lfsOid" variant="muted" size="sm" class="ml-1" data-qa-selector="label-lfs"
|
|
|
|
>LFS</gl-badge
|
|
|
|
>
|
|
|
|
<!-- eslint-enable @gitlab/vue-require-i18n-strings -->
|
2019-09-04 21:01:54 +05:30
|
|
|
<template v-if="isSubmodule">
|
2019-09-30 21:07:59 +05:30
|
|
|
@ <gl-link :href="submoduleTreeUrl" class="commit-sha">{{ shortSha }}</gl-link>
|
2019-09-04 21:01:54 +05:30
|
|
|
</template>
|
2020-04-22 19:07:51 +05:30
|
|
|
<gl-icon
|
2019-12-26 22:10:19 +05:30
|
|
|
v-if="hasLockLabel"
|
|
|
|
v-gl-tooltip
|
|
|
|
:title="commit.lockLabel"
|
|
|
|
name="lock"
|
|
|
|
:size="12"
|
2020-04-22 19:07:51 +05:30
|
|
|
class="ml-1"
|
2019-12-26 22:10:19 +05:30
|
|
|
/>
|
2019-09-04 21:01:54 +05:30
|
|
|
</td>
|
2020-04-22 19:07:51 +05:30
|
|
|
<td class="d-none d-sm-table-cell tree-commit cursor-default">
|
2019-12-26 22:10:19 +05:30
|
|
|
<gl-link
|
|
|
|
v-if="commit"
|
|
|
|
:href="commit.commitPath"
|
|
|
|
:title="commit.message"
|
|
|
|
class="str-truncated-100 tree-commit-link"
|
2020-05-24 23:13:21 +05:30
|
|
|
v-html="commit.titleHtml"
|
|
|
|
/>
|
2019-09-30 21:07:59 +05:30
|
|
|
<gl-skeleton-loading v-else :lines="1" class="h-auto" />
|
|
|
|
</td>
|
2020-04-22 19:07:51 +05:30
|
|
|
<td class="tree-time-ago text-right cursor-default">
|
2019-12-26 22:10:19 +05:30
|
|
|
<timeago-tooltip v-if="commit" :time="commit.committedDate" />
|
2019-09-30 21:07:59 +05:30
|
|
|
<gl-skeleton-loading v-else :lines="1" class="ml-auto h-auto w-50" />
|
|
|
|
</td>
|
2019-09-04 21:01:54 +05:30
|
|
|
</tr>
|
|
|
|
</template>
|