Commit 4d74ba74 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ide-fix-same-file-names' into 'master'

Fixed IDE file list when files have same name but different paths

Closes #5092

See merge request gitlab-org/gitlab-ee!4806
parents 120fac8d ba1d6d7c
......@@ -121,8 +121,8 @@ export const getTreeEntry = (store, treeId, path) => {
return fileList ? fileList.find(file => file.path === path) : null;
};
export const findEntry = (tree, type, name) => tree.find(
f => f.type === type && f.name === name,
export const findEntry = (tree, type, name, prop = 'name') => tree.find(
f => f.type === type && f[prop] === name,
);
export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path);
......@@ -163,7 +163,7 @@ export const createOrMergeEntry = ({ projectId,
level,
state }) => {
if (state.changedFiles.length) {
const foundChangedFile = findEntry(state.changedFiles, type, entry.name);
const foundChangedFile = findEntry(state.changedFiles, type, entry.path, 'path');
if (foundChangedFile) {
return foundChangedFile;
......@@ -171,7 +171,7 @@ export const createOrMergeEntry = ({ projectId,
}
if (state.openFiles.length) {
const foundOpenFile = findEntry(state.openFiles, type, entry.name);
const foundOpenFile = findEntry(state.openFiles, type, entry.path, 'path');
if (foundOpenFile) {
return foundOpenFile;
......
---
title: Fixed IDE file list when multiple files have same name but different paths
merge_request:
author:
type: fixed
......@@ -426,5 +426,63 @@ describe('Multi-file store tree actions', () => {
done();
}).catch(done.fail);
});
it('does not add changed file with same name but different path', (done) => {
const f = file('openedFile');
const tree = {
tree: [],
};
const data = {
trees: [{ name: 'tree' }],
submodules: [{ name: 'submodule' }],
blobs: [f],
};
store.state.changedFiles.push({
...f,
type: 'blob',
path: `src/${f.name}`,
changed: true,
});
store.dispatch('updateDirectoryData', {
data,
tree,
clearTree: false,
}).then(() => {
expect(tree.tree[2].changed).toBeFalsy();
done();
}).catch(done.fail);
});
it('does not add opened file with same name but different path', (done) => {
const f = file('openedFile');
const tree = {
tree: [],
};
const data = {
trees: [{ name: 'tree' }],
submodules: [{ name: 'submodule' }],
blobs: [f],
};
store.state.openFiles.push({
...f,
type: 'blob',
path: `src/${f.name}`,
opened: true,
});
store.dispatch('updateDirectoryData', {
data,
tree,
clearTree: false,
}).then(() => {
expect(tree.tree[2].opened).toBeFalsy();
done();
}).catch(done.fail);
});
});
});
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