diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 09:10:17 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-09 09:10:17 +0000 |
commit | ad0265eead72a624ce7a020847db4f0f0c877e57 (patch) | |
tree | 206e0564b02aa9530e3c95f70eb10a77e074bdf0 /app/assets/javascripts/ide/stores | |
parent | 4dfc8711171fe0c04bc6b8b224687603026dea46 (diff) | |
download | gitlab-ce-ad0265eead72a624ce7a020847db4f0f0c877e57.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/ide/stores')
4 files changed, 50 insertions, 36 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/project.js b/app/assets/javascripts/ide/stores/actions/project.js index 0b168009847..ae3829dc35e 100644 --- a/app/assets/javascripts/ide/stores/actions/project.js +++ b/app/assets/javascripts/ide/stores/actions/project.js @@ -83,10 +83,14 @@ export const showBranchNotFoundError = ({ dispatch }, branchId) => { }); }; -export const showEmptyState = ({ commit, state, dispatch }, { projectId, branchId }) => { +export const loadEmptyBranch = ({ commit, state }, { projectId, branchId }) => { const treePath = `${projectId}/${branchId}`; + const currentTree = state.trees[`${projectId}/${branchId}`]; - dispatch('setCurrentBranchId', branchId); + // If we already have a tree, let's not recreate an empty one + if (currentTree) { + return; + } commit(types.CREATE_TREE, { treePath }); commit(types.TOGGLE_LOADING, { @@ -114,8 +118,16 @@ export const loadFile = ({ dispatch, state }, { basePath }) => { } }; -export const loadBranch = ({ dispatch, getters }, { projectId, branchId }) => - dispatch('getBranchData', { +export const loadBranch = ({ dispatch, getters, state }, { projectId, branchId }) => { + const currentProject = state.projects[projectId]; + + if (currentProject?.branches?.[branchId]) { + return Promise.resolve(); + } else if (getters.emptyRepo) { + return dispatch('loadEmptyBranch', { projectId, branchId }); + } + + return dispatch('getBranchData', { projectId, branchId, }) @@ -137,29 +149,23 @@ export const loadBranch = ({ dispatch, getters }, { projectId, branchId }) => dispatch('showBranchNotFoundError', branchId); throw err; }); +}; -export const openBranch = ({ dispatch, state, getters }, { projectId, branchId, basePath }) => { - const currentProject = state.projects[projectId]; - if (getters.emptyRepo) { - return dispatch('showEmptyState', { projectId, branchId }); - } - if (!currentProject || !currentProject.branches[branchId]) { - dispatch('setCurrentBranchId', branchId); - - return dispatch('loadBranch', { projectId, branchId }) - .then(() => dispatch('loadFile', { basePath })) - .catch( - () => - new Error( - sprintf( - __('An error occurred while getting files for - %{branchId}'), - { - branchId: `<strong>${esc(projectId)}/${esc(branchId)}</strong>`, - }, - false, - ), +export const openBranch = ({ dispatch }, { projectId, branchId, basePath }) => { + dispatch('setCurrentBranchId', branchId); + + return dispatch('loadBranch', { projectId, branchId }) + .then(() => dispatch('loadFile', { basePath })) + .catch( + () => + new Error( + sprintf( + __('An error occurred while getting files for - %{branchId}'), + { + branchId: `<strong>${esc(projectId)}/${esc(branchId)}</strong>`, + }, + false, ), - ); - } - return Promise.resolve(dispatch('loadFile', { basePath })); + ), + ); }; diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js index d7ad39019a5..5d0a8570906 100644 --- a/app/assets/javascripts/ide/stores/getters.js +++ b/app/assets/javascripts/ide/stores/getters.js @@ -4,6 +4,7 @@ import { packageJsonPath, PERMISSION_READ_MR, PERMISSION_CREATE_MR, + PERMISSION_PUSH_CODE, } from '../constants'; export const activeFile = state => state.openFiles.find(file => file.active) || null; @@ -120,8 +121,9 @@ export const packageJson = state => state.entries[packageJsonPath]; export const isOnDefaultBranch = (_state, getters) => getters.currentProject && getters.currentProject.default_branch === getters.branchName; -export const canPushToBranch = (_state, getters) => - getters.currentBranch && getters.currentBranch.can_push; +export const canPushToBranch = (_state, getters) => { + return Boolean(getters.currentBranch ? getters.currentBranch.can_push : getters.canPushCode); +}; export const isFileDeletedAndReadded = (state, getters) => path => { const stagedFile = getters.getStagedFile(path); @@ -157,5 +159,8 @@ export const canReadMergeRequests = (state, getters) => export const canCreateMergeRequests = (state, getters) => Boolean(getters.findProjectPermissions(state.currentProjectId)[PERMISSION_CREATE_MR]); +export const canPushCode = (state, getters) => + Boolean(getters.findProjectPermissions(state.currentProjectId)[PERMISSION_PUSH_CODE]); + // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; diff --git a/app/assets/javascripts/ide/stores/modules/commit/actions.js b/app/assets/javascripts/ide/stores/modules/commit/actions.js index 9bf0542cd0b..505daa8834d 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/actions.js +++ b/app/assets/javascripts/ide/stores/modules/commit/actions.js @@ -106,6 +106,9 @@ export const updateFilesAfterCommit = ({ commit, dispatch, rootState, rootGetter }; export const commitChanges = ({ commit, state, getters, dispatch, rootState, rootGetters }) => { + // Pull commit options out because they could change + // During some of the pre and post commit processing + const { shouldCreateMR, isCreatingNewBranch, branchName } = getters; const newBranch = state.commitAction !== consts.COMMIT_TO_CURRENT_BRANCH; const stageFilesPromise = rootState.stagedFiles.length ? Promise.resolve() @@ -116,7 +119,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo return stageFilesPromise .then(() => { const payload = createCommitPayload({ - branch: getters.branchName, + branch: branchName, newBranch, getters, state, @@ -149,7 +152,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo dispatch('updateCommitMessage', ''); return dispatch('updateFilesAfterCommit', { data, - branch: getters.branchName, + branch: branchName, }) .then(() => { commit(rootTypes.CLEAR_STAGED_CHANGES, null, { root: true }); @@ -158,15 +161,15 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo commit(rootTypes.SET_LAST_COMMIT_MSG, '', { root: true }); }, 5000); - if (getters.shouldCreateMR) { + if (shouldCreateMR) { const { currentProject } = rootGetters; - const targetBranch = getters.isCreatingNewBranch + const targetBranch = isCreatingNewBranch ? rootState.currentBranchId : currentProject.default_branch; dispatch( 'redirectToUrl', - createNewMergeRequestUrl(currentProject.web_url, getters.branchName, targetBranch), + createNewMergeRequestUrl(currentProject.web_url, branchName, targetBranch), { root: true }, ); } @@ -194,7 +197,7 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo if (rootGetters.activeFile) { router.push( - `/project/${rootState.currentProjectId}/blob/${getters.branchName}/-/${rootGetters.activeFile.path}`, + `/project/${rootState.currentProjectId}/blob/${branchName}/-/${rootGetters.activeFile.path}`, ); } } diff --git a/app/assets/javascripts/ide/stores/modules/commit/getters.js b/app/assets/javascripts/ide/stores/modules/commit/getters.js index e421d44b6de..413c4b0110d 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/getters.js +++ b/app/assets/javascripts/ide/stores/modules/commit/getters.js @@ -55,7 +55,7 @@ export const shouldHideNewMrOption = (_state, getters, _rootState, rootGetters) rootGetters.canPushToBranch; export const shouldDisableNewMrOption = (state, getters, rootState, rootGetters) => - !rootGetters.canCreateMergeRequests; + !rootGetters.canCreateMergeRequests || rootGetters.emptyRepo; export const shouldCreateMR = (state, getters) => state.shouldCreateMR && !getters.shouldDisableNewMrOption; |