debian-mirror-gitlab/app/assets/javascripts/ide/components/commit_sidebar/actions.vue

86 lines
2.7 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2018-10-15 14:42:47 +05:30
import _ from 'underscore';
2019-07-07 11:18:12 +05:30
import { mapActions, mapState, mapGetters, createNamespacedHelpers } from 'vuex';
2018-10-15 14:42:47 +05:30
import { sprintf, __ } from '~/locale';
2019-07-07 11:18:12 +05:30
import consts from '../../stores/modules/commit/constants';
2018-10-15 14:42:47 +05:30
import RadioGroup from './radio_group.vue';
2018-05-09 12:01:36 +05:30
2019-07-07 11:18:12 +05:30
const { mapState: mapCommitState, mapGetters: mapCommitGetters } = createNamespacedHelpers(
'commit',
);
2018-10-15 14:42:47 +05:30
export default {
components: {
RadioGroup,
},
computed: {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
2019-07-07 11:18:12 +05:30
...mapCommitState(['commitAction', 'shouldCreateMR', 'shouldDisableNewMrOption']),
...mapGetters(['currentProject', 'currentBranch', 'currentMergeRequest']),
...mapCommitGetters(['shouldDisableNewMrOption']),
2018-10-15 14:42:47 +05:30
commitToCurrentBranchText() {
return sprintf(
__('Commit to %{branchName} branch'),
{ branchName: `<strong class="monospace">${_.escape(this.currentBranchId)}</strong>` },
false,
);
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
disableMergeRequestRadio() {
return this.changedFiles.length > 0 && this.stagedFiles.length > 0;
2018-05-09 12:01:36 +05:30
},
2018-10-15 14:42:47 +05:30
},
2018-11-08 19:23:39 +05:30
watch: {
disableMergeRequestRadio() {
this.updateSelectedCommitAction();
},
},
2018-10-15 14:42:47 +05:30
mounted() {
2018-11-08 19:23:39 +05:30
this.updateSelectedCommitAction();
2018-10-15 14:42:47 +05:30
},
methods: {
2019-07-07 11:18:12 +05:30
...mapActions('commit', ['updateCommitAction', 'toggleShouldCreateMR']),
2018-11-08 19:23:39 +05:30
updateSelectedCommitAction() {
if (this.currentBranch && !this.currentBranch.can_push) {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
} else if (this.disableMergeRequestRadio) {
this.updateCommitAction(consts.COMMIT_TO_CURRENT_BRANCH);
}
},
2018-10-15 14:42:47 +05:30
},
commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH,
commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH,
2018-11-08 19:23:39 +05:30
currentBranchPermissionsTooltip: __(
"This option is disabled as you don't have write permissions for the current branch",
),
2018-10-15 14:42:47 +05:30
};
2018-05-09 12:01:36 +05:30
</script>
<template>
<div class="append-bottom-15 ide-commit-radios">
<radio-group
:value="$options.commitToCurrentBranch"
2018-11-08 19:23:39 +05:30
:disabled="currentBranch && !currentBranch.can_push"
:title="$options.currentBranchPermissionsTooltip"
2018-05-09 12:01:36 +05:30
>
2019-02-15 15:39:39 +05:30
<span class="ide-radio-label" v-html="commitToCurrentBranchText"> </span>
2018-05-09 12:01:36 +05:30
</radio-group>
<radio-group
:value="$options.commitToNewBranch"
:label="__('Create a new branch')"
:show-input="true"
/>
2019-07-07 11:18:12 +05:30
<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>
2018-05-09 12:01:36 +05:30
</div>
</template>