Commit ab72cfc3 authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 483a66c0
...@@ -191,25 +191,34 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) = ...@@ -191,25 +191,34 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) =
dispatch('restoreTree', file.parentPath); dispatch('restoreTree', file.parentPath);
} }
commit(types.DISCARD_FILE_CHANGES, path); if (file.tempFile || file.prevPath) {
commit(types.REMOVE_FILE_FROM_CHANGED, path); dispatch('closeFile', file);
if (file.prevPath) {
dispatch('discardFileChanges', file.prevPath);
}
if (file.tempFile && file.opened) { if (file.tempFile) {
commit(types.TOGGLE_FILE_OPEN, path); dispatch('deleteEntry', file.path);
} else if (getters.activeFile && file.path === getters.activeFile.path) { } else {
dispatch('updateDelayViewerUpdated', true) dispatch('renameEntry', {
.then(() => { path: file.path,
router.push(`/project${file.url}`); name: file.prevName,
}) parentPath: file.prevParentPath,
.catch(e => {
throw e;
}); });
}
} else {
commit(types.DISCARD_FILE_CHANGES, path);
if (getters.activeFile && file.path === getters.activeFile.path) {
dispatch('updateDelayViewerUpdated', true)
.then(() => {
router.push(`/project${file.url}`);
})
.catch(e => {
throw e;
});
}
} }
commit(types.REMOVE_FILE_FROM_CHANGED, path);
eventHub.$emit(`editor.update.model.new.content.${file.key}`, file.content); eventHub.$emit(`editor.update.model.new.content.${file.key}`, file.content);
eventHub.$emit(`editor.update.model.dispose.unstaged-${file.key}`, file.content); eventHub.$emit(`editor.update.model.dispose.unstaged-${file.key}`, file.content);
}; };
......
---
title: Fix "Discard" for newly-created and renamed files
merge_request: 21905
author:
type: fixed
...@@ -581,11 +581,13 @@ describe('IDE store file actions', () => { ...@@ -581,11 +581,13 @@ describe('IDE store file actions', () => {
jest.spyOn(eventHub, '$on').mockImplementation(() => {}); jest.spyOn(eventHub, '$on').mockImplementation(() => {});
jest.spyOn(eventHub, '$emit').mockImplementation(() => {}); jest.spyOn(eventHub, '$emit').mockImplementation(() => {});
tmpFile = file(); tmpFile = file('tempFile');
tmpFile.content = 'testing'; tmpFile.content = 'testing';
store.state.changedFiles.push(tmpFile); store.state.changedFiles.push(tmpFile);
store.state.entries[tmpFile.path] = tmpFile; store.state.entries[tmpFile.path] = tmpFile;
jest.spyOn(store, 'dispatch');
}); });
it('resets file content', done => { it('resets file content', done => {
...@@ -610,33 +612,35 @@ describe('IDE store file actions', () => { ...@@ -610,33 +612,35 @@ describe('IDE store file actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('closes temp file', done => { it('closes temp file and deletes it', () => {
tmpFile.tempFile = true; tmpFile.tempFile = true;
tmpFile.opened = true; tmpFile.opened = true;
tmpFile.parentPath = 'parentFile';
store.state.entries.parentFile = file('parentFile');
store actions.discardFileChanges(store, tmpFile.path);
.dispatch('discardFileChanges', tmpFile.path)
.then(() => {
expect(tmpFile.opened).toBeFalsy();
done(); expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile);
}) expect(store.dispatch).toHaveBeenCalledWith('deleteEntry', tmpFile.path);
.catch(done.fail);
}); });
it('does not re-open a closed temp file', done => { it('renames the file to its original name and closes it if it was open', () => {
tmpFile.tempFile = true; Object.assign(tmpFile, {
prevPath: 'parentPath/old_name',
prevName: 'old_name',
prevParentPath: 'parentPath',
});
expect(tmpFile.opened).toBeFalsy(); store.state.entries.parentPath = file('parentPath');
store actions.discardFileChanges(store, tmpFile.path);
.dispatch('discardFileChanges', tmpFile.path)
.then(() => {
expect(tmpFile.opened).toBeFalsy();
done(); expect(store.dispatch).toHaveBeenCalledWith('closeFile', tmpFile);
}) expect(store.dispatch).toHaveBeenCalledWith('renameEntry', {
.catch(done.fail); path: 'tempFile',
name: 'old_name',
parentPath: 'parentPath',
});
}); });
it('pushes route for active file', done => { it('pushes route for active file', done => {
......
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