Skip to content
代码片段 群组 项目
未验证 提交 d3b85275 编辑于 作者: Kushal Pandya's avatar Kushal Pandya 提交者: GitLab
浏览文件

Merge branch '407493-ce-requirements' into 'master'

Add rich text editor in requirements

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/143778



Merged-by: default avatarKushal Pandya <kushal@gitlab.com>
Approved-by: default avatarKushal Pandya <kushal@gitlab.com>
Co-authored-by: default avatarHimanshu Kapoor <hkapoor@gitlab.com>
No related branches found
No related tags found
无相关合并请求
<script> <script>
import { GlForm, GlFormGroup, GlFormInput } from '@gitlab/ui'; import { GlForm, GlFormGroup, GlFormInput } from '@gitlab/ui';
import { __ } from '~/locale';
import Autosave from '~/autosave'; import Autosave from '~/autosave';
import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import MarkdownEditor from '~/vue_shared/components/markdown/markdown_editor.vue';
import markdownEditorEventHub from '~/vue_shared/components/markdown/eventhub';
import { CLEAR_AUTOSAVE_ENTRY_EVENT } from '~/vue_shared/constants';
import ZenMode from '~/zen_mode'; import ZenMode from '~/zen_mode';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
export default { export default {
...@@ -12,7 +13,7 @@ export default { ...@@ -12,7 +13,7 @@ export default {
GlForm, GlForm,
GlFormGroup, GlFormGroup,
GlFormInput, GlFormInput,
MarkdownField, MarkdownEditor,
}, },
props: { props: {
issuable: { issuable: {
...@@ -48,8 +49,22 @@ export default { ...@@ -48,8 +49,22 @@ export default {
return { return {
title: '', title: '',
description: '', description: '',
formFieldProps: {
id: 'issuable-description',
name: 'issuable-description',
'aria-label': __('Description'),
placeholder: __('Write a comment or drag your files here…'),
class: 'note-textarea js-gfm-input js-autosize markdown-area',
},
}; };
}, },
computed: {
descriptionAutosaveKey() {
if (this.enableAutosave)
return [document.location.pathname, document.location.search, 'description'].join('/');
return '';
},
},
watch: { watch: {
issuable: { issuable: {
handler(value) { handler(value) {
...@@ -76,25 +91,20 @@ export default { ...@@ -76,25 +91,20 @@ export default {
}, },
methods: { methods: {
initAutosave() { initAutosave() {
const { titleInput, descriptionInput } = this.$refs; const { titleInput } = this.$refs;
if (!titleInput || !descriptionInput) return; if (!titleInput) return;
this.autosaveTitle = new Autosave(titleInput.$el, [ this.autosaveTitle = new Autosave(titleInput.$el, [
document.location.pathname, document.location.pathname,
document.location.search, document.location.search,
'title', 'title',
]); ]);
this.autosaveDescription = new Autosave(descriptionInput, [
document.location.pathname,
document.location.search,
'description',
]);
}, },
resetAutosave() { resetAutosave() {
this.autosaveTitle.reset(); this.autosaveTitle.reset();
this.autosaveDescription.reset();
markdownEditorEventHub.$emit(CLEAR_AUTOSAVE_ENTRY_EVENT, this.descriptionAutosaveKey);
}, },
handleKeydown(e, inputType) { handleKeydown(e, inputType) {
this.$emit(`keydown-${inputType}`, e, { this.$emit(`keydown-${inputType}`, e, {
...@@ -132,26 +142,15 @@ export default { ...@@ -132,26 +142,15 @@ export default {
label-for="issuable-description" label-for="issuable-description"
class="col-12 gl-px-0 common-note-form" class="col-12 gl-px-0 common-note-form"
> >
<markdown-field <markdown-editor
:markdown-preview-path="descriptionPreviewPath" v-model="description"
:render-markdown-path="descriptionPreviewPath"
:markdown-docs-path="descriptionHelpPath" :markdown-docs-path="descriptionHelpPath"
:enable-autocomplete="enableAutocomplete" :enable-autocomplete="enableAutocomplete"
:textarea-value="description" :supports-quick-actions="enableAutocomplete"
> :form-field-props="formFieldProps"
<template #textarea> @keydown="handleKeydown($event, 'description')"
<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…')"
class="note-textarea js-gfm-input js-autosize markdown-area"
dir="auto"
@keydown="handleKeydown($event, 'description')"
></textarea>
</template>
</markdown-field>
</gl-form-group> </gl-form-group>
<div <div
data-testid="actions" data-testid="actions"
......
import { GlFormInput } from '@gitlab/ui'; import { GlFormInput } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue'; import { nextTick } from 'vue';
import IssuableEditForm from '~/vue_shared/issuable/show/components/issuable_edit_form.vue'; import IssuableEditForm from '~/vue_shared/issuable/show/components/issuable_edit_form.vue';
import IssuableEventHub from '~/vue_shared/issuable/show/event_hub'; import IssuableEventHub from '~/vue_shared/issuable/show/event_hub';
import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import MarkdownEditor from '~/vue_shared/components/markdown/markdown_editor.vue';
import MarkdownToolbar from '~/vue_shared/components/markdown/toolbar.vue';
import EditorModeSwitcher from '~/vue_shared/components/markdown/editor_mode_switcher.vue';
import markdownEditorEventHub from '~/vue_shared/components/markdown/eventhub';
import { CLEAR_AUTOSAVE_ENTRY_EVENT } from '~/vue_shared/constants';
import Autosave from '~/autosave'; import Autosave from '~/autosave';
import { mockIssuableShowProps, mockIssuable } from '../mock_data'; import { mockIssuableShowProps, mockIssuable } from '../mock_data';
...@@ -20,7 +24,10 @@ const createComponent = ({ propsData = issuableEditFormProps } = {}) => ...@@ -20,7 +24,10 @@ const createComponent = ({ propsData = issuableEditFormProps } = {}) =>
shallowMount(IssuableEditForm, { shallowMount(IssuableEditForm, {
propsData, propsData,
stubs: { stubs: {
MarkdownEditor,
MarkdownField, MarkdownField,
MarkdownToolbar,
EditorModeSwitcher,
}, },
slots: { slots: {
'edit-form-actions': ` 'edit-form-actions': `
...@@ -109,17 +116,18 @@ describe('IssuableEditForm', () => { ...@@ -109,17 +116,18 @@ describe('IssuableEditForm', () => {
describe('methods', () => { describe('methods', () => {
describe('initAutosave', () => { describe('initAutosave', () => {
it('initializes autosave', () => { it('initializes autosave', () => {
expect(Autosave.mock.calls).toEqual([ expect(Autosave.mock.calls).toEqual([[expect.any(Element), ['/', '', 'title']]]);
[expect.any(Element), ['/', '', 'title']],
[expect.any(Element), ['/', '', 'description']],
]);
}); });
}); });
describe('resetAutosave', () => { describe('resetAutosave', () => {
it('resets title and description on "update.issuable event"', () => { it('resets title on "update.issuable event"', () => {
const clearDescriptionAutosaveSpy = jest.fn();
markdownEditorEventHub.$on(CLEAR_AUTOSAVE_ENTRY_EVENT, clearDescriptionAutosaveSpy);
IssuableEventHub.$emit('update.issuable'); IssuableEventHub.$emit('update.issuable');
expect(Autosave.prototype.reset.mock.calls).toEqual([[], []]); expect(Autosave.prototype.reset).toHaveBeenCalled();
expect(clearDescriptionAutosaveSpy).toHaveBeenCalled();
}); });
}); });
}); });
...@@ -152,6 +160,12 @@ describe('IssuableEditForm', () => { ...@@ -152,6 +160,12 @@ describe('IssuableEditForm', () => {
}); });
}); });
it('allows switching to rich text editor', () => {
const descriptionEl = wrapper.find('[data-testid="description"]');
expect(descriptionEl.text()).toContain('Switch to rich text editing');
});
it('renders form actions', () => { it('renders form actions', () => {
const actionsEl = wrapper.find('[data-testid="actions"]'); const actionsEl = wrapper.find('[data-testid="actions"]');
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册