diff options
author | Denys Mishunov <dmishunov@gitlab.com> | 2019-06-26 17:50:31 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-06-26 17:50:31 +0300 |
commit | f0fc53589755d00320b8c12ae739ba6c18872c3c (patch) | |
tree | 5fffcfa518cb76e34c3debbbcb19d275dcc9f4fc /app/assets/javascripts/ide/stores | |
parent | 4b7f053a49168491215e8ee20060c7283e138858 (diff) |
Re-name entries in one commit
Update window's URL after entry's re-name
Set proper hook for correct fileLanguage
Filtered out `moved` entries from the tree
Diffstat (limited to 'app/assets/javascripts/ide/stores')
-rw-r--r-- | app/assets/javascripts/ide/stores/actions.js | 12 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/file.js | 4 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations.js | 9 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/utils.js | 4 |
4 files changed, 17 insertions, 12 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js index 48aabaf9dcf..507dc363529 100644 --- a/app/assets/javascripts/ide/stores/actions.js +++ b/app/assets/javascripts/ide/stores/actions.js @@ -8,6 +8,7 @@ import * as types from './mutation_types'; import { decorateFiles } from '../lib/files'; import { stageKeys } from '../constants'; import service from '../services'; +import router from '../ide_router'; export const redirectToUrl = (self, url) => visitUrl(url); @@ -234,10 +235,15 @@ export const renameEntry = ( parentPath: newParentPath, }); }); - } + } else { + const newPath = parentPath ? `${parentPath}/${name}` : name; + const newEntry = state.entries[newPath]; + commit(types.TOGGLE_FILE_CHANGED, { file: newEntry, changed: true }); - if (!entryPath && !entry.tempFile) { - dispatch('deleteEntry', path); + if (entry.opened) { + router.push(`/project${newEntry.url}`); + commit(types.TOGGLE_FILE_OPEN, entry.path); + } } dispatch('triggerFilesChange'); diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index dc40a1fa6a2..7627b6e03af 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -73,7 +73,9 @@ export const getFileData = ( .getFileData(joinPaths(gon.relative_url_root || '', url.replace('/-/', '/'))) .then(({ data, headers }) => { const normalizedHeaders = normalizeHeaders(headers); - setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE'])); + let title = normalizedHeaders['PAGE-TITLE']; + title = file.prevPath ? title.replace(file.prevPath, file.path) : title; + setPageTitle(decodeURI(title)); if (data) commit(types.SET_FILE_DATA, { data, file }); if (openFile) commit(types.TOGGLE_FILE_OPEN, path); diff --git a/app/assets/javascripts/ide/stores/mutations.js b/app/assets/javascripts/ide/stores/mutations.js index ae42b87c9a7..ec4c2fdcde2 100644 --- a/app/assets/javascripts/ide/stores/mutations.js +++ b/app/assets/javascripts/ide/stores/mutations.js @@ -216,15 +216,16 @@ export default { Vue.set(state.entries, newPath, { ...oldEntry, id: newPath, - key: `${newPath}-${oldEntry.type}-${oldEntry.id}`, + key: `${newPath}-${oldEntry.type}-${oldEntry.path}`, path: newPath, name: entryPath ? oldEntry.name : name, tempFile: true, prevPath: oldEntry.tempFile ? null : oldEntry.path, url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath), tree: [], - parentPath, raw: '', + opened: false, + parentPath, }); oldEntry.moved = true; @@ -241,10 +242,6 @@ export default { state.changedFiles = state.changedFiles.concat(newEntry); } - if (state.entries[newPath].opened) { - state.openFiles.push(state.entries[newPath]); - } - if (oldEntry.tempFile) { const filterMethod = f => f.path !== oldEntry.path; diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js index 4e7a8765abe..fb132c1afc1 100644 --- a/app/assets/javascripts/ide/stores/utils.js +++ b/app/assets/javascripts/ide/stores/utils.js @@ -147,9 +147,9 @@ export const createCommitPayload = ({ commit_message: state.commitMessage || getters.preBuiltCommitMessage, actions: getCommitFiles(rootState.stagedFiles).map(f => ({ action: commitActionForFile(f), - file_path: f.path, + file_path: f.moved ? f.movedPath : f.path, previous_path: f.prevPath === '' ? undefined : f.prevPath, - content: f.content || undefined, + content: f.prevPath ? null : f.content || undefined, encoding: f.base64 ? 'base64' : 'text', last_commit_id: newBranch || f.deleted || f.prevPath ? undefined : f.lastCommitSha, })), |