actions.vue 2.41 KB
Newer Older
Phil Hughes's avatar
Phil Hughes committed
1
<script>
2
import _ from 'underscore';
3
import { mapActions, mapState, mapGetters } from 'vuex';
Phil Hughes's avatar
Phil Hughes committed
4 5 6
import { sprintf, __ } from '~/locale';
import * as consts from '../../stores/modules/commit/constants';
import RadioGroup from './radio_group.vue';
Phil Hughes's avatar
Phil Hughes committed
7

Phil Hughes's avatar
Phil Hughes committed
8 9 10 11 12
export default {
  components: {
    RadioGroup,
  },
  computed: {
13
    ...mapState(['currentBranchId', 'changedFiles', 'stagedFiles']),
14
    ...mapGetters(['currentProject', 'currentBranch']),
Phil Hughes's avatar
Phil Hughes committed
15 16 17
    commitToCurrentBranchText() {
      return sprintf(
        __('Commit to %{branchName} branch'),
18
        { branchName: `<strong class="monospace">${_.escape(this.currentBranchId)}</strong>` },
Phil Hughes's avatar
Phil Hughes committed
19 20
        false,
      );
Phil Hughes's avatar
Phil Hughes committed
21
    },
Phil Hughes's avatar
Phil Hughes committed
22 23 24
    disableMergeRequestRadio() {
      return this.changedFiles.length > 0 && this.stagedFiles.length > 0;
    },
Phil Hughes's avatar
Phil Hughes committed
25
  },
26 27 28 29 30
  watch: {
    disableMergeRequestRadio() {
      this.updateSelectedCommitAction();
    },
  },
31
  mounted() {
32
    this.updateSelectedCommitAction();
33 34 35
  },
  methods: {
    ...mapActions('commit', ['updateCommitAction']),
36 37 38 39 40 41 42
    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);
      }
    },
43
  },
Phil Hughes's avatar
Phil Hughes committed
44 45 46
  commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH,
  commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH,
  commitToNewBranchMR: consts.COMMIT_TO_NEW_BRANCH_MR,
47
  currentBranchPermissionsTooltip: __(
Phil Hughes's avatar
Phil Hughes committed
48
    "This option is disabled as you don't have write permissions for the current branch",
49
  ),
Phil Hughes's avatar
Phil Hughes committed
50
};
Phil Hughes's avatar
Phil Hughes committed
51 52 53 54 55 56
</script>

<template>
  <div class="append-bottom-15 ide-commit-radios">
    <radio-group
      :value="$options.commitToCurrentBranch"
57
      :disabled="currentBranch && !currentBranch.can_push"
58
      :title="$options.currentBranchPermissionsTooltip"
Phil Hughes's avatar
Phil Hughes committed
59 60
    >
      <span
61
        class="ide-radio-label"
Phil Hughes's avatar
Phil Hughes committed
62
        v-html="commitToCurrentBranchText"
Phil Hughes's avatar
Phil Hughes committed
63 64 65 66 67 68 69 70 71
      >
      </span>
    </radio-group>
    <radio-group
      :value="$options.commitToNewBranch"
      :label="__('Create a new branch')"
      :show-input="true"
    />
    <radio-group
72
      v-if="currentProject.merge_requests_enabled"
Phil Hughes's avatar
Phil Hughes committed
73 74
      :value="$options.commitToNewBranchMR"
      :label="__('Create a new branch and merge request')"
75
      :title="__('This option is disabled while you still have unstaged changes')"
Phil Hughes's avatar
Phil Hughes committed
76
      :show-input="true"
Phil Hughes's avatar
Phil Hughes committed
77
      :disabled="disableMergeRequestRadio"
Phil Hughes's avatar
Phil Hughes committed
78 79 80
    />
  </div>
</template>