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

183 lines
5.4 KiB
Vue
Raw Normal View History

2018-10-15 14:42:47 +05:30
<script>
import { mapState, mapActions, mapGetters } from 'vuex';
2020-04-08 14:13:33 +05:30
import { n__, __ } from '~/locale';
2020-05-24 23:13:21 +05:30
import { GlModal } from '@gitlab/ui';
2018-10-15 14:42:47 +05:30
import LoadingButton from '~/vue_shared/components/loading_button.vue';
import CommitMessageField from './message_field.vue';
import Actions from './actions.vue';
import SuccessMessage from './success_message.vue';
2020-03-13 15:44:24 +05:30
import { leftSidebarViews, MAX_WINDOW_HEIGHT_COMPACT } from '../../constants';
2020-05-24 23:13:21 +05:30
import consts from '../../stores/modules/commit/constants';
2018-10-15 14:42:47 +05:30
export default {
components: {
Actions,
LoadingButton,
CommitMessageField,
SuccessMessage,
2020-05-24 23:13:21 +05:30
GlModal,
2018-10-15 14:42:47 +05:30
},
data() {
return {
isCompact: true,
componentHeight: null,
};
},
computed: {
...mapState(['changedFiles', 'stagedFiles', 'currentActivityView', 'lastCommitMsg']),
...mapState('commit', ['commitMessage', 'submitCommitLoading']),
2020-06-23 00:09:42 +05:30
...mapGetters(['someUncommittedChanges']),
2018-11-08 19:23:39 +05:30
...mapGetters('commit', ['discardDraftButtonDisabled', 'preBuiltCommitMessage']),
2018-10-15 14:42:47 +05:30
overviewText() {
2020-04-08 14:13:33 +05:30
return n__('%d changed file', '%d changed files', this.stagedFiles.length);
2018-10-15 14:42:47 +05:30
},
2018-11-08 19:23:39 +05:30
commitButtonText() {
return this.stagedFiles.length ? __('Commit') : __('Stage & Commit');
},
2020-03-13 15:44:24 +05:30
currentViewIsCommitView() {
return this.currentActivityView === leftSidebarViews.commit.name;
},
2018-10-15 14:42:47 +05:30
},
watch: {
2020-06-23 00:09:42 +05:30
currentActivityView: 'handleCompactState',
someUncommittedChanges: 'handleCompactState',
lastCommitMsg: 'handleCompactState',
2018-10-15 14:42:47 +05:30
},
methods: {
...mapActions(['updateActivityBarView']),
2020-05-24 23:13:21 +05:30
...mapActions('commit', [
'updateCommitMessage',
'discardDraft',
'commitChanges',
'updateCommitAction',
]),
commit() {
return this.commitChanges().catch(() => {
this.$refs.createBranchModal.show();
});
},
forceCreateNewBranch() {
return this.updateCommitAction(consts.COMMIT_TO_NEW_BRANCH).then(() => this.commit());
},
2020-06-23 00:09:42 +05:30
handleCompactState() {
if (this.lastCommitMsg) {
this.isCompact = false;
2020-03-13 15:44:24 +05:30
} else {
2020-06-23 00:09:42 +05:30
this.isCompact =
!this.someUncommittedChanges ||
!this.currentViewIsCommitView ||
window.innerHeight < MAX_WINDOW_HEIGHT_COMPACT;
2020-03-13 15:44:24 +05:30
}
2018-10-15 14:42:47 +05:30
},
2020-06-23 00:09:42 +05:30
toggleIsCompact() {
this.isCompact = !this.isCompact;
},
beginCommit() {
return this.updateActivityBarView(leftSidebarViews.commit.name).then(() => {
this.isCompact = false;
});
},
2018-10-15 14:42:47 +05:30
beforeEnterTransition() {
const elHeight = this.isCompact
? this.$refs.formEl && this.$refs.formEl.offsetHeight
: this.$refs.compactEl && this.$refs.compactEl.offsetHeight;
2018-11-08 19:23:39 +05:30
this.componentHeight = elHeight;
2018-10-15 14:42:47 +05:30
},
enterTransition() {
this.$nextTick(() => {
const elHeight = this.isCompact
? this.$refs.compactEl && this.$refs.compactEl.offsetHeight
: this.$refs.formEl && this.$refs.formEl.offsetHeight;
2018-11-08 19:23:39 +05:30
this.componentHeight = elHeight;
2018-10-15 14:42:47 +05:30
});
},
afterEndTransition() {
this.componentHeight = null;
},
},
};
</script>
<template>
<div
:class="{
'is-compact': isCompact,
2019-02-15 15:39:39 +05:30
'is-full': !isCompact,
2018-10-15 14:42:47 +05:30
}"
:style="{
height: componentHeight ? `${componentHeight}px` : null,
}"
2018-11-08 19:23:39 +05:30
class="multi-file-commit-form"
2018-10-15 14:42:47 +05:30
>
<transition
name="commit-form-slide-up"
@before-enter="beforeEnterTransition"
@enter="enterTransition"
@after-enter="afterEndTransition"
>
2019-02-15 15:39:39 +05:30
<div v-if="isCompact" ref="compactEl" class="commit-form-compact">
2018-10-15 14:42:47 +05:30
<button
2020-06-23 00:09:42 +05:30
:disabled="!someUncommittedChanges"
2018-11-08 19:23:39 +05:30
type="button"
2018-12-13 13:39:08 +05:30
class="btn btn-primary btn-sm btn-block qa-begin-commit-button"
2020-06-23 00:09:42 +05:30
data-testid="begin-commit-button"
@click="beginCommit"
2018-10-15 14:42:47 +05:30
>
2018-11-08 19:23:39 +05:30
{{ __('Commit…') }}
2018-10-15 14:42:47 +05:30
</button>
2020-04-08 14:13:33 +05:30
<p class="text-center bold">{{ overviewText }}</p>
2018-10-15 14:42:47 +05:30
</div>
2020-06-23 00:09:42 +05:30
<form v-else ref="formEl" @submit.prevent.stop="commit">
2019-02-15 15:39:39 +05:30
<transition name="fade"> <success-message v-show="lastCommitMsg" /> </transition>
2018-10-15 14:42:47 +05:30
<commit-message-field
:text="commitMessage"
2018-11-08 19:23:39 +05:30
:placeholder="preBuiltCommitMessage"
2018-10-15 14:42:47 +05:30
@input="updateCommitMessage"
2020-05-24 23:13:21 +05:30
@submit="commit"
2018-10-15 14:42:47 +05:30
/>
<div class="clearfix prepend-top-15">
<actions />
<loading-button
:loading="submitCommitLoading"
2018-11-08 19:23:39 +05:30
:label="commitButtonText"
2018-12-13 13:39:08 +05:30
container-class="btn btn-success btn-sm float-left qa-commit-button"
2020-05-24 23:13:21 +05:30
@click="commit"
2018-10-15 14:42:47 +05:30
/>
<button
v-if="!discardDraftButtonDisabled"
type="button"
2018-11-08 19:23:39 +05:30
class="btn btn-default btn-sm float-right"
2018-10-15 14:42:47 +05:30
@click="discardDraft"
>
{{ __('Discard draft') }}
</button>
<button
v-else
type="button"
2018-11-08 19:23:39 +05:30
class="btn btn-default btn-sm float-right"
2020-03-13 15:44:24 +05:30
@click="toggleIsCompact"
2018-10-15 14:42:47 +05:30
>
{{ __('Collapse') }}
</button>
</div>
2020-05-24 23:13:21 +05:30
<gl-modal
ref="createBranchModal"
modal-id="ide-create-branch-modal"
:ok-title="__('Create new branch')"
:title="__('Branch has changed')"
ok-variant="success"
@ok="forceCreateNewBranch"
>
{{
__(`This branch has changed since you started editing.
Would you like to create a new branch?`)
}}
</gl-modal>
2018-10-15 14:42:47 +05:30
</form>
</transition>
</div>
</template>