Commit d0378125 authored by Phil Hughes's avatar Phil Hughes

update staged files to correctly use pending tab

parent c02d344c
...@@ -31,7 +31,10 @@ export default { ...@@ -31,7 +31,10 @@ export default {
methods: { methods: {
...mapActions(['discardFileChanges', 'updateViewer', 'openPendingTab']), ...mapActions(['discardFileChanges', 'updateViewer', 'openPendingTab']),
openFileInEditor() { openFileInEditor() {
return this.openPendingTab(this.file).then(changeViewer => { return this.openPendingTab({
file: this.file,
keyPrefix: this.file.staged ? 'staged' : 'unstaged',
}).then(changeViewer => {
if (changeViewer) { if (changeViewer) {
this.updateViewer('diff'); this.updateViewer('diff');
} }
......
...@@ -70,11 +70,7 @@ export default { ...@@ -70,11 +70,7 @@ export default {
baseSha: this.currentMergeRequest ? this.currentMergeRequest.baseCommitSha : '', baseSha: this.currentMergeRequest ? this.currentMergeRequest.baseCommitSha : '',
}) })
.then(() => { .then(() => {
const viewerPromise = this.delayViewerUpdated return this.updateViewer(this.file.pending ? 'diff' : 'editor');
? this.updateViewer(this.file.pending ? 'diff' : 'editor')
: Promise.resolve();
return viewerPromise;
}) })
.then(() => { .then(() => {
this.updateDelayViewerUpdated(false); this.updateDelayViewerUpdated(false);
......
...@@ -37,7 +37,7 @@ export default class Model { ...@@ -37,7 +37,7 @@ export default class Model {
this.dispose = this.dispose.bind(this); this.dispose = this.dispose.bind(this);
eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose); eventHub.$on(`editor.update.model.dispose.${this.file.key}`, this.dispose);
eventHub.$on(`editor.update.model.content.${this.file.path}`, this.updateContent); eventHub.$on(`editor.update.model.content.${this.file.key}`, this.updateContent);
} }
get url() { get url() {
...@@ -92,6 +92,6 @@ export default class Model { ...@@ -92,6 +92,6 @@ export default class Model {
this.events.clear(); this.events.clear();
eventHub.$off(`editor.update.model.dispose.${this.file.key}`, this.dispose); eventHub.$off(`editor.update.model.dispose.${this.file.key}`, this.dispose);
eventHub.$off(`editor.update.model.content.${this.file.path}`, this.updateContent); eventHub.$off(`editor.update.model.content.${this.file.key}`, this.updateContent);
} }
} }
...@@ -24,7 +24,10 @@ export const closeFile = ({ commit, state, dispatch }, file) => { ...@@ -24,7 +24,10 @@ export const closeFile = ({ commit, state, dispatch }, file) => {
if (nextFileToOpen.pending) { if (nextFileToOpen.pending) {
dispatch('updateViewer', 'diff'); dispatch('updateViewer', 'diff');
dispatch('openPendingTab', nextFileToOpen); dispatch('openPendingTab', {
file: nextFileToOpen,
keyPrefix: nextFileToOpen.staged ? 'staged' : 'unstaged',
});
} else { } else {
dispatch('updateDelayViewerUpdated', true); dispatch('updateDelayViewerUpdated', true);
router.push(`/project${nextFileToOpen.url}`); router.push(`/project${nextFileToOpen.url}`);
...@@ -159,26 +162,35 @@ export const discardFileChanges = ({ state, commit }, path) => { ...@@ -159,26 +162,35 @@ export const discardFileChanges = ({ state, commit }, path) => {
commit(types.TOGGLE_FILE_OPEN, path); commit(types.TOGGLE_FILE_OPEN, path);
} }
eventHub.$emit(`editor.update.model.content.${path}`, { eventHub.$emit(`editor.update.model.content.${file.key}`, {
content: file.raw, content: file.raw,
changed: false, changed: false,
}); });
}; };
export const stageChange = ({ commit }, path) => { export const stageChange = ({ commit, state }, path) => {
const stagedFile = state.stagedFiles.find(f => f.path === path);
commit(types.STAGE_CHANGE, path); commit(types.STAGE_CHANGE, path);
if (stagedFile) {
eventHub.$emit(`editor.update.model.content.staged-${stagedFile.key}`, {
content: stagedFile.content,
changed: false,
});
}
}; };
export const unstageChange = ({ commit }, path) => { export const unstageChange = ({ commit }, path) => {
commit(types.UNSTAGE_CHANGE, path); commit(types.UNSTAGE_CHANGE, path);
}; };
export const openPendingTab = ({ commit, getters, dispatch, state }, file) => { export const openPendingTab = ({ commit, getters, dispatch, state }, { file, keyPrefix }) => {
if (getters.activeFile && getters.activeFile.path === file.path && state.viewer === 'diff') { if (getters.activeFile && getters.activeFile.path === file.path && state.viewer === 'diff') {
return false; return false;
} }
commit(types.ADD_PENDING_TAB, { file }); commit(types.ADD_PENDING_TAB, { file, keyPrefix });
dispatch('scrollToTab'); dispatch('scrollToTab');
......
...@@ -37,9 +37,9 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => { ...@@ -37,9 +37,9 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => {
const commitMsg = sprintf( const commitMsg = sprintf(
__('Your changes have been committed. Commit %{commitId} %{commitStats}'), __('Your changes have been committed. Commit %{commitId} %{commitStats}'),
{ {
commitId: `<a href="${currentProject.web_url}/commit/${ commitId: `<a href="${currentProject.web_url}/commit/${data.short_id}" class="commit-sha">${
data.short_id data.short_id
}" class="commit-sha">${data.short_id}</a>`, }</a>`,
commitStats, commitStats,
}, },
false, false,
...@@ -54,9 +54,7 @@ export const checkCommitStatus = ({ rootState }) => ...@@ -54,9 +54,7 @@ export const checkCommitStatus = ({ rootState }) =>
.then(({ data }) => { .then(({ data }) => {
const { id } = data.commit; const { id } = data.commit;
const selectedBranch = const selectedBranch =
rootState.projects[rootState.currentProjectId].branches[ rootState.projects[rootState.currentProjectId].branches[rootState.currentBranchId];
rootState.currentBranchId
];
if (selectedBranch.workingReference !== id) { if (selectedBranch.workingReference !== id) {
return true; return true;
...@@ -112,43 +110,25 @@ export const updateFilesAfterCommit = ( ...@@ -112,43 +110,25 @@ export const updateFilesAfterCommit = (
{ root: true }, { root: true },
); );
eventHub.$emit(`editor.update.model.content.${file.path}`, { eventHub.$emit(`editor.update.model.content.${file.key}`, {
content: file.content, content: file.content,
changed: !!changedFile, changed: !!changedFile,
}); });
}); });
if ( if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH && rootGetters.activeFile) {
state.commitAction === consts.COMMIT_TO_NEW_BRANCH &&
rootGetters.activeFile
) {
router.push( router.push(
`/project/${rootState.currentProjectId}/blob/${branch}/${ `/project/${rootState.currentProjectId}/blob/${branch}/${rootGetters.activeFile.path}`,
rootGetters.activeFile.path
}`,
); );
} }
dispatch('updateCommitAction', consts.COMMIT_TO_CURRENT_BRANCH); dispatch('updateCommitAction', consts.COMMIT_TO_CURRENT_BRANCH);
}; };
export const commitChanges = ({ export const commitChanges = ({ commit, state, getters, dispatch, rootState }) => {
commit,
state,
getters,
dispatch,
rootState,
}) => {
const newBranch = state.commitAction !== consts.COMMIT_TO_CURRENT_BRANCH; const newBranch = state.commitAction !== consts.COMMIT_TO_CURRENT_BRANCH;
const payload = createCommitPayload( const payload = createCommitPayload(getters.branchName, newBranch, state, rootState);
getters.branchName, const getCommitStatus = newBranch ? Promise.resolve(false) : dispatch('checkCommitStatus');
newBranch,
state,
rootState,
);
const getCommitStatus = newBranch
? Promise.resolve(false)
: dispatch('checkCommitStatus');
commit(types.UPDATE_LOADING, true); commit(types.UPDATE_LOADING, true);
......
...@@ -133,10 +133,7 @@ describe('IDE commit module actions', () => { ...@@ -133,10 +133,7 @@ describe('IDE commit module actions', () => {
store store
.dispatch('commit/checkCommitStatus') .dispatch('commit/checkCommitStatus')
.then(() => { .then(() => {
expect(service.getBranchData).toHaveBeenCalledWith( expect(service.getBranchData).toHaveBeenCalledWith('abcproject', 'master');
'abcproject',
'master',
);
done(); done();
}) })
...@@ -230,9 +227,7 @@ describe('IDE commit module actions', () => { ...@@ -230,9 +227,7 @@ describe('IDE commit module actions', () => {
branch, branch,
}) })
.then(() => { .then(() => {
expect( expect(store.state.projects.abcproject.branches.master.workingReference).toBe(data.id);
store.state.projects.abcproject.branches.master.workingReference,
).toBe(data.id);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -286,10 +281,10 @@ describe('IDE commit module actions', () => { ...@@ -286,10 +281,10 @@ describe('IDE commit module actions', () => {
branch, branch,
}) })
.then(() => { .then(() => {
expect(eventHub.$emit).toHaveBeenCalledWith( expect(eventHub.$emit).toHaveBeenCalledWith(`editor.update.model.content.${f.key}`, {
`editor.update.model.content.${f.path}`, content: f.content,
{ content: f.content, changed: false }, changed: false,
); });
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -304,9 +299,7 @@ describe('IDE commit module actions', () => { ...@@ -304,9 +299,7 @@ describe('IDE commit module actions', () => {
branch, branch,
}) })
.then(() => { .then(() => {
expect(router.push).toHaveBeenCalledWith( expect(router.push).toHaveBeenCalledWith(`/project/abcproject/blob/master/${f.path}`);
`/project/abcproject/blob/master/${f.path}`,
);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -321,9 +314,7 @@ describe('IDE commit module actions', () => { ...@@ -321,9 +314,7 @@ describe('IDE commit module actions', () => {
branch, branch,
}) })
.then(() => { .then(() => {
expect(store.state.commit.commitAction).not.toBe( expect(store.state.commit.commitAction).not.toBe(consts.COMMIT_TO_NEW_BRANCH);
consts.COMMIT_TO_NEW_BRANCH,
);
}) })
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
...@@ -445,9 +436,7 @@ describe('IDE commit module actions', () => { ...@@ -445,9 +436,7 @@ describe('IDE commit module actions', () => {
store store
.dispatch('commit/commitChanges') .dispatch('commit/commitChanges')
.then(() => { .then(() => {
expect(store.state.openFiles[0].lastCommit.message).toBe( expect(store.state.openFiles[0].lastCommit.message).toBe('test message');
'test message',
);
done(); 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