2021-01-03 14:25:43 +05:30
|
|
|
<script>
|
|
|
|
import { GlForm, GlFormGroup, GlFormInput } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import $ from 'jquery';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
import Autosave from '~/autosave';
|
|
|
|
import MarkdownField from '~/vue_shared/components/markdown/field.vue';
|
2021-04-29 21:17:54 +05:30
|
|
|
import ZenMode from '~/zen_mode';
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
import eventHub from '../event_hub';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
GlForm,
|
|
|
|
GlFormGroup,
|
|
|
|
GlFormInput,
|
|
|
|
MarkdownField,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
issuable: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
enableAutocomplete: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
enableAutosave: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-04-29 21:17:54 +05:30
|
|
|
enableZenMode: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
showFieldTitle: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
descriptionPreviewPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
descriptionHelpPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2021-02-22 17:27:13 +05:30
|
|
|
title: '',
|
|
|
|
description: '',
|
2021-01-03 14:25:43 +05:30
|
|
|
};
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
watch: {
|
|
|
|
issuable: {
|
|
|
|
handler(value) {
|
|
|
|
this.title = value?.title || '';
|
|
|
|
this.description = value?.description || '';
|
|
|
|
},
|
|
|
|
deep: true,
|
|
|
|
immediate: true,
|
|
|
|
},
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
created() {
|
|
|
|
eventHub.$on('update.issuable', this.resetAutosave);
|
|
|
|
eventHub.$on('close.form', this.resetAutosave);
|
|
|
|
},
|
|
|
|
mounted() {
|
2021-02-22 17:27:13 +05:30
|
|
|
if (this.enableAutosave) this.initAutosave();
|
2021-04-29 21:17:54 +05:30
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
if (this.enableZenMode) new ZenMode();
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('update.issuable', this.resetAutosave);
|
|
|
|
eventHub.$off('close.form', this.resetAutosave);
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
initAutosave() {
|
|
|
|
const { titleInput, descriptionInput } = this.$refs;
|
|
|
|
|
|
|
|
if (!titleInput || !descriptionInput) return;
|
|
|
|
|
|
|
|
this.autosaveTitle = new Autosave($(titleInput.$el), [
|
|
|
|
document.location.pathname,
|
|
|
|
document.location.search,
|
|
|
|
'title',
|
|
|
|
]);
|
|
|
|
|
|
|
|
this.autosaveDescription = new Autosave($(descriptionInput.$el), [
|
|
|
|
document.location.pathname,
|
|
|
|
document.location.search,
|
|
|
|
'description',
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
resetAutosave() {
|
|
|
|
this.autosaveTitle.reset();
|
|
|
|
this.autosaveDescription.reset();
|
|
|
|
},
|
2021-02-22 17:27:13 +05:30
|
|
|
handleKeydown(e, inputType) {
|
|
|
|
this.$emit(`keydown-${inputType}`, e, {
|
|
|
|
issuableTitle: this.title,
|
|
|
|
issuableDescription: this.description,
|
|
|
|
});
|
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<gl-form>
|
|
|
|
<gl-form-group
|
|
|
|
data-testid="title"
|
|
|
|
:label="__('Title')"
|
2021-02-22 17:27:13 +05:30
|
|
|
:label-sr-only="!showFieldTitle"
|
2021-01-03 14:25:43 +05:30
|
|
|
label-for="issuable-title"
|
2021-02-22 17:27:13 +05:30
|
|
|
class="col-12 gl-px-0"
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
<gl-form-input
|
|
|
|
id="issuable-title"
|
|
|
|
ref="titleInput"
|
|
|
|
v-model.trim="title"
|
|
|
|
:placeholder="__('Title')"
|
|
|
|
:aria-label="__('Title')"
|
|
|
|
:autofocus="true"
|
|
|
|
class="qa-title-input"
|
2021-02-22 17:27:13 +05:30
|
|
|
@keydown="handleKeydown($event, 'title')"
|
2021-01-03 14:25:43 +05:30
|
|
|
/>
|
|
|
|
</gl-form-group>
|
|
|
|
<gl-form-group
|
|
|
|
data-testid="description"
|
|
|
|
:label="__('Description')"
|
2021-02-22 17:27:13 +05:30
|
|
|
:label-sr-only="!showFieldTitle"
|
2021-01-03 14:25:43 +05:30
|
|
|
label-for="issuable-description"
|
2021-02-22 17:27:13 +05:30
|
|
|
label-class="gl-pb-0!"
|
|
|
|
class="col-12 gl-px-0 common-note-form"
|
2021-01-03 14:25:43 +05:30
|
|
|
>
|
|
|
|
<markdown-field
|
|
|
|
:markdown-preview-path="descriptionPreviewPath"
|
|
|
|
:markdown-docs-path="descriptionHelpPath"
|
|
|
|
:enable-autocomplete="enableAutocomplete"
|
|
|
|
:textarea-value="description"
|
|
|
|
>
|
|
|
|
<template #textarea>
|
|
|
|
<textarea
|
|
|
|
id="issuable-description"
|
|
|
|
ref="descriptionInput"
|
|
|
|
v-model="description"
|
|
|
|
:data-supports-quick-actions="enableAutocomplete"
|
|
|
|
:aria-label="__('Description')"
|
|
|
|
:placeholder="__('Write a comment or drag your files here…')"
|
2021-03-08 18:12:59 +05:30
|
|
|
class="note-textarea js-gfm-input js-autosize markdown-area qa-description-textarea"
|
2021-01-03 14:25:43 +05:30
|
|
|
dir="auto"
|
2021-02-22 17:27:13 +05:30
|
|
|
@keydown="handleKeydown($event, 'description')"
|
2021-01-03 14:25:43 +05:30
|
|
|
></textarea>
|
|
|
|
</template>
|
|
|
|
</markdown-field>
|
|
|
|
</gl-form-group>
|
2021-02-22 17:27:13 +05:30
|
|
|
<div data-testid="actions" class="col-12 gl-mt-3 gl-mb-3 gl-px-0 clearfix">
|
2021-01-03 14:25:43 +05:30
|
|
|
<slot
|
|
|
|
name="edit-form-actions"
|
|
|
|
:issuable-title="title"
|
|
|
|
:issuable-description="description"
|
|
|
|
></slot>
|
|
|
|
</div>
|
|
|
|
</gl-form>
|
|
|
|
</template>
|