diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-20 18:07:53 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-12-20 18:07:53 +0000 |
commit | 682360490629376e2ec07d737c7d7dbfdaaeeab7 (patch) | |
tree | 7abe62a4d200738ac086ac0c0bd633ce0bc03f00 /app/assets/javascripts/ide/stores | |
parent | 2f26f81ce3e3f97ddc5ce5e2e103925d7d0d170f (diff) | |
download | gitlab-ce-682360490629376e2ec07d737c7d7dbfdaaeeab7.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/ide/stores')
-rw-r--r-- | app/assets/javascripts/ide/stores/actions.js | 36 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/file.js | 22 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/getters.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations/file.js | 34 |
4 files changed, 56 insertions, 37 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js index 7a386299eed..66a89582da3 100644 --- a/app/assets/javascripts/ide/stores/actions.js +++ b/app/assets/javascripts/ide/stores/actions.js @@ -134,28 +134,40 @@ export const scrollToTab = () => { }); }; -export const stageAllChanges = ({ state, commit, dispatch }) => { +export const stageAllChanges = ({ state, commit, dispatch, getters }) => { const openFile = state.openFiles[0]; commit(types.SET_LAST_COMMIT_MSG, ''); - state.changedFiles.forEach(file => commit(types.STAGE_CHANGE, file.path)); + state.changedFiles.forEach(file => + commit(types.STAGE_CHANGE, { path: file.path, diffInfo: getters.getDiffInfo(file.path) }), + ); - dispatch('openPendingTab', { - file: state.stagedFiles.find(f => f.path === openFile.path), - keyPrefix: stageKeys.staged, - }); + const file = getters.getStagedFile(openFile.path); + + if (file) { + dispatch('openPendingTab', { + file, + keyPrefix: stageKeys.staged, + }); + } }; -export const unstageAllChanges = ({ state, commit, dispatch }) => { +export const unstageAllChanges = ({ state, commit, dispatch, getters }) => { const openFile = state.openFiles[0]; - state.stagedFiles.forEach(file => commit(types.UNSTAGE_CHANGE, file.path)); + state.stagedFiles.forEach(file => + commit(types.UNSTAGE_CHANGE, { path: file.path, diffInfo: getters.getDiffInfo(file.path) }), + ); - dispatch('openPendingTab', { - file: state.changedFiles.find(f => f.path === openFile.path), - keyPrefix: stageKeys.unstaged, - }); + const file = getters.getChangedFile(openFile.path); + + if (file) { + dispatch('openPendingTab', { + file, + keyPrefix: stageKeys.unstaged, + }); + } }; export const updateViewer = ({ commit }, viewer) => { diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index 8864224c19e..27b8e32bf5e 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -214,20 +214,20 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) = eventHub.$emit(`editor.update.model.dispose.unstaged-${file.key}`, file.content); }; -export const stageChange = ({ commit, state, dispatch }, path) => { - const stagedFile = state.stagedFiles.find(f => f.path === path); - const openFile = state.openFiles.find(f => f.path === path); +export const stageChange = ({ commit, dispatch, getters }, path) => { + const stagedFile = getters.getStagedFile(path); + const openFile = getters.getOpenFile(path); - commit(types.STAGE_CHANGE, path); + commit(types.STAGE_CHANGE, { path, diffInfo: getters.getDiffInfo(path) }); commit(types.SET_LAST_COMMIT_MSG, ''); if (stagedFile) { eventHub.$emit(`editor.update.model.new.content.staged-${stagedFile.key}`, stagedFile.content); } - if (openFile && openFile.active) { - const file = state.stagedFiles.find(f => f.path === path); + const file = getters.getStagedFile(path); + if (openFile && openFile.active && file) { dispatch('openPendingTab', { file, keyPrefix: stageKeys.staged, @@ -235,14 +235,14 @@ export const stageChange = ({ commit, state, dispatch }, path) => { } }; -export const unstageChange = ({ commit, dispatch, state }, path) => { - const openFile = state.openFiles.find(f => f.path === path); +export const unstageChange = ({ commit, dispatch, getters }, path) => { + const openFile = getters.getOpenFile(path); - commit(types.UNSTAGE_CHANGE, path); + commit(types.UNSTAGE_CHANGE, { path, diffInfo: getters.getDiffInfo(path) }); - if (openFile && openFile.active) { - const file = state.changedFiles.find(f => f.path === path); + const file = getters.getChangedFile(path); + if (openFile && openFile.active && file) { dispatch('openPendingTab', { file, keyPrefix: stageKeys.unstaged, diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js index bb8374b4e78..2fc574cd343 100644 --- a/app/assets/javascripts/ide/stores/getters.js +++ b/app/assets/javascripts/ide/stores/getters.js @@ -64,6 +64,7 @@ export const allBlobs = state => export const getChangedFile = state => path => state.changedFiles.find(f => f.path === path); export const getStagedFile = state => path => state.stagedFiles.find(f => f.path === path); +export const getOpenFile = state => path => state.openFiles.find(f => f.path === path); export const lastOpenedFile = state => [...state.changedFiles, ...state.stagedFiles].sort((a, b) => b.lastOpenedAt - a.lastOpenedAt)[0]; diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js index 8caeb2d73b2..1b126352330 100644 --- a/app/assets/javascripts/ide/stores/mutations/file.js +++ b/app/assets/javascripts/ide/stores/mutations/file.js @@ -164,31 +164,32 @@ export default { changedFiles: state.changedFiles.filter(f => f.path !== path), }); }, - [types.STAGE_CHANGE](state, path) { + [types.STAGE_CHANGE](state, { path, diffInfo }) { const stagedFile = state.stagedFiles.find(f => f.path === path); Object.assign(state, { changedFiles: state.changedFiles.filter(f => f.path !== path), entries: Object.assign(state.entries, { [path]: Object.assign(state.entries[path], { - staged: true, + staged: diffInfo.exists, + changed: diffInfo.changed, + tempFile: diffInfo.tempFile, + deleted: diffInfo.deleted, }), }), }); if (stagedFile) { - Object.assign(stagedFile, { - ...state.entries[path], - }); + Object.assign(stagedFile, { ...state.entries[path] }); } else { - Object.assign(state, { - stagedFiles: state.stagedFiles.concat({ - ...state.entries[path], - }), - }); + state.stagedFiles = [...state.stagedFiles, { ...state.entries[path] }]; + } + + if (!diffInfo.exists) { + state.stagedFiles = state.stagedFiles.filter(f => f.path !== path); } }, - [types.UNSTAGE_CHANGE](state, path) { + [types.UNSTAGE_CHANGE](state, { path, diffInfo }) { const changedFile = state.changedFiles.find(f => f.path === path); const stagedFile = state.stagedFiles.find(f => f.path === path); @@ -201,9 +202,11 @@ export default { changed: true, }); - Object.assign(state, { - changedFiles: state.changedFiles.concat(state.entries[path]), - }); + state.changedFiles = state.changedFiles.concat(state.entries[path]); + } + + if (!diffInfo.exists) { + state.changedFiles = state.changedFiles.filter(f => f.path !== path); } Object.assign(state, { @@ -211,6 +214,9 @@ export default { entries: Object.assign(state.entries, { [path]: Object.assign(state.entries[path], { staged: false, + changed: diffInfo.changed, + tempFile: diffInfo.tempFile, + deleted: diffInfo.deleted, }), }), }); |