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

98 lines
2.7 KiB
Vue
Raw Normal View History

2018-05-09 12:01:36 +05:30
<script>
2021-03-11 19:13:27 +05:30
import { GlSprintf } from '@gitlab/ui';
2020-05-24 23:13:21 +05:30
import { escape } from 'lodash';
2019-09-04 21:01:54 +05:30
import { mapState, mapGetters, createNamespacedHelpers } from 'vuex';
2021-01-03 14:25:43 +05:30
import { s__ } from '~/locale';
2021-03-11 19:13:27 +05:30
import {
COMMIT_TO_CURRENT_BRANCH,
COMMIT_TO_NEW_BRANCH,
} from '../../stores/modules/commit/constants';
2019-09-04 21:01:54 +05:30
import NewMergeRequestOption from './new_merge_request_option.vue';
2021-03-11 19:13:27 +05:30
import RadioGroup from './radio_group.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: {
2021-01-03 14:25:43 +05:30
GlSprintf,
2018-10-15 14:42:47 +05:30
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']),
2021-01-03 14:25:43 +05:30
currentBranchText() {
return escape(this.currentBranchId);
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) {
2021-03-11 19:13:27 +05:30
this.updateCommitAction(COMMIT_TO_CURRENT_BRANCH);
2019-12-04 20:38:33 +05:30
} else {
2021-03-11 19:13:27 +05:30
this.updateCommitAction(COMMIT_TO_NEW_BRANCH);
2018-11-08 19:23:39 +05:30
}
},
2018-10-15 14:42:47 +05:30
},
2021-03-11 19:13:27 +05:30
commitToCurrentBranch: COMMIT_TO_CURRENT_BRANCH,
commitToNewBranch: 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>
2020-07-28 23:09:34 +05:30
<div class="gl-mb-5 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
>
2021-01-03 14:25:43 +05:30
<span class="ide-option-label" data-qa-selector="commit_to_current_branch_radio">
<gl-sprintf :message="s__('IDE|Commit to %{branchName} branch')">
<template #branchName>
<strong class="monospace">{{ currentBranchText }}</strong>
</template>
</gl-sprintf>
</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>