debian-mirror-gitlab/app/assets/javascripts/ide/stores/mutations/tree.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import * as types from '../mutation_types';
2019-07-07 11:18:12 +05:30
import { sortTree, mergeTrees } from '../utils';
2018-05-09 12:01:36 +05:30
export default {
[types.TOGGLE_TREE_OPEN](state, path) {
Object.assign(state.entries[path], {
opened: !state.entries[path].opened,
});
},
2018-11-08 19:23:39 +05:30
[types.SET_TREE_OPEN](state, path) {
Object.assign(state.entries[path], {
opened: true,
});
},
2018-05-09 12:01:36 +05:30
[types.CREATE_TREE](state, { treePath }) {
Object.assign(state, {
2020-05-24 23:13:21 +05:30
trees: {
...state.trees,
2018-05-09 12:01:36 +05:30
[treePath]: {
tree: [],
loading: true,
},
2020-05-24 23:13:21 +05:30
},
2018-05-09 12:01:36 +05:30
});
},
[types.SET_DIRECTORY_DATA](state, { data, treePath }) {
2019-07-07 11:18:12 +05:30
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 });
2018-05-09 12:01:36 +05:30
},
[types.REMOVE_ALL_CHANGES_FILES](state) {
Object.assign(state, {
changedFiles: [],
});
},
2018-11-18 11:00:15 +05:30
[types.RESTORE_TREE](state, path) {
const entry = state.entries[path];
const parent = entry.parentPath
? state.entries[entry.parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
2021-03-08 18:12:59 +05:30
if (!parent.tree.find((f) => f.path === path)) {
2018-11-18 11:00:15 +05:30
parent.tree = sortTree(parent.tree.concat(entry));
}
},
2018-05-09 12:01:36 +05:30
};