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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
3.3 KiB
Vue
Raw Normal View History

2017-09-10 17:25:29 +05:30
<script>
2022-01-26 12:08:38 +05:30
import { GlButton, GlModalDirective } from '@gitlab/ui';
2021-09-04 01:27:46 +05:30
import { uniqueId } from 'lodash';
2018-12-13 13:39:08 +05:30
import { __, sprintf } from '~/locale';
2022-01-26 12:08:38 +05:30
import Tracking from '~/tracking';
2018-12-13 13:39:08 +05:30
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';
2022-01-26 12:08:38 +05:30
import DeleteIssueModal from './delete_issue_modal.vue';
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
2022-01-26 12:08:38 +05:30
const trackingMixin = Tracking.mixin({ label: 'delete_issue' });
2018-12-13 13:39:08 +05:30
export default {
2020-11-24 15:15:51 +05:30
components: {
2022-01-26 12:08:38 +05:30
DeleteIssueModal,
2020-11-24 15:15:51 +05:30
GlButton,
2021-09-04 01:27:46 +05:30
},
directives: {
GlModal: GlModalDirective,
2020-11-24 15:15:51 +05:30
},
2022-01-26 12:08:38 +05:30
mixins: [trackingMixin, updateMixin],
2018-12-13 13:39:08 +05:30
props: {
canDestroy: {
type: Boolean,
required: true,
2017-09-10 17:25:29 +05:30
},
2022-01-26 12:08:38 +05:30
endpoint: {
required: true,
type: String,
},
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(),
});
},
2018-12-13 13:39:08 +05:30
isSubmitEnabled() {
return this.formState.title.trim() !== '';
},
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;
2022-01-26 12:08:38 +05:30
eventHub.$emit('delete.issuable');
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"
2022-01-26 12:08:38 +05:30
@click="track('click_button')"
2021-09-04 01:27:46 +05:30
>
{{ deleteIssuableButtonText }}
</gl-button>
2022-01-26 12:08:38 +05:30
<delete-issue-modal
:issue-path="endpoint"
:issue-type="typeToShow"
2021-09-04 01:27:46 +05:30
:modal-id="modalId"
2022-01-26 12:08:38 +05:30
:title="deleteIssuableButtonText"
@delete="deleteIssuable"
/>
2021-09-04 01:27:46 +05:30
</div>
2017-09-10 17:25:29 +05:30
</div>
</template>