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

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import * as types from '../mutation_types';
2019-05-30 16:15:17 +05:30
import { sortTree } 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, {
trees: Object.assign({}, state.trees, {
[treePath]: {
tree: [],
loading: true,
},
}),
});
},
[types.SET_DIRECTORY_DATA](state, { data, treePath }) {
2019-05-30 16:15:17 +05:30
Object.assign(state.trees[treePath], {
tree: data,
});
2018-05-09 12:01:36 +05:30
},
[types.SET_LAST_COMMIT_URL](state, { tree = state, url }) {
Object.assign(tree, {
lastCommitPath: url,
});
},
[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}`];
if (!parent.tree.find(f => f.path === path)) {
parent.tree = sortTree(parent.tree.concat(entry));
}
},
2018-05-09 12:01:36 +05:30
};