diff options
Diffstat (limited to 'app/assets/javascripts/repo/stores/actions/tree.js')
-rw-r--r-- | app/assets/javascripts/repo/stores/actions/tree.js | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/app/assets/javascripts/repo/stores/actions/tree.js b/app/assets/javascripts/repo/stores/actions/tree.js index 8869bb8da2a..a0be8d4c556 100644 --- a/app/assets/javascripts/repo/stores/actions/tree.js +++ b/app/assets/javascripts/repo/stores/actions/tree.js @@ -2,7 +2,12 @@ import { normalizeHeaders } from '../../../lib/utils/common_utils'; import flash from '../../../flash'; import service from '../../services'; import * as types from '../mutation_types'; -import { pushState, setPageTitle } from '../utils'; +import { + pushState, + setPageTitle, + findEntry, + createTemp, +} from '../utils'; export const getTreeData = ( { commit, state }, @@ -68,3 +73,35 @@ export const clickedTreeRow = ({ commit, dispatch }, row) => { dispatch('getFileData', row); } }; + +export const createTempTree = ({ state, commit, dispatch }, name) => { + let tree = state; + const dirNames = name.replace(`${state.path}/`, '').split('/'); + + dirNames.forEach((dirName) => { + const foundEntry = findEntry(tree, 'tree', dirName); + + if (!foundEntry) { + const tmpEntry = createTemp({ + name: dirName, + path: tree.path, + type: 'tree', + level: tree.level !== undefined ? tree.level + 1 : 0, + }); + + commit(types.CREATE_TMP_TREE, { + parent: tree, + tmpEntry, + }); + + tree = tmpEntry; + } else { + tree = foundEntry; + } + }); + + dispatch('createTempFile', { + tree, + name: '.gitkeep', + }); +}; |