Commit dd31c189 authored by Olena Horal-Koretska's avatar Olena Horal-Koretska

Merge branch '323209-preload-repo-blob' into 'master'

Preload blobs and directories in repo view

See merge request gitlab-org/gitlab!63066
parents 0fcd3a7a b37b804c
......@@ -7,13 +7,17 @@ import {
GlTooltipDirective,
GlLoadingIcon,
GlIcon,
GlHoverLoadDirective,
} from '@gitlab/ui';
import { escapeRegExp } from 'lodash';
import filesQuery from 'shared_queries/repository/files.query.graphql';
import { escapeFileUrl } from '~/lib/utils/url_utility';
import { TREE_PAGE_SIZE } from '~/repository/constants';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import TimeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import getRefMixin from '../../mixins/get_ref';
import blobInfoQuery from '../../queries/blob_info.query.graphql';
import commitQuery from '../../queries/commit.query.graphql';
export default {
......@@ -28,6 +32,7 @@ export default {
},
directives: {
GlTooltip: GlTooltipDirective,
GlHoverLoad: GlHoverLoadDirective,
},
apollo: {
commit: {
......@@ -139,6 +144,33 @@ export default {
return this.commit && this.commit.lockLabel;
},
},
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 });
},
},
};
</script>
......@@ -148,6 +180,7 @@ export default {
<component
:is="linkComponent"
ref="link"
v-gl-hover-load="handlePreload"
:to="routerLinkTo"
:href="url"
:class="{
......
query getBlobInfo($projectPath: ID!, $filePath: String!) {
project(fullPath: $projectPath) {
id
repository {
blobs(paths: [$filePath]) {
nodes {
......
import { GlBadge, GlLink, GlIcon } from '@gitlab/ui';
import { shallowMount, RouterLinkStub } from '@vue/test-utils';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import TableRow from '~/repository/components/table/row.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue';
import { FILE_SYMLINK_MODE } from '~/vue_shared/constants';
......@@ -19,6 +20,9 @@ function factory(propsData = {}) {
projectPath: 'gitlab-org/gitlab-ce',
url: `https://test.com`,
},
directives: {
GlHoverLoad: createMockDirective(),
},
provide: {
glFeatures: { refactorBlobViewer: true },
},
......@@ -34,6 +38,8 @@ function factory(propsData = {}) {
}
describe('Repository table row component', () => {
const findRouterLink = () => vm.find(RouterLinkStub);
afterEach(() => {
vm.destroy();
});
......@@ -81,6 +87,21 @@ describe('Repository table row component', () => {
});
});
it('renders a gl-hover-load directive', () => {
factory({
id: '1',
sha: '123',
path: 'test',
type: 'blob',
currentPath: '/',
});
const hoverLoadDirective = getBinding(findRouterLink().element, 'gl-hover-load');
expect(hoverLoadDirective).not.toBeUndefined();
expect(hoverLoadDirective.value).toBeInstanceOf(Function);
});
it.each`
type | component | componentName
${'tree'} | ${RouterLinkStub} | ${'RouterLink'}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment