1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import * as types from '../mutation_types';
import { sortTree, mergeTrees } from '../utils';
export default {
[types.TOGGLE_TREE_OPEN](state, path) {
Object.assign(state.entries[path], {
opened: !state.entries[path].opened,
});
},
[types.SET_TREE_OPEN](state, path) {
Object.assign(state.entries[path], {
opened: true,
});
},
[types.CREATE_TREE](state, { treePath }) {
Object.assign(state, {
trees: {
...state.trees,
[treePath]: {
tree: [],
loading: true,
},
},
});
},
[types.SET_DIRECTORY_DATA](state, { data, treePath }) {
const selectedTree = state.trees[treePath];
// If we opened files while loading the tree, we need to merge them
// Otherwise, simply overwrite the tree
const tree = !selectedTree.tree.length
? data
: selectedTree.loading && mergeTrees(selectedTree.tree, data);
Object.assign(selectedTree, { tree });
},
[types.REMOVE_ALL_CHANGES_FILES](state) {
Object.assign(state, {
changedFiles: [],
});
},
[types.RESTORE_TREE](state, path) {
const entry = state.entries[path];
const parent = entry.parentPath
? state.entries[entry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
if (!parent.tree.find(f => f.path === path)) {
parent.tree = sortTree(parent.tree.concat(entry));
}
},
};
|