2019-09-04 21:01:54 +05:30
|
|
|
<script>
|
2020-04-22 19:07:51 +05:30
|
|
|
import {
|
|
|
|
GlBadge,
|
|
|
|
GlLink,
|
2022-07-23 23:45:48 +05:30
|
|
|
GlSkeletonLoader,
|
2020-04-22 19:07:51 +05:30
|
|
|
GlTooltipDirective,
|
|
|
|
GlLoadingIcon,
|
|
|
|
GlIcon,
|
2021-09-04 01:27:46 +05:30
|
|
|
GlHoverLoadDirective,
|
2021-11-18 22:05:49 +05:30
|
|
|
GlSafeHtmlDirective,
|
|
|
|
GlIntersectionObserver,
|
2020-04-22 19:07:51 +05:30
|
|
|
} from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { escapeRegExp } from 'lodash';
|
2021-11-11 11:23:49 +05:30
|
|
|
import paginatedTreeQuery from 'shared_queries/repository/paginated_tree.query.graphql';
|
2020-04-22 19:07:51 +05:30
|
|
|
import { escapeFileUrl } from '~/lib/utils/url_utility';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { TREE_PAGE_SIZE, ROW_APPEAR_DELAY } 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,
|
2022-07-23 23:45:48 +05:30
|
|
|
GlSkeletonLoader,
|
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,
|
2021-11-18 22:05:49 +05:30
|
|
|
GlIntersectionObserver,
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
2021-09-04 01:27:46 +05:30
|
|
|
GlHoverLoad: GlHoverLoadDirective,
|
2021-11-18 22:05:49 +05:30
|
|
|
SafeHtml: GlSafeHtmlDirective,
|
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
|
|
|
};
|
|
|
|
},
|
2021-11-18 22:05:49 +05:30
|
|
|
skip() {
|
|
|
|
return this.glFeatures.lazyLoadCommits;
|
|
|
|
},
|
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-11-18 22:05:49 +05:30
|
|
|
commitInfo: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
rowNumber: {
|
|
|
|
type: Number,
|
|
|
|
required: false,
|
|
|
|
default: null,
|
|
|
|
},
|
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,
|
2021-11-18 22:05:49 +05:30
|
|
|
hasRowAppeared: false,
|
2022-01-26 12:08:38 +05:30
|
|
|
delayedRowAppear: null,
|
2019-09-30 21:07:59 +05:30
|
|
|
};
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
computed: {
|
2021-11-18 22:05:49 +05:30
|
|
|
commitData() {
|
|
|
|
return this.glFeatures.lazyLoadCommits ? this.commitInfo : this.commit;
|
|
|
|
},
|
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() {
|
2021-11-18 22:05:49 +05:30
|
|
|
return this.commitData && this.commitData.lockLabel;
|
|
|
|
},
|
|
|
|
showSkeletonLoader() {
|
|
|
|
return !this.commitData && this.hasRowAppeared;
|
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() {
|
2021-12-11 22:18:48 +05:30
|
|
|
this.apolloQuery(paginatedTreeQuery, {
|
2021-09-04 01:27:46 +05:30
|
|
|
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,
|
2021-10-27 15:23:28 +05:30
|
|
|
ref: this.ref,
|
2022-04-04 11:22:00 +05:30
|
|
|
shouldFetchRawText: Boolean(this.glFeatures.highlightJs),
|
2021-09-04 01:27:46 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
apolloQuery(query, variables) {
|
|
|
|
this.$apollo.query({ query, variables });
|
|
|
|
},
|
2021-11-18 22:05:49 +05:30
|
|
|
rowAppeared() {
|
|
|
|
this.hasRowAppeared = true;
|
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
if (this.commitInfo) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-18 22:05:49 +05:30
|
|
|
if (this.glFeatures.lazyLoadCommits) {
|
2022-01-26 12:08:38 +05:30
|
|
|
this.delayedRowAppear = setTimeout(
|
|
|
|
() => this.$emit('row-appear', this.rowNumber),
|
|
|
|
ROW_APPEAR_DELAY,
|
|
|
|
);
|
2021-11-18 22:05:49 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
rowDisappeared() {
|
2022-01-26 12:08:38 +05:30
|
|
|
clearTimeout(this.delayedRowAppear);
|
2021-11-18 22:05:49 +05:30
|
|
|
this.hasRowAppeared = false;
|
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
},
|
2021-11-18 22:05:49 +05:30
|
|
|
safeHtmlConfig: { ADD_TAGS: ['gl-emoji'] },
|
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"
|
2021-09-30 23:02:18 +05:30
|
|
|
v-gl-tooltip:tooltip-container
|
|
|
|
:title="fullPath"
|
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
|
2021-11-18 22:05:49 +05:30
|
|
|
:title="commitData.lockLabel"
|
2019-12-26 22:10:19 +05:30
|
|
|
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
|
2021-11-18 22:05:49 +05:30
|
|
|
v-if="commitData"
|
|
|
|
v-safe-html:[$options.safeHtmlConfig]="commitData.titleHtml"
|
|
|
|
:href="commitData.commitPath"
|
|
|
|
:title="commitData.message"
|
2019-12-26 22:10:19 +05:30
|
|
|
class="str-truncated-100 tree-commit-link"
|
2020-05-24 23:13:21 +05:30
|
|
|
/>
|
2021-11-18 22:05:49 +05:30
|
|
|
<gl-intersection-observer @appear="rowAppeared" @disappear="rowDisappeared">
|
2022-07-23 23:45:48 +05:30
|
|
|
<gl-skeleton-loader v-if="showSkeletonLoader" :lines="1" />
|
2021-11-18 22:05:49 +05:30
|
|
|
</gl-intersection-observer>
|
2019-09-30 21:07:59 +05:30
|
|
|
</td>
|
2020-04-22 19:07:51 +05:30
|
|
|
<td class="tree-time-ago text-right cursor-default">
|
2021-11-18 22:05:49 +05:30
|
|
|
<timeago-tooltip v-if="commitData" :time="commitData.committedDate" />
|
2022-07-23 23:45:48 +05:30
|
|
|
<gl-skeleton-loader v-if="showSkeletonLoader" :lines="1" />
|
2019-09-30 21:07:59 +05:30
|
|
|
</td>
|
2019-09-04 21:01:54 +05:30
|
|
|
</tr>
|
|
|
|
</template>
|