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 {
this.editor.attachModel(this.model);
this.model.onChange((model) => {
const { file } = this.model;
const { file } = model;
if (file.active) {
this.changeFileContent({
file,
content: model.getValue(),
content: model.getModel().getValue(),
});
}
});
......
......@@ -61,14 +61,14 @@ export default class Model {
this.events.set(
this.path,
this.disposable.add(
this.model.onDidChangeContent(e => cb(this.model, e)),
this.model.onDidChangeContent(e => cb(this, e)),
),
);
}
updateContent(content) {
this.getModel().setValue(content);
this.getOriginalModel().setValue(content);
this.getModel().setValue(content);
}
dispose() {
......
......@@ -89,12 +89,17 @@ export const updateFilesAfterCommit = (
lastCommit,
}, { root: true });
eventHub.$emit(`editor.update.model.content.${entry.path}`, entry.content);
commit(rootTypes.SET_FILE_RAW_DATA, {
file: entry,
raw: entry.content,
}, { 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 });
......
......@@ -39,6 +39,7 @@ export const DISCARD_FILE_CHANGES = 'DISCARD_FILE_CHANGES';
export const CREATE_TMP_FILE = 'CREATE_TMP_FILE';
export const ADD_FILE_TO_CHANGED = 'ADD_FILE_TO_CHANGED';
export const REMOVE_FILE_FROM_CHANGED = 'REMOVE_FILE_FROM_CHANGED';
export const TOGGLE_FILE_CHANGED = 'TOGGLE_FILE_CHANGED';
// Viewer mutation types
export const SET_PREVIEW_MODE = 'SET_PREVIEW_MODE';
......
......@@ -79,4 +79,9 @@ export default {
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', () => {
model.getModel().setValue('123');
setTimeout(() => {
expect(spy).toHaveBeenCalledWith(model.getModel(), jasmine.anything());
expect(spy).toHaveBeenCalledWith(model, jasmine.anything());
done();
});
});
......
......@@ -178,6 +178,7 @@ describe('IDE commit module actions', () => {
f = file('changedFile');
Object.assign(f, {
active: true,
changed: true,
content: 'file content',
});
......@@ -191,8 +192,11 @@ describe('IDE commit module actions', () => {
},
},
};
store.state.changedFiles.push(f);
store.state.openFiles.push(f);
store.state.changedFiles.push(f, {
...file('changedFile2'),
changed: true,
});
store.state.openFiles = store.state.changedFiles;
});
it('updates stores working reference', (done) => {
......@@ -209,6 +213,20 @@ describe('IDE commit module actions', () => {
.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) => {
store.dispatch('commit/updateFilesAfterCommit', {
data,
......
......@@ -161,4 +161,17 @@ describe('Multi-file store file mutations', () => {
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