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

95 lines
2.7 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2020-04-22 19:07:51 +05:30
import { escape as esc } from 'lodash';
2019-09-04 21:01:54 +05:30
import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
2020-03-13 15:44:24 +05:30
import { sprintf, s__ } 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']),
2020-04-22 19:07:51 +05:30
...mapGetters(['currentBranch', 'emptyRepo', 'canPushToBranch']),
2018-10-15 14:42:47 +05:30
commitToCurrentBranchText() {
return sprintf(
2020-03-13 15:44:24 +05:30
s__('IDE|Commit to %{branchName} branch'),
2020-04-22 19:07:51 +05:30
{ branchName: `<strong class="monospace">${esc(this.currentBranchId)}</strong>` },
2018-10-15 14:42:47 +05:30
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
},
2020-04-22 19:07:51 +05:30
shouldDefaultToCurrentBranch() {
if (this.emptyRepo) {
return true;
}
return this.canPushToBranch && !this.currentBranch?.default;
},
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() {
2020-04-22 19:07:51 +05:30
if (!this.commitAction) {
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() {
2020-04-22 19:07:51 +05:30
if (!this.currentBranch && !this.emptyRepo) {
2019-12-04 20:38:33 +05:30
return;
}
2020-04-22 19:07:51 +05:30
if (this.shouldDefaultToCurrentBranch) {
2018-11-08 19:23:39 +05:30
this.updateCommitAction(consts.COMMIT_TO_CURRENT_BRANCH);
2019-12-04 20:38:33 +05:30
} else {
this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH);
2018-11-08 19:23:39 +05:30
}
},
2018-10-15 14:42:47 +05:30
},
commitToCurrentBranch: consts.COMMIT_TO_CURRENT_BRANCH,
commitToNewBranch: consts.COMMIT_TO_NEW_BRANCH,
2020-03-13 15:44:24 +05:30
currentBranchPermissionsTooltip: s__(
"IDE|This option is disabled because you don't have write permissions for the current branch.",
2018-11-08 19:23:39 +05:30
),
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"
2020-04-22 19:07:51 +05:30
:disabled="!canPushToBranch"
2018-11-08 19:23:39 +05:30
:title="$options.currentBranchPermissionsTooltip"
2018-05-09 12:01:36 +05:30
>
2019-12-04 20:38:33 +05:30
<span
2020-03-13 15:44:24 +05:30
class="ide-option-label"
2019-12-04 20:38:33 +05:30
data-qa-selector="commit_to_current_branch_radio"
v-html="commitToCurrentBranchText"
></span>
2018-05-09 12:01:36 +05:30
</radio-group>
2020-04-22 19:07:51 +05:30
<template v-if="!emptyRepo">
<radio-group
:value="$options.commitToNewBranch"
:label="__('Create a new branch')"
:show-input="true"
/>
<new-merge-request-option />
</template>
2018-05-09 12:01:36 +05:30
</div>
</template>