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

76 lines
2.3 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-09-04 21:01:54 +05:30
import { 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';
2019-09-04 21:01:54 +05:30
import NewMergeRequestOption from './new_merge_request_option.vue';
2018-05-09 12:01:36 +05:30
2019-09-04 21:01:54 +05:30
const { mapState: mapCommitState, mapActions: mapCommitActions } = createNamespacedHelpers(
2019-07-07 11:18:12 +05:30
'commit',
);
2018-10-15 14:42:47 +05:30
export default {
components: {
RadioGroup,
2019-09-04 21:01:54 +05:30
NewMergeRequestOption,
2018-10-15 14:42:47 +05:30
},
computed: {
...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
2019-09-04 21:01:54 +05:30
...mapCommitState(['commitAction']),
...mapGetters(['currentBranch']),
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
},
2019-09-04 21:01:54 +05:30
containsStagedChanges() {
2018-10-15 14:42:47 +05:30
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: {
2019-09-04 21:01:54 +05:30
containsStagedChanges() {
2018-11-08 19:23:39 +05:30
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-09-04 21:01:54 +05:30
...mapCommitActions(['updateCommitAction']),
2018-11-08 19:23:39 +05:30
updateSelectedCommitAction() {
if (this.currentBranch && !this.currentBranch.can_push) {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
2019-09-04 21:01:54 +05:30
} else if (this.containsStagedChanges) {
2018-11-08 19:23:39 +05:30
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>
2019-09-04 21:01:54 +05:30
<div class="append-bottom-15 ide-commit-options">
2018-05-09 12:01:36 +05:30
<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-09-04 21:01:54 +05:30
<new-merge-request-option />
2018-05-09 12:01:36 +05:30
</div>
</template>