Commit 3f4aaea2 authored by Phil Hughes's avatar Phil Hughes

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
parent 100c68ee
...@@ -8,7 +8,7 @@ export default { ...@@ -8,7 +8,7 @@ export default {
}); });
}, },
getRawFileData(file) { getRawFileData(file) {
if (file.tempFile) { if (file.tempFile && !file.prevPath) {
return Promise.resolve(file.content); return Promise.resolve(file.content);
} }
......
...@@ -186,8 +186,14 @@ export const openNewEntryModal = ({ commit }, { type, path = '' }) => { ...@@ -186,8 +186,14 @@ export const openNewEntryModal = ({ commit }, { type, path = '' }) => {
}; };
export const deleteEntry = ({ commit, dispatch, state }, path) => { export const deleteEntry = ({ commit, dispatch, state }, path) => {
const entry = state.entries[path];
dispatch('burstUnusedSeal'); 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); commit(types.DELETE_ENTRY, path);
}; };
......
...@@ -62,14 +62,14 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => { ...@@ -62,14 +62,14 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => {
export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive = true }) => { export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive = true }) => {
const file = state.entries[path]; 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 }); commit(types.TOGGLE_LOADING, { entry: file });
const url = file.prevPath ? file.url.replace(file.path, file.prevPath) : file.url;
return service return service
.getFileData( .getFileData(`${gon.relative_url_root ? gon.relative_url_root : ''}${url.replace('/-/', '/')}`)
`${gon.relative_url_root ? gon.relative_url_root : ''}${file.url.replace('/-/', '/')}`,
)
.then(({ data, headers }) => { .then(({ data, headers }) => {
const normalizedHeaders = normalizeHeaders(headers); const normalizedHeaders = normalizeHeaders(headers);
setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE'])); setPageTitle(decodeURI(normalizedHeaders['PAGE-TITLE']));
...@@ -101,7 +101,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) = ...@@ -101,7 +101,7 @@ export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) =
service service
.getRawFileData(file) .getRawFileData(file)
.then(raw => { .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) { if (file.mrChange && file.mrChange.new_file === false) {
service service
.getBaseRawFileData(file, baseSha) .getBaseRawFileData(file, baseSha)
...@@ -176,9 +176,22 @@ export const setFileViewMode = ({ commit }, { file, viewMode }) => { ...@@ -176,9 +176,22 @@ export const setFileViewMode = ({ commit }, { file, viewMode }) => {
export const discardFileChanges = ({ dispatch, state, commit, getters }, path) => { export const discardFileChanges = ({ dispatch, state, commit, getters }, path) => {
const file = state.entries[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.DISCARD_FILE_CHANGES, path);
commit(types.REMOVE_FILE_FROM_CHANGED, path); commit(types.REMOVE_FILE_FROM_CHANGED, path);
if (file.prevPath) {
dispatch('discardFileChanges', file.prevPath);
}
if (file.tempFile && file.opened) { if (file.tempFile && file.opened) {
commit(types.TOGGLE_FILE_OPEN, path); commit(types.TOGGLE_FILE_OPEN, path);
} else if (getters.activeFile && file.path === getters.activeFile.path) { } else if (getters.activeFile && file.path === getters.activeFile.path) {
......
...@@ -89,3 +89,13 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } = ...@@ -89,3 +89,13 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
resolve(); 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);
}
};
...@@ -78,3 +78,5 @@ export const SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE'; ...@@ -78,3 +78,5 @@ export const SET_ERROR_MESSAGE = 'SET_ERROR_MESSAGE';
export const OPEN_NEW_ENTRY_MODAL = 'OPEN_NEW_ENTRY_MODAL'; export const OPEN_NEW_ENTRY_MODAL = 'OPEN_NEW_ENTRY_MODAL';
export const DELETE_ENTRY = 'DELETE_ENTRY'; export const DELETE_ENTRY = 'DELETE_ENTRY';
export const RENAME_ENTRY = 'RENAME_ENTRY'; export const RENAME_ENTRY = 'RENAME_ENTRY';
export const RESTORE_TREE = 'RESTORE_TREE';
...@@ -198,12 +198,18 @@ export default { ...@@ -198,12 +198,18 @@ export default {
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; : state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
entry.deleted = true; entry.deleted = true;
state.changedFiles = state.changedFiles.concat(entry);
parent.tree = parent.tree.filter(f => f.path !== entry.path); 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 }) { [types.RENAME_ENTRY](state, { path, name, entryPath = null }) {
const oldEntry = state.entries[entryPath || path]; 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 newPath = oldEntry.path.replace(nameRegex, name);
const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : ''; const parentPath = oldEntry.parentPath ? oldEntry.parentPath.replace(nameRegex, name) : '';
...@@ -220,15 +226,17 @@ export default { ...@@ -220,15 +226,17 @@ export default {
parentPath, parentPath,
}; };
oldEntry.moved = true; oldEntry.moved = true;
oldEntry.movedPath = newPath;
const parent = parentPath const parent = parentPath
? state.entries[parentPath] ? state.entries[parentPath]
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; : 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) { if (newEntry.type === 'blob') {
state.changedFiles = state.changedFiles.concat(state.entries[newPath]); state.changedFiles = state.changedFiles.concat(newEntry);
} }
}, },
...projectMutations, ...projectMutations,
......
...@@ -53,15 +53,19 @@ export default { ...@@ -53,15 +53,19 @@ export default {
}, },
[types.SET_FILE_RAW_DATA](state, { file, raw }) { [types.SET_FILE_RAW_DATA](state, { file, raw }) {
const openPendingFile = state.openFiles.find( 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], { Object.assign(state.entries[file.path], {
raw, raw,
}); });
if (openPendingFile) { if (!openPendingFile) return;
if (!openPendingFile.tempFile) {
openPendingFile.raw = raw; openPendingFile.raw = raw;
} else if (openPendingFile.tempFile) {
openPendingFile.content = raw;
} }
}, },
[types.SET_FILE_BASE_RAW_DATA](state, { file, baseRaw }) { [types.SET_FILE_BASE_RAW_DATA](state, { file, baseRaw }) {
...@@ -119,12 +123,14 @@ export default { ...@@ -119,12 +123,14 @@ export default {
[types.DISCARD_FILE_CHANGES](state, path) { [types.DISCARD_FILE_CHANGES](state, path) {
const stagedFile = state.stagedFiles.find(f => f.path === path); const stagedFile = state.stagedFiles.find(f => f.path === path);
const entry = state.entries[path]; const entry = state.entries[path];
const { deleted } = entry; const { deleted, prevPath } = entry;
Object.assign(state.entries[path], { Object.assign(state.entries[path], {
content: stagedFile ? stagedFile.content : state.entries[path].raw, content: stagedFile ? stagedFile.content : state.entries[path].raw,
changed: false, changed: false,
deleted: false, deleted: false,
moved: false,
movedPath: '',
}); });
if (deleted) { if (deleted) {
...@@ -133,6 +139,12 @@ export default { ...@@ -133,6 +139,12 @@ export default {
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`]; : state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
parent.tree = sortTree(parent.tree.concat(entry)); 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) { [types.ADD_FILE_TO_CHANGED](state, path) {
......
import * as types from '../mutation_types'; import * as types from '../mutation_types';
import { sortTree } from '../utils';
export default { export default {
[types.TOGGLE_TREE_OPEN](state, path) { [types.TOGGLE_TREE_OPEN](state, path) {
...@@ -36,4 +37,14 @@ export default { ...@@ -36,4 +37,14 @@ export default {
changedFiles: [], 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));
}
},
}; };
...@@ -48,6 +48,7 @@ export const dataStructure = () => ({ ...@@ -48,6 +48,7 @@ export const dataStructure = () => ({
mrChange: null, mrChange: null,
deleted: false, deleted: false,
prevPath: '', prevPath: '',
movedPath: '',
moved: false, moved: false,
}); });
......
...@@ -1377,6 +1377,7 @@ ...@@ -1377,6 +1377,7 @@
.ide-entry-dropdown-toggle { .ide-entry-dropdown-toggle {
padding: $gl-padding-4; padding: $gl-padding-4;
color: $gl-text-color;
background-color: $theme-gray-100; background-color: $theme-gray-100;
&:hover { &:hover {
...@@ -1389,6 +1390,10 @@ ...@@ -1389,6 +1390,10 @@
background-color: $blue-500; background-color: $blue-500;
outline: 0; outline: 0;
} }
svg {
fill: currentColor;
}
} }
.ide-new-btn .dropdown.show .ide-entry-dropdown-toggle { .ide-new-btn .dropdown.show .ide-entry-dropdown-toggle {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment