summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-04-09 09:10:17 +0000
commitad0265eead72a624ce7a020847db4f0f0c877e57 (patch)
tree206e0564b02aa9530e3c95f70eb10a77e074bdf0 /app/assets/javascripts/ide
parent4dfc8711171fe0c04bc6b8b224687603026dea46 (diff)
downloadgitlab-ce-ad0265eead72a624ce7a020847db4f0f0c877e57.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/ide')
-rw-r--r--app/assets/javascripts/ide/components/commit_sidebar/actions.vue31
-rw-r--r--app/assets/javascripts/ide/constants.js1
-rw-r--r--app/assets/javascripts/ide/queries/getUserPermissions.query.graphql3
-rw-r--r--app/assets/javascripts/ide/stores/actions/project.js60
-rw-r--r--app/assets/javascripts/ide/stores/getters.js9
-rw-r--r--app/assets/javascripts/ide/stores/modules/commit/actions.js15
-rw-r--r--app/assets/javascripts/ide/stores/modules/commit/getters.js2
7 files changed, 72 insertions, 49 deletions
diff --git a/app/assets/javascripts/ide/components/commit_sidebar/actions.vue b/app/assets/javascripts/ide/components/commit_sidebar/actions.vue
index 3276d21a04e..6a8ea506d1b 100644
--- a/app/assets/javascripts/ide/components/commit_sidebar/actions.vue
+++ b/app/assets/javascripts/ide/components/commit_sidebar/actions.vue
@@ -18,7 +18,7 @@ export default {
computed: {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
...mapCommitState(['commitAction']),
- ...mapGetters(['currentBranch']),
+ ...mapGetters(['currentBranch', 'emptyRepo', 'canPushToBranch']),
commitToCurrentBranchText() {
return sprintf(
s__('IDE|Commit to %{branchName} branch'),
@@ -29,6 +29,13 @@ export default {
containsStagedChanges() {
return this.changedFiles.length > 0 && this.stagedFiles.length > 0;
},
+ shouldDefaultToCurrentBranch() {
+ if (this.emptyRepo) {
+ return true;
+ }
+
+ return this.canPushToBranch && !this.currentBranch?.default;
+ },
},
watch: {
containsStagedChanges() {
@@ -43,13 +50,11 @@ export default {
methods: {
...mapCommitActions(['updateCommitAction']),
updateSelectedCommitAction() {
- if (!this.currentBranch) {
+ if (!this.currentBranch && !this.emptyRepo) {
return;
}
- const { can_push: canPush = false, default: isDefault = false } = this.currentBranch;
-
- if (canPush && !isDefault) {
+ if (this.shouldDefaultToCurrentBranch) {
this.updateCommitAction(consts.COMMIT_TO_CURRENT_BRANCH);
} else {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
@@ -68,7 +73,7 @@ export default {
<div class="append-bottom-15 ide-commit-options">
<radio-group
:value="$options.commitToCurrentBranch"
- :disabled="currentBranch && !currentBranch.can_push"
+ :disabled="!canPushToBranch"
:title="$options.currentBranchPermissionsTooltip"
>
<span
@@ -77,11 +82,13 @@ export default {
v-html="commitToCurrentBranchText"
></span>
</radio-group>
- <radio-group
- :value="$options.commitToNewBranch"
- :label="__('Create a new branch')"
- :show-input="true"
- />
- <new-merge-request-option />
+ <template v-if="!emptyRepo">
+ <radio-group
+ :value="$options.commitToNewBranch"
+ :label="__('Create a new branch')"
+ :show-input="true"
+ />
+ <new-merge-request-option />
+ </template>
</div>
</template>
diff --git a/app/assets/javascripts/ide/constants.js b/app/assets/javascripts/ide/constants.js
index e7762f9e0f2..fa2672aaece 100644
--- a/app/assets/javascripts/ide/constants.js
+++ b/app/assets/javascripts/ide/constants.js
@@ -10,6 +10,7 @@ export const FILE_VIEW_MODE_PREVIEW = 'preview';
export const PERMISSION_CREATE_MR = 'createMergeRequestIn';
export const PERMISSION_READ_MR = 'readMergeRequest';
+export const PERMISSION_PUSH_CODE = 'pushCode';
export const viewerTypes = {
mr: 'mrdiff',
diff --git a/app/assets/javascripts/ide/queries/getUserPermissions.query.graphql b/app/assets/javascripts/ide/queries/getUserPermissions.query.graphql
index 48f63995f44..2c9013ffa9c 100644
--- a/app/assets/javascripts/ide/queries/getUserPermissions.query.graphql
+++ b/app/assets/javascripts/ide/queries/getUserPermissions.query.graphql
@@ -2,7 +2,8 @@ query getUserPermissions($projectPath: ID!) {
project(fullPath: $projectPath) {
userPermissions {
createMergeRequestIn,
- readMergeRequest
+ readMergeRequest,
+ pushCode
}
}
}
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;