Commit e6a4548b authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'ph/221282/fixParentDirectoryLoading' into 'master'

Fixed parent directory still loading in repository browser

Closes #221282

See merge request gitlab-org/gitlab!42823
parents 14b71694 e73c646c
......@@ -75,6 +75,7 @@ export default {
},
methods: {
fetchFiles() {
const originalPath = this.path || '/';
this.isLoadingFiles = true;
return this.$apollo
......@@ -83,14 +84,14 @@ export default {
variables: {
projectPath: this.projectPath,
ref: this.ref,
path: this.path || '/',
path: originalPath,
nextPageCursor: this.nextPageCursor,
pageSize: this.pageSize,
},
})
.then(({ data }) => {
if (data.errors) throw data.errors;
if (!data?.project?.repository) return;
if (!data?.project?.repository || originalPath !== (this.path || '/')) return;
const pageInfo = this.hasNextPage(data.project.repository.tree);
......
......@@ -5,8 +5,8 @@ import commitsQuery from './queries/commits.query.graphql';
import projectPathQuery from './queries/project_path.query.graphql';
import refQuery from './queries/ref.query.graphql';
let fetchpromise;
let resolvers = [];
const fetchpromises = {};
const resolvers = {};
export function resolveCommit(commits, path, { resolve, entry }) {
const commit = commits.find(c => c.filePath === `${path}/${entry.name}` && c.type === entry.type);
......@@ -18,15 +18,19 @@ export function resolveCommit(commits, path, { resolve, entry }) {
export function fetchLogsTree(client, path, offset, resolver = null) {
if (resolver) {
resolvers.push(resolver);
if (!resolvers[path]) {
resolvers[path] = [resolver];
} else {
resolvers[path].push(resolver);
}
}
if (fetchpromise) return fetchpromise;
if (fetchpromises[path]) return fetchpromises[path];
const { projectPath } = client.readQuery({ query: projectPathQuery });
const { escapedRef } = client.readQuery({ query: refQuery });
fetchpromise = axios
fetchpromises[path] = axios
.get(
`${gon.relative_url_root}/${projectPath}/-/refs/${escapedRef}/logs_tree/${encodeURIComponent(
path.replace(/^\//, ''),
......@@ -46,16 +50,16 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
data,
});
resolvers.forEach(r => resolveCommit(data.commits, path, r));
resolvers[path].forEach(r => resolveCommit(data.commits, path, r));
fetchpromise = null;
delete fetchpromises[path];
if (headerLogsOffset) {
fetchLogsTree(client, path, headerLogsOffset);
} else {
resolvers = [];
delete resolvers[path];
}
});
return fetchpromise;
return fetchpromises[path];
}
......@@ -84,6 +84,14 @@ describe('fetchLogsTree', () => {
expect(axios.get.mock.calls.length).toEqual(1);
}));
it('calls axios for each path', () =>
Promise.all([
fetchLogsTree(client, '', '0', resolver),
fetchLogsTree(client, '/test', '0', resolver),
]).then(() => {
expect(axios.get.mock.calls.length).toEqual(2);
}));
it('calls entry resolver', () =>
fetchLogsTree(client, '', '0', resolver).then(() => {
expect(resolver.resolve).toHaveBeenCalledWith(
......
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