diff options
author | Phil Hughes <me@iamphill.com> | 2019-04-05 16:48:25 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2019-04-05 16:48:25 +0300 |
commit | 66699030ef82c14b4c209045f7cc6cb0d995f989 (patch) | |
tree | 75c6298c56dbcc620a0b1748b8fb73970ddc2a06 /app/assets/javascripts/ide | |
parent | 8e04450cc284dd079427a7a9a3c1380f8cdc8767 (diff) | |
parent | 2571856fc52eecf0d39f517905e14e7a9d2267da (diff) |
Merge branch '57482-shortcut-to-create-merge-request-from-web-ide' into 'master'
Resolve "Shortcut to create merge request from Web IDE"
Closes #57482
See merge request gitlab-org/gitlab-ce!26792
Diffstat (limited to 'app/assets/javascripts/ide')
9 files changed, 75 insertions, 37 deletions
diff --git a/app/assets/javascripts/ide/components/commit_sidebar/actions.vue b/app/assets/javascripts/ide/components/commit_sidebar/actions.vue index d360dc42cd3..1824a0f6147 100644 --- a/app/assets/javascripts/ide/components/commit_sidebar/actions.vue +++ b/app/assets/javascripts/ide/components/commit_sidebar/actions.vue @@ -1,17 +1,23 @@ <script> import _ from 'underscore'; -import { mapActions, mapState, mapGetters } from 'vuex'; +import { mapActions, mapState, mapGetters, createNamespacedHelpers } from 'vuex'; import { sprintf, __ } from '~/locale'; -import * as consts from '../../stores/modules/commit/constants'; +import consts from '../../stores/modules/commit/constants'; import RadioGroup from './radio_group.vue'; +const { mapState: mapCommitState, mapGetters: mapCommitGetters } = createNamespacedHelpers( + 'commit', +); + export default { components: { RadioGroup, }, computed: { ...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']), - ...mapGetters(['currentProject', 'currentBranch']), + ...mapCommitState(['commitAction', 'shouldCreateMR', 'shouldDisableNewMrOption']), + ...mapGetters(['currentProject', 'currentBranch', 'currentMergeRequest']), + ...mapCommitGetters(['shouldDisableNewMrOption']), commitToCurrentBranchText() { return sprintf( __('Commit to %{branchName} branch'), @@ -32,7 +38,7 @@ export default { this.updateSelectedCommitAction(); }, methods: { - ...mapActions('commit', ['updateCommitAction']), + ...mapActions('commit', ['updateCommitAction', 'toggleShouldCreateMR']), updateSelectedCommitAction() { if (this.currentBranch && !this.currentBranch.can_push) { this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH); @@ -43,7 +49,6 @@ export default { }, commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH, commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH, - commitToNewBranchMR: consts.COMMIT_TO_NEW_BRANCH_MR, currentBranchPermissionsTooltip: __( "This option is disabled as you don't have write permissions for the current branch", ), @@ -64,13 +69,17 @@ export default { :label="__('Create a new branch')" :show-input="true" /> - <radio-group - v-if="currentProject.merge_requests_enabled" - :value="$options.commitToNewBranchMR" - :label="__('Create a new branch and merge request')" - :title="__('This option is disabled while you still have unstaged changes')" - :show-input="true" - :disabled="disableMergeRequestRadio" - /> + <hr class="my-2" /> + <label class="mb-0"> + <input + :checked="shouldCreateMR" + :disabled="shouldDisableNewMrOption" + type="checkbox" + @change="toggleShouldCreateMR" + /> + <span class="prepend-left-10" :class="{ 'text-secondary': shouldDisableNewMrOption }"> + {{ __('Start a new merge request') }} + </span> + </label> </div> </template> diff --git a/app/assets/javascripts/ide/components/repo_commit_section.vue b/app/assets/javascripts/ide/components/repo_commit_section.vue index 8dd88f187d4..99f1d4a573d 100644 --- a/app/assets/javascripts/ide/components/repo_commit_section.vue +++ b/app/assets/javascripts/ide/components/repo_commit_section.vue @@ -5,7 +5,7 @@ import Icon from '~/vue_shared/components/icon.vue'; import DeprecatedModal from '~/vue_shared/components/deprecated_modal.vue'; import CommitFilesList from './commit_sidebar/list.vue'; import EmptyState from './commit_sidebar/empty_state.vue'; -import * as consts from '../stores/modules/commit/constants'; +import consts from '../stores/modules/commit/constants'; import { activityBarViews, stageKeys } from '../constants'; export default { diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js index 8ad85074d6b..490658a4543 100644 --- a/app/assets/javascripts/ide/stores/getters.js +++ b/app/assets/javascripts/ide/stores/getters.js @@ -25,7 +25,10 @@ export const projectsWithTrees = state => }); export const currentMergeRequest = state => { - if (state.projects[state.currentProjectId]) { + if ( + state.projects[state.currentProjectId] && + state.projects[state.currentProjectId].mergeRequests + ) { return state.projects[state.currentProjectId].mergeRequests[state.currentMergeRequestId]; } return null; diff --git a/app/assets/javascripts/ide/stores/modules/commit/actions.js b/app/assets/javascripts/ide/stores/modules/commit/actions.js index 24c2f71ae2b..c2760eb1554 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/actions.js +++ b/app/assets/javascripts/ide/stores/modules/commit/actions.js @@ -6,7 +6,7 @@ import { createCommitPayload, createNewMergeRequestUrl } from '../../utils'; import router from '../../../ide_router'; import service from '../../../services'; import * as types from './mutation_types'; -import * as consts from './constants'; +import consts from './constants'; import { activityBarViews } from '../../../constants'; import eventHub from '../../../eventhub'; @@ -18,16 +18,23 @@ export const discardDraft = ({ commit }) => { commit(types.UPDATE_COMMIT_MESSAGE, ''); }; -export const updateCommitAction = ({ commit }, commitAction) => { - commit(types.UPDATE_COMMIT_ACTION, commitAction); +export const updateCommitAction = ({ commit, rootGetters }, commitAction) => { + commit(types.UPDATE_COMMIT_ACTION, { + commitAction, + currentMergeRequest: rootGetters.currentMergeRequest, + }); +}; + +export const toggleShouldCreateMR = ({ commit }) => { + commit(types.TOGGLE_SHOULD_CREATE_MR); }; export const updateBranchName = ({ commit }, branchName) => { commit(types.UPDATE_NEW_BRANCH_NAME, branchName); }; -export const setLastCommitMessage = ({ rootState, commit }, data) => { - const currentProject = rootState.projects[rootState.currentProjectId]; +export const setLastCommitMessage = ({ commit, rootGetters }, data) => { + const { currentProject } = rootGetters; const commitStats = data.stats ? sprintf(__('with %{additions} additions, %{deletions} deletions.'), { additions: data.stats.additions, @@ -48,8 +55,8 @@ export const setLastCommitMessage = ({ rootState, commit }, data) => { commit(rootTypes.SET_LAST_COMMIT_MSG, commitMsg, { root: true }); }; -export const updateFilesAfterCommit = ({ commit, dispatch, rootState }, { data }) => { - const selectedProject = rootState.projects[rootState.currentProjectId]; +export const updateFilesAfterCommit = ({ commit, dispatch, rootState, rootGetters }, { data }) => { + const selectedProject = rootGetters.currentProject; const lastCommit = { commit_path: `${selectedProject.web_url}/commit/${data.id}`, commit: { @@ -135,14 +142,15 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo branch: getters.branchName, }) .then(() => { - if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR) { + if (state.shouldCreateMR) { + const { currentProject } = rootGetters; + const targetBranch = getters.isCreatingNewBranch + ? rootState.currentBranchId + : currentProject.default_branch; + dispatch( 'redirectToUrl', - createNewMergeRequestUrl( - rootState.projects[rootState.currentProjectId].web_url, - getters.branchName, - rootState.currentBranchId, - ), + createNewMergeRequestUrl(currentProject.web_url, getters.branchName, targetBranch), { root: true }, ); } diff --git a/app/assets/javascripts/ide/stores/modules/commit/constants.js b/app/assets/javascripts/ide/stores/modules/commit/constants.js index 230b0a3d9b5..c6c3701effe 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/constants.js +++ b/app/assets/javascripts/ide/stores/modules/commit/constants.js @@ -1,3 +1,7 @@ -export const COMMIT_TO_CURRENT_BRANCH = '1'; -export const COMMIT_TO_NEW_BRANCH = '2'; -export const COMMIT_TO_NEW_BRANCH_MR = '3'; +const COMMIT_TO_CURRENT_BRANCH = '1'; +const COMMIT_TO_NEW_BRANCH = '2'; + +export default { + COMMIT_TO_CURRENT_BRANCH, + COMMIT_TO_NEW_BRANCH, +}; diff --git a/app/assets/javascripts/ide/stores/modules/commit/getters.js b/app/assets/javascripts/ide/stores/modules/commit/getters.js index bbe40b2ec2f..6aa5d22a4ea 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/getters.js +++ b/app/assets/javascripts/ide/stores/modules/commit/getters.js @@ -1,5 +1,5 @@ import { sprintf, n__, __ } from '../../../../locale'; -import * as consts from './constants'; +import consts from './constants'; const BRANCH_SUFFIX_COUNT = 5; const createTranslatedTextForFiles = (files, text) => { @@ -20,10 +20,7 @@ export const placeholderBranchName = (state, _, rootState) => )}`; export const branchName = (state, getters, rootState) => { - if ( - state.commitAction === consts.COMMIT_TO_NEW_BRANCH || - state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR - ) { + if (state.commitAction === consts.COMMIT_TO_NEW_BRANCH) { if (state.newBranchName === '') { return getters.placeholderBranchName; } @@ -49,5 +46,10 @@ export const preBuiltCommitMessage = (state, _, rootState) => { .join('\n'); }; +export const isCreatingNewBranch = state => state.commitAction === consts.COMMIT_TO_NEW_BRANCH; + +export const shouldDisableNewMrOption = (state, _getters, _rootState, rootGetters) => + rootGetters.currentMergeRequest && state.commitAction === consts.COMMIT_TO_CURRENT_BRANCH; + // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; diff --git a/app/assets/javascripts/ide/stores/modules/commit/mutation_types.js b/app/assets/javascripts/ide/stores/modules/commit/mutation_types.js index 9221f054e9f..7ad8f3570b7 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/mutation_types.js +++ b/app/assets/javascripts/ide/stores/modules/commit/mutation_types.js @@ -2,3 +2,4 @@ export const UPDATE_COMMIT_MESSAGE = 'UPDATE_COMMIT_MESSAGE'; export const UPDATE_COMMIT_ACTION = 'UPDATE_COMMIT_ACTION'; export const UPDATE_NEW_BRANCH_NAME = 'UPDATE_NEW_BRANCH_NAME'; export const UPDATE_LOADING = 'UPDATE_LOADING'; +export const TOGGLE_SHOULD_CREATE_MR = 'TOGGLE_SHOULD_CREATE_MR'; diff --git a/app/assets/javascripts/ide/stores/modules/commit/mutations.js b/app/assets/javascripts/ide/stores/modules/commit/mutations.js index 797357e3df9..be0f894c059 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/mutations.js +++ b/app/assets/javascripts/ide/stores/modules/commit/mutations.js @@ -1,4 +1,5 @@ import * as types from './mutation_types'; +import consts from './constants'; export default { [types.UPDATE_COMMIT_MESSAGE](state, commitMessage) { @@ -6,9 +7,13 @@ export default { commitMessage, }); }, - [types.UPDATE_COMMIT_ACTION](state, commitAction) { + [types.UPDATE_COMMIT_ACTION](state, { commitAction, currentMergeRequest }) { Object.assign(state, { commitAction, + shouldCreateMR: + commitAction === consts.COMMIT_TO_CURRENT_BRANCH && currentMergeRequest + ? false + : state.shouldCreateMR, }); }, [types.UPDATE_NEW_BRANCH_NAME](state, newBranchName) { @@ -21,4 +26,9 @@ export default { submitCommitLoading, }); }, + [types.TOGGLE_SHOULD_CREATE_MR](state) { + Object.assign(state, { + shouldCreateMR: !state.shouldCreateMR, + }); + }, }; diff --git a/app/assets/javascripts/ide/stores/modules/commit/state.js b/app/assets/javascripts/ide/stores/modules/commit/state.js index 8dae50961b0..5c0e6a41ca1 100644 --- a/app/assets/javascripts/ide/stores/modules/commit/state.js +++ b/app/assets/javascripts/ide/stores/modules/commit/state.js @@ -3,4 +3,5 @@ export default () => ({ commitAction: '1', newBranchName: '', submitCommitLoading: false, + shouldCreateMR: false, }); |