Commit a2e767d4 authored by Filipa Lacerda's avatar Filipa Lacerda

Merge branch 'ide-commit-reset-changes' into 'master'

Fixed IDE changed files not reseting after commit

Closes #5094

See merge request gitlab-org/gitlab-ee!4810
parents e7d9291f 89eecb55
...@@ -83,12 +83,12 @@ export default { ...@@ -83,12 +83,12 @@ export default {
this.editor.attachModel(this.model); this.editor.attachModel(this.model);
this.model.onChange((model) => { this.model.onChange((model) => {
const { file } = this.model; const { file } = model;
if (file.active) { if (file.active) {
this.changeFileContent({ this.changeFileContent({
file, file,
content: model.getValue(), content: model.getModel().getValue(),
}); });
} }
}); });
......
...@@ -61,14 +61,14 @@ export default class Model { ...@@ -61,14 +61,14 @@ export default class Model {
this.events.set( this.events.set(
this.path, this.path,
this.disposable.add( this.disposable.add(
this.model.onDidChangeContent(e => cb(this.model, e)), this.model.onDidChangeContent(e => cb(this, e)),
), ),
); );
} }
updateContent(content) { updateContent(content) {
this.getModel().setValue(content);
this.getOriginalModel().setValue(content); this.getOriginalModel().setValue(content);
this.getModel().setValue(content);
} }
dispose() { dispose() {
......
...@@ -89,12 +89,17 @@ export const updateFilesAfterCommit = ( ...@@ -89,12 +89,17 @@ export const updateFilesAfterCommit = (
lastCommit, lastCommit,
}, { root: true }); }, { root: true });
eventHub.$emit(`editor.update.model.content.${entry.path}`, entry.content);
commit(rootTypes.SET_FILE_RAW_DATA, { commit(rootTypes.SET_FILE_RAW_DATA, {
file: entry, file: entry,
raw: entry.content, raw: entry.content,
}, { root: true }); }, { root: true });
eventHub.$emit(`editor.update.model.content.${entry.path}`, entry.raw); commit(rootTypes.TOGGLE_FILE_CHANGED, {
file: entry,
changed: false,
}, { root: true });
}); });
commit(rootTypes.REMOVE_ALL_CHANGES_FILES, null, { root: true }); commit(rootTypes.REMOVE_ALL_CHANGES_FILES, null, { root: true });
......
...@@ -39,6 +39,7 @@ export const DISCARD_FILE_CHANGES = 'DISCARD_FILE_CHANGES'; ...@@ -39,6 +39,7 @@ export const DISCARD_FILE_CHANGES = 'DISCARD_FILE_CHANGES';
export const CREATE_TMP_FILE = 'CREATE_TMP_FILE'; export const CREATE_TMP_FILE = 'CREATE_TMP_FILE';
export const ADD_FILE_TO_CHANGED = 'ADD_FILE_TO_CHANGED'; export const ADD_FILE_TO_CHANGED = 'ADD_FILE_TO_CHANGED';
export const REMOVE_FILE_FROM_CHANGED = 'REMOVE_FILE_FROM_CHANGED'; export const REMOVE_FILE_FROM_CHANGED = 'REMOVE_FILE_FROM_CHANGED';
export const TOGGLE_FILE_CHANGED = 'TOGGLE_FILE_CHANGED';
// Viewer mutation types // Viewer mutation types
export const SET_PREVIEW_MODE = 'SET_PREVIEW_MODE'; export const SET_PREVIEW_MODE = 'SET_PREVIEW_MODE';
......
...@@ -79,4 +79,9 @@ export default { ...@@ -79,4 +79,9 @@ export default {
state.changedFiles.splice(indexOfChangedFile, 1); state.changedFiles.splice(indexOfChangedFile, 1);
}, },
[types.TOGGLE_FILE_CHANGED](state, { file, changed }) {
Object.assign(file, {
changed,
});
},
}; };
...@@ -64,7 +64,7 @@ describe('Multi-file editor library model', () => { ...@@ -64,7 +64,7 @@ describe('Multi-file editor library model', () => {
model.getModel().setValue('123'); model.getModel().setValue('123');
setTimeout(() => { setTimeout(() => {
expect(spy).toHaveBeenCalledWith(model.getModel(), jasmine.anything()); expect(spy).toHaveBeenCalledWith(model, jasmine.anything());
done(); done();
}); });
}); });
......
...@@ -178,6 +178,7 @@ describe('IDE commit module actions', () => { ...@@ -178,6 +178,7 @@ describe('IDE commit module actions', () => {
f = file('changedFile'); f = file('changedFile');
Object.assign(f, { Object.assign(f, {
active: true, active: true,
changed: true,
content: 'file content', content: 'file content',
}); });
...@@ -191,8 +192,11 @@ describe('IDE commit module actions', () => { ...@@ -191,8 +192,11 @@ describe('IDE commit module actions', () => {
}, },
}, },
}; };
store.state.changedFiles.push(f); store.state.changedFiles.push(f, {
store.state.openFiles.push(f); ...file('changedFile2'),
changed: true,
});
store.state.openFiles = store.state.changedFiles;
}); });
it('updates stores working reference', (done) => { it('updates stores working reference', (done) => {
...@@ -209,6 +213,20 @@ describe('IDE commit module actions', () => { ...@@ -209,6 +213,20 @@ describe('IDE commit module actions', () => {
.catch(done.fail); .catch(done.fail);
}); });
it('resets all files changed status', (done) => {
store.dispatch('commit/updateFilesAfterCommit', {
data,
branch,
})
.then(() => {
store.state.openFiles.forEach((entry) => {
expect(entry.changed).toBeFalsy();
});
})
.then(done)
.catch(done.fail);
});
it('removes all changed files', (done) => { it('removes all changed files', (done) => {
store.dispatch('commit/updateFilesAfterCommit', { store.dispatch('commit/updateFilesAfterCommit', {
data, data,
......
...@@ -161,4 +161,17 @@ describe('Multi-file store file mutations', () => { ...@@ -161,4 +161,17 @@ describe('Multi-file store file mutations', () => {
expect(localState.changedFiles.length).toBe(0); expect(localState.changedFiles.length).toBe(0);
}); });
}); });
describe('TOGGLE_FILE_CHANGED', () => {
it('updates file changed status', () => {
const f = file();
mutations.TOGGLE_FILE_CHANGED(localState, {
file: f,
changed: true,
});
expect(f.changed).toBeTruthy();
});
});
}); });
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