Commit 49b8c8ad authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '215120-edit-markdown-via-wysiwyg-editor' into 'master'

Replace edit area with rich content editor

See merge request gitlab-org/gitlab!30985
parents 28c685ce 2e9f3163
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { GlSkeletonLoader } from '@gitlab/ui'; import { GlSkeletonLoader } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import RichContentEditor from '~/vue_shared/components/rich_content_editor/rich_content_editor.vue';
import EditArea from '../components/edit_area.vue'; import EditArea from '../components/edit_area.vue';
import EditHeader from '../components/edit_header.vue'; import EditHeader from '../components/edit_header.vue';
import SavedChangesMessage from '../components/saved_changes_message.vue'; import SavedChangesMessage from '../components/saved_changes_message.vue';
...@@ -11,6 +13,7 @@ import SubmitChangesError from '../components/submit_changes_error.vue'; ...@@ -11,6 +13,7 @@ import SubmitChangesError from '../components/submit_changes_error.vue';
export default { export default {
components: { components: {
RichContentEditor,
EditArea, EditArea,
EditHeader, EditHeader,
InvalidContentMessage, InvalidContentMessage,
...@@ -19,6 +22,7 @@ export default { ...@@ -19,6 +22,7 @@ export default {
PublishToolbar, PublishToolbar,
SubmitChangesError, SubmitChangesError,
}, },
mixins: [glFeatureFlagsMixin()],
computed: { computed: {
...mapState([ ...mapState([
'content', 'content',
...@@ -76,7 +80,14 @@ export default { ...@@ -76,7 +80,14 @@ export default {
@dismiss="dismissSubmitChangesError" @dismiss="dismissSubmitChangesError"
/> />
<edit-header class="w-75 align-self-center py-2" :title="title" /> <edit-header class="w-75 align-self-center py-2" :title="title" />
<rich-content-editor
v-if="glFeatures.richContentEditor"
class="w-75 gl-align-self-center"
:value="content"
@input="setContent"
/>
<edit-area <edit-area
v-else
class="w-75 h-100 shadow-none align-self-center" class="w-75 h-100 shadow-none align-self-center"
:value="content" :value="content"
@input="setContent" @input="setContent"
......
...@@ -23,3 +23,5 @@ export const EDITOR_OPTIONS = { ...@@ -23,3 +23,5 @@ export const EDITOR_OPTIONS = {
export const EDITOR_TYPES = { export const EDITOR_TYPES = {
wysiwyg: 'wysiwyg', wysiwyg: 'wysiwyg',
}; };
export const EDITOR_HEIGHT = '100%';
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import 'codemirror/lib/codemirror.css'; import 'codemirror/lib/codemirror.css';
import '@toast-ui/editor/dist/toastui-editor.css'; import '@toast-ui/editor/dist/toastui-editor.css';
import { EDITOR_OPTIONS, EDITOR_TYPES } from './constants'; import { EDITOR_OPTIONS, EDITOR_TYPES, EDITOR_HEIGHT } from './constants';
export default { export default {
components: { components: {
...@@ -16,6 +16,26 @@ export default { ...@@ -16,6 +16,26 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
options: {
type: Object,
required: false,
default: () => EDITOR_OPTIONS,
},
initialEditType: {
type: String,
required: false,
default: EDITOR_TYPES.wysiwyg,
},
height: {
type: String,
required: false,
default: EDITOR_HEIGHT,
},
},
computed: {
editorOptions() {
return { ...EDITOR_OPTIONS, ...this.options };
},
}, },
methods: { methods: {
onContentChanged() { onContentChanged() {
...@@ -25,16 +45,15 @@ export default { ...@@ -25,16 +45,15 @@ export default {
return this.$refs.editor.invoke('getMarkdown'); return this.$refs.editor.invoke('getMarkdown');
}, },
}, },
editorOptions: EDITOR_OPTIONS,
initialEditType: EDITOR_TYPES.wysiwyg,
}; };
</script> </script>
<template> <template>
<toast-editor <toast-editor
ref="editor" ref="editor"
:initial-edit-type="$options.initialEditType"
:initial-value="value" :initial-value="value"
:options="$options.editorOptions" :options="editorOptions"
:initial-edit-type="initialEditType"
:height="height"
@change="onContentChanged" @change="onContentChanged"
/> />
</template> </template>
...@@ -10,6 +10,10 @@ class Projects::StaticSiteEditorController < Projects::ApplicationController ...@@ -10,6 +10,10 @@ class Projects::StaticSiteEditorController < Projects::ApplicationController
before_action :assign_ref_and_path, only: [:show] before_action :assign_ref_and_path, only: [:show]
before_action :authorize_edit_tree!, only: [:show] before_action :authorize_edit_tree!, only: [:show]
before_action do
push_frontend_feature_flag(:rich_content_editor)
end
def show def show
@config = Gitlab::StaticSiteEditor::Config.new(@repository, @ref, @path, params[:return_url]) @config = Gitlab::StaticSiteEditor::Config.new(@repository, @ref, @path, params[:return_url])
end end
......
...@@ -10,6 +10,9 @@ export const Editor = { ...@@ -10,6 +10,9 @@ export const Editor = {
initialEditType: { initialEditType: {
type: String, type: String,
}, },
height: {
type: String,
},
}, },
render(h) { render(h) {
return h('div'); return h('div');
......
...@@ -5,7 +5,7 @@ import { GlSkeletonLoader } from '@gitlab/ui'; ...@@ -5,7 +5,7 @@ import { GlSkeletonLoader } from '@gitlab/ui';
import createState from '~/static_site_editor/store/state'; import createState from '~/static_site_editor/store/state';
import Home from '~/static_site_editor/pages/home.vue'; import Home from '~/static_site_editor/pages/home.vue';
import EditArea from '~/static_site_editor/components/edit_area.vue'; import RichContentEditor from '~/vue_shared/components/rich_content_editor/rich_content_editor.vue';
import EditHeader from '~/static_site_editor/components/edit_header.vue'; import EditHeader from '~/static_site_editor/components/edit_header.vue';
import InvalidContentMessage from '~/static_site_editor/components/invalid_content_message.vue'; import InvalidContentMessage from '~/static_site_editor/components/invalid_content_message.vue';
import PublishToolbar from '~/static_site_editor/components/publish_toolbar.vue'; import PublishToolbar from '~/static_site_editor/components/publish_toolbar.vue';
...@@ -71,10 +71,13 @@ describe('static_site_editor/pages/home', () => { ...@@ -71,10 +71,13 @@ describe('static_site_editor/pages/home', () => {
wrapper = shallowMount(Home, { wrapper = shallowMount(Home, {
localVue, localVue,
store, store,
provide: {
glFeatures: { richContentEditor: true },
},
}); });
}; };
const findEditArea = () => wrapper.find(EditArea); const findRichContentEditor = () => wrapper.find(RichContentEditor);
const findEditHeader = () => wrapper.find(EditHeader); const findEditHeader = () => wrapper.find(EditHeader);
const findInvalidContentMessage = () => wrapper.find(InvalidContentMessage); const findInvalidContentMessage = () => wrapper.find(InvalidContentMessage);
const findPublishToolbar = () => wrapper.find(PublishToolbar); const findPublishToolbar = () => wrapper.find(PublishToolbar);
...@@ -103,8 +106,8 @@ describe('static_site_editor/pages/home', () => { ...@@ -103,8 +106,8 @@ describe('static_site_editor/pages/home', () => {
}); });
describe('when content is not loaded', () => { describe('when content is not loaded', () => {
it('does not render edit area', () => { it('does not render rich content editor', () => {
expect(findEditArea().exists()).toBe(false); expect(findRichContentEditor().exists()).toBe(false);
}); });
it('does not render edit header', () => { it('does not render edit header', () => {
...@@ -129,8 +132,8 @@ describe('static_site_editor/pages/home', () => { ...@@ -129,8 +132,8 @@ describe('static_site_editor/pages/home', () => {
buildWrapper(); buildWrapper();
}); });
it('renders the edit area', () => { it('renders the rich content editor', () => {
expect(findEditArea().exists()).toBe(true); expect(findRichContentEditor().exists()).toBe(true);
}); });
it('renders the edit header', () => { it('renders the edit header', () => {
...@@ -141,8 +144,8 @@ describe('static_site_editor/pages/home', () => { ...@@ -141,8 +144,8 @@ describe('static_site_editor/pages/home', () => {
expect(findSkeletonLoader().exists()).toBe(false); expect(findSkeletonLoader().exists()).toBe(false);
}); });
it('passes page content to edit area', () => { it('passes page content to the rich content editor', () => {
expect(findEditArea().props('value')).toBe(content); expect(findRichContentEditor().props('value')).toBe(content);
}); });
it('passes page title to edit header', () => { it('passes page title to edit header', () => {
...@@ -228,11 +231,11 @@ describe('static_site_editor/pages/home', () => { ...@@ -228,11 +231,11 @@ describe('static_site_editor/pages/home', () => {
expect(loadContentActionMock).toHaveBeenCalled(); expect(loadContentActionMock).toHaveBeenCalled();
}); });
it('dispatches setContent action when edit area emits input event', () => { it('dispatches setContent action when rich content editor emits input event', () => {
buildContentLoadedStore(); buildContentLoadedStore();
buildWrapper(); buildWrapper();
findEditArea().vm.$emit('input', sourceContent); findRichContentEditor().vm.$emit('input', sourceContent);
expect(setContentActionMock).toHaveBeenCalledWith(expect.anything(), sourceContent, undefined); expect(setContentActionMock).toHaveBeenCalledWith(expect.anything(), sourceContent, undefined);
}); });
......
...@@ -50,6 +50,10 @@ describe('Rich Content Editor', () => { ...@@ -50,6 +50,10 @@ describe('Rich Content Editor', () => {
it('has the correct initial edit type', () => { it('has the correct initial edit type', () => {
expect(findEditor().props().initialEditType).toBe('wysiwyg'); expect(findEditor().props().initialEditType).toBe('wysiwyg');
}); });
it('has the correct height', () => {
expect(findEditor().props().height).toBe('100%');
});
}); });
describe('when content is changed', () => { describe('when content is changed', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment