debian-mirror-gitlab/app/assets/javascripts/issue_show/components/edit_actions.vue

157 lines
3.8 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2021-09-04 01:27:46 +05:30
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
import { uniqueId } from 'lodash';
2018-12-13 13:39:08 +05:30
import { __, sprintf } from '~/locale';
import eventHub from '../event_hub';
2021-03-11 19:13:27 +05:30
import updateMixin from '../mixins/update';
2021-09-04 01:27:46 +05:30
import getIssueStateQuery from '../queries/get_issue_state.query.graphql';
2017-09-10 17:25:29 +05:30
2018-12-13 13:39:08 +05:30
const issuableTypes = {
issue: __('Issue'),
epic: __('Epic'),
2021-09-04 01:27:46 +05:30
incident: __('Incident'),
2018-12-13 13:39:08 +05:30
};
2018-12-05 23:21:45 +05:30
2018-12-13 13:39:08 +05:30
export default {
2020-11-24 15:15:51 +05:30
components: {
GlButton,
2021-09-04 01:27:46 +05:30
GlModal,
},
directives: {
GlModal: GlModalDirective,
2020-11-24 15:15:51 +05:30
},
2018-12-13 13:39:08 +05:30
mixins: [updateMixin],
props: {
canDestroy: {
type: Boolean,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
formState: {
type: Object,
required: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
showDeleteButton: {
type: Boolean,
required: false,
default: true,
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
issuableType: {
type: String,
required: true,
},
},
data() {
return {
deleteLoading: false,
2021-09-04 01:27:46 +05:30
skipApollo: false,
issueState: {},
modalId: uniqueId('delete-issuable-modal-'),
2018-12-13 13:39:08 +05:30
};
},
2021-09-04 01:27:46 +05:30
apollo: {
issueState: {
query: getIssueStateQuery,
skip() {
return this.skipApollo;
},
result() {
this.skipApollo = true;
},
},
},
2018-12-13 13:39:08 +05:30
computed: {
2021-09-04 01:27:46 +05:30
deleteIssuableButtonText() {
return sprintf(__('Delete %{issuableType}'), {
issuableType: this.typeToShow.toLowerCase(),
});
},
deleteIssuableModalText() {
return this.issuableType === 'epic'
? __('Delete this epic and all descendants?')
: sprintf(__('%{issuableType} will be removed! Are you sure?'), {
issuableType: this.typeToShow,
});
},
2018-12-13 13:39:08 +05:30
isSubmitEnabled() {
return this.formState.title.trim() !== '';
},
2021-09-04 01:27:46 +05:30
modalActionProps() {
return {
primary: {
text: this.deleteIssuableButtonText,
attributes: [{ variant: 'danger' }, { loading: this.deleteLoading }],
},
cancel: {
text: __('Cancel'),
},
};
},
2018-12-13 13:39:08 +05:30
shouldShowDeleteButton() {
return this.canDestroy && this.showDeleteButton;
},
2021-09-04 01:27:46 +05:30
typeToShow() {
const { issueState, issuableType } = this;
const type = issueState.issueType ?? issuableType;
return issuableTypes[type];
2021-04-17 20:07:23 +05:30
},
2018-12-13 13:39:08 +05:30
},
methods: {
closeForm() {
eventHub.$emit('close.form');
},
deleteIssuable() {
2021-09-04 01:27:46 +05:30
this.deleteLoading = true;
eventHub.$emit('delete.issuable', { destroy_confirm: true });
2017-09-10 17:25:29 +05:30
},
2018-12-13 13:39:08 +05:30
},
};
2017-09-10 17:25:29 +05:30
</script>
<template>
2021-09-04 01:27:46 +05:30
<div class="gl-mt-3 gl-mb-3 gl-display-flex gl-justify-content-space-between">
<div>
<gl-button
:loading="formState.updateLoading"
:disabled="formState.updateLoading || !isSubmitEnabled"
category="primary"
variant="confirm"
class="qa-save-button gl-mr-3"
data-testid="issuable-save-button"
type="submit"
@click.prevent="updateIssuable"
>
{{ __('Save changes') }}
</gl-button>
<gl-button data-testid="issuable-cancel-button" @click="closeForm">
{{ __('Cancel') }}
</gl-button>
</div>
<div v-if="shouldShowDeleteButton">
<gl-button
v-gl-modal="modalId"
:loading="deleteLoading"
:disabled="deleteLoading"
category="secondary"
variant="danger"
class="qa-delete-button"
data-testid="issuable-delete-button"
>
{{ deleteIssuableButtonText }}
</gl-button>
<gl-modal
ref="removeModal"
:modal-id="modalId"
size="sm"
:action-primary="modalActionProps.primary"
:action-cancel="modalActionProps.cancel"
@primary="deleteIssuable"
>
<template #modal-title>{{ deleteIssuableButtonText }}</template>
<div>
<p class="gl-mb-1">{{ deleteIssuableModalText }}</p>
</div>
</gl-modal>
</div>
2017-09-10 17:25:29 +05:30
</div>
</template>