summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-08-01 17:16:21 +0100
committerPhil Hughes <me@iamphill.com>2018-08-01 17:16:21 +0100
commit3f4aaea26c65391098e9e424c4550493a1c525cb (patch)
tree104086d742b61c069aa3f0e9bd65fbecdd6375cc /app/assets/javascripts/ide/stores
parent100c68eecd7ba6f950d1f23d339a2f1ec55675d8 (diff)
downloadgitlab-ce-3f4aaea26c65391098e9e424c4550493a1c525cb.tar.gz
correctly show renaming and deleting entries
for folders, it shows all the files in commit mode for files, nothing changes, the behaviour is the same
Diffstat (limited to 'app/assets/javascripts/ide/stores')
-rw-r--r--app/assets/javascripts/ide/stores/actions.js8
-rw-r--r--app/assets/javascripts/ide/stores/actions/file.js23
-rw-r--r--app/assets/javascripts/ide/stores/actions/tree.js10
-rw-r--r--app/assets/javascripts/ide/stores/mutation_types.js2
-rw-r--r--app/assets/javascripts/ide/stores/mutations.js18
-rw-r--r--app/assets/javascripts/ide/stores/mutations/file.js18
-rw-r--r--app/assets/javascripts/ide/stores/mutations/tree.js11
-rw-r--r--app/assets/javascripts/ide/stores/utils.js1
8 files changed, 77 insertions, 14 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js
index 6f70f297214..523f6ef03f4 100644
--- a/app/assets/javascripts/ide/stores/actions.js
+++ b/app/assets/javascripts/ide/stores/actions.js
@@ -186,8 +186,14 @@ export const openNewEntryModal = ({ commit }, { type, path = '' }) => {
};
export const deleteEntry = ({ commit, dispatch, state }, path) => {
+ const entry = state.entries[path];
dispatch('burstUnusedSeal');
- dispatch('closeFile', state.entries[path]);
+ dispatch('closeFile', entry);
+
+ if (entry.type === 'tree') {
+ entry.tree.forEach(f => dispatch('deleteEntry', f.path));
+ }
+
commit(types.DELETE_ENTRY, path);
};
diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js
index b343750f789..9e3f5da4676 100644
--- a/app/assets/javascripts/ide/stores/actions/file.js
+++ b/app/assets/javascripts/ide/stores/actions/file.js
@@ -62,14 +62,14 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => {
export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive = true }) => {
const file = state.entries[path];
- if (file.raw || file.tempFile) return Promise.resolve();
+ if (file.raw || (file.tempFile && !file.prevPath)) return Promise.resolve();
commit(types.TOGGLE_LOADING, { entry: file });
+ const url = file.prevPath ? file.url.replace(file.path, file.prevPath) : file.url;
+
return service
- .getFileData(
- `${gon.relative_url_root ? gon.relative_url_root : ''}${file.url.replace('/-/', '/')}`,
- )
+ .getFileData(`${gon.relative_url_root ? gon.relative_url_root : ''}${url.replace('/-/', '/')}`)
.then(({ data, headers }) => {
const normalizedHeaders = normalizeHeaders(headers);
setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE']));
@@ -101,7 +101,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) =
service
.getRawFileData(file)
.then(raw => {
- if (!file.tempFile) commit(types.SET_FILE_RAW_DATA, { file, raw });
+ if (!(file.tempFile && !file.prevPath)) commit(types.SET_FILE_RAW_DATA, { file, raw });
if (file.mrChange && file.mrChange.new_file === false) {
service
.getBaseRawFileData(file, baseSha)
@@ -176,9 +176,22 @@ export const setFileViewMode = ({ commit }, { file, viewMode }) => {
export const discardFileChanges = ({ dispatch, state, commit, getters }, path) => {
const file = state.entries[path];
+ if (file.deleted && file.parentPath) {
+ dispatch('restoreTree', file.parentPath);
+ }
+
+ if (file.movedPath) {
+ commit(types.DISCARD_FILE_CHANGES, file.movedPath);
+ commit(types.REMOVE_FILE_FROM_CHANGED, file.movedPath);
+ }
+
commit(types.DISCARD_FILE_CHANGES, path);
commit(types.REMOVE_FILE_FROM_CHANGED, path);
+ if (file.prevPath) {
+ dispatch('discardFileChanges', file.prevPath);
+ }
+
if (file.tempFile && file.opened) {
commit(types.TOGGLE_FILE_OPEN, path);
} else if (getters.activeFile && file.path === getters.activeFile.path) {
diff --git a/app/assets/javascripts/ide/stores/actions/tree.js b/app/assets/javascripts/ide/stores/actions/tree.js
index acb6ef5e6d4..9288bbe32f5 100644
--- a/app/assets/javascripts/ide/stores/actions/tree.js
+++ b/app/assets/javascripts/ide/stores/actions/tree.js
@@ -89,3 +89,13 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
resolve();
}
});
+
+export const restoreTree = ({ dispatch, commit, state }, path) => {
+ const entry = state.entries[path];
+
+ commit(types.RESTORE_TREE, path);
+
+ if (entry.parentPath) {
+ dispatch('restoreTree', entry.parentPath);
+ }
+};
diff --git a/app/assets/javascripts/ide/stores/mutation_types.js b/app/assets/javascripts/ide/stores/mutation_types.js
index ea3a6afb6e3..5a7991d2fa7 100644
--- a/app/assets/javascripts/ide/stores/mutation_types.js
+++ b/app/assets/javascripts/ide/stores/mutation_types.js
@@ -78,3 +78,5 @@ export const SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE';
export const OPEN_NEW_ENTRY_MODAL = 'OPEN_NEW_ENTRY_MODAL';
export const DELETE_ENTRY = 'DELETE_ENTRY';
export const RENAME_ENTRY = 'RENAME_ENTRY';
+
+export const RESTORE_TREE = 'RESTORE_TREE';
diff --git a/app/assets/javascripts/ide/stores/mutations.js b/app/assets/javascripts/ide/stores/mutations.js
index 68fb9d86932..c9e3cbf4592 100644
--- a/app/assets/javascripts/ide/stores/mutations.js
+++ b/app/assets/javascripts/ide/stores/mutations.js
@@ -198,12 +198,18 @@ export default {
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
entry.deleted = true;
- state.changedFiles = state.changedFiles.concat(entry);
parent.tree = parent.tree.filter(f => f.path !== entry.path);
+
+ if (entry.type === 'blob') {
+ state.changedFiles = state.changedFiles.concat(entry);
+ }
},
[types.RENAME_ENTRY](state, { path, name, entryPath = null }) {
const oldEntry = state.entries[entryPath || path];
- const nameRegex = new RegExp(`^${path}`);
+ const nameRegex =
+ !entryPath && oldEntry.type === 'blob'
+ ? new RegExp(`${oldEntry.name}$`)
+ : new RegExp(`^${path}`);
const newPath = oldEntry.path.replace(nameRegex, name);
const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : '';
@@ -220,15 +226,17 @@ export default {
parentPath,
};
oldEntry.moved = true;
+ oldEntry.movedPath = newPath;
const parent = parentPath
? state.entries[parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
+ const newEntry = state.entries[newPath];
- parent.tree = sortTree(parent.tree.concat(state.entries[newPath]));
+ parent.tree = sortTree(parent.tree.concat(newEntry));
- if (!entryPath) {
- state.changedFiles = state.changedFiles.concat(state.entries[newPath]);
+ if (newEntry.type === 'blob') {
+ state.changedFiles = state.changedFiles.concat(newEntry);
}
},
...projectMutations,
diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js
index 9a87d50d6d5..a249f7d2e12 100644
--- a/app/assets/javascripts/ide/stores/mutations/file.js
+++ b/app/assets/javascripts/ide/stores/mutations/file.js
@@ -53,15 +53,19 @@ export default {
},
[types.SET_FILE_RAW_DATA](state, { file, raw }) {
const openPendingFile = state.openFiles.find(
- f => f.path === file.path && f.pending && !f.tempFile,
+ f => f.path === file.path && f.pending && !(f.tempFile && !f.prevPath),
);
Object.assign(state.entries[file.path], {
raw,
});
- if (openPendingFile) {
+ if (!openPendingFile) return;
+
+ if (!openPendingFile.tempFile) {
openPendingFile.raw = raw;
+ } else if (openPendingFile.tempFile) {
+ openPendingFile.content = raw;
}
},
[types.SET_FILE_BASE_RAW_DATA](state, { file, baseRaw }) {
@@ -119,12 +123,14 @@ export default {
[types.DISCARD_FILE_CHANGES](state, path) {
const stagedFile = state.stagedFiles.find(f => f.path === path);
const entry = state.entries[path];
- const { deleted } = entry;
+ const { deleted, prevPath } = entry;
Object.assign(state.entries[path], {
content: stagedFile ? stagedFile.content : state.entries[path].raw,
changed: false,
deleted: false,
+ moved: false,
+ movedPath: '',
});
if (deleted) {
@@ -133,6 +139,12 @@ export default {
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
parent.tree = sortTree(parent.tree.concat(entry));
+ } else if (prevPath) {
+ const parent = entry.parentPath
+ ? state.entries[entry.parentPath]
+ : state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
+
+ parent.tree = parent.tree.filter(f => f.path !== path);
}
},
[types.ADD_FILE_TO_CHANGED](state, path) {
diff --git a/app/assets/javascripts/ide/stores/mutations/tree.js b/app/assets/javascripts/ide/stores/mutations/tree.js
index 2cf34af9274..eac7441ee54 100644
--- a/app/assets/javascripts/ide/stores/mutations/tree.js
+++ b/app/assets/javascripts/ide/stores/mutations/tree.js
@@ -1,4 +1,5 @@
import * as types from '../mutation_types';
+import { sortTree } from '../utils';
export default {
[types.TOGGLE_TREE_OPEN](state, path) {
@@ -36,4 +37,14 @@ export default {
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));
+ }
+ },
};
diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js
index d3662e32c6e..5dc3e2c202d 100644
--- a/app/assets/javascripts/ide/stores/utils.js
+++ b/app/assets/javascripts/ide/stores/utils.js
@@ -48,6 +48,7 @@ export const dataStructure = () => ({
mrChange: null,
deleted: false,
prevPath: '',
+ movedPath: '',
moved: false,
});