Commit 6ccbdee5 authored by Phil Hughes's avatar Phil Hughes

Fixed parent directory still loading in repository browser

Stops the directory from setting data on the Vue instance after
the user has navigated after from the direcetory.
This fixes a bug where the parents directory content would still load
and then become visible even after the user navigates away.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/221282
parent 90b901fb
...@@ -75,6 +75,7 @@ export default { ...@@ -75,6 +75,7 @@ export default {
}, },
methods: { methods: {
fetchFiles() { fetchFiles() {
const path = 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,
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 || path !== (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