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