Commit e590578e authored by Denys Mishunov's avatar Denys Mishunov Committed by Douglas Barbosa Alexandre

Removed :monaco_snippets in Vue/JS

In the course of making Monaco default for editing Snippets, we remove
te feature flag from the codebase. This commit removes it from Vue/JS
files
parent 15145fc8
/* global ace */
import Editor from '~/editor/editor_lite'; import Editor from '~/editor/editor_lite';
export function initEditorLite({ el, blobPath, blobContent }) { export function initEditorLite({ el, blobPath, blobContent }) {
if (!el) { if (!el) {
throw new Error(`"el" parameter is required to initialize Editor`); throw new Error(`"el" parameter is required to initialize Editor`);
} }
let editor; const editor = new Editor();
editor.createInstance({
if (window?.gon?.features?.monacoSnippets) { el,
editor = new Editor(); blobPath,
editor.createInstance({ blobContent,
el, });
blobPath,
blobContent,
});
} else {
editor = ace.edit(el);
}
return editor; return editor;
} }
......
...@@ -3,18 +3,6 @@ import setupCollapsibleInputs from './collapsible_input'; ...@@ -3,18 +3,6 @@ import setupCollapsibleInputs from './collapsible_input';
let editor; let editor;
const initAce = () => {
const editorEl = document.getElementById('editor');
const form = document.querySelector('.snippet-form-holder form');
const content = document.querySelector('.snippet-file-content');
editor = initEditorLite({ el: editorEl });
form.addEventListener('submit', () => {
content.value = editor.getValue();
});
};
const initMonaco = () => { const initMonaco = () => {
const editorEl = document.getElementById('editor'); const editorEl = document.getElementById('editor');
const contentEl = document.querySelector('.snippet-file-content'); const contentEl = document.querySelector('.snippet-file-content');
...@@ -36,15 +24,7 @@ const initMonaco = () => { ...@@ -36,15 +24,7 @@ const initMonaco = () => {
}); });
}; };
export const initEditor = () => {
if (window?.gon?.features?.monacoSnippets) {
initMonaco();
} else {
initAce();
}
setupCollapsibleInputs();
};
export default () => { export default () => {
initEditor(); initMonaco();
setupCollapsibleInputs();
}; };
- if Feature.disabled?(:monaco_snippets)
- content_for :page_specific_javascripts do
= page_specific_javascript_tag('lib/ace.js')
- if Feature.enabled?(:snippets_edit_vue) - if Feature.enabled?(:snippets_edit_vue)
#js-snippet-edit.snippet-form{ data: {'project_path': @snippet.project&.full_path, 'snippet-gid': @snippet.new_record? ? '' : @snippet.to_global_id, 'markdown-preview-path': preview_markdown_path(parent), 'markdown-docs-path': help_page_path('user/markdown'), 'visibility-help-link': help_page_path("public_access/public_access") } } #js-snippet-edit.snippet-form{ data: {'project_path': @snippet.project&.full_path, 'snippet-gid': @snippet.new_record? ? '' : @snippet.to_global_id, 'markdown-preview-path': preview_markdown_path(parent), 'markdown-docs-path': help_page_path('user/markdown'), 'visibility-help-link': help_page_path("public_access/public_access") } }
- else - else
......
---
title: Enable Monaco for editing Snippets by default
merge_request: 30892
author:
type: added
...@@ -43,7 +43,6 @@ module Gitlab ...@@ -43,7 +43,6 @@ module Gitlab
# Initialize gon.features with any flags that should be # Initialize gon.features with any flags that should be
# made globally available to the frontend # made globally available to the frontend
push_frontend_feature_flag(:snippets_vue, default_enabled: false) push_frontend_feature_flag(:snippets_vue, default_enabled: false)
push_frontend_feature_flag(:monaco_snippets, default_enabled: false)
push_frontend_feature_flag(:monaco_blobs, default_enabled: false) push_frontend_feature_flag(:monaco_blobs, default_enabled: false)
push_frontend_feature_flag(:monaco_ci, default_enabled: false) push_frontend_feature_flag(:monaco_ci, default_enabled: false)
push_frontend_feature_flag(:snippets_edit_vue, default_enabled: false) push_frontend_feature_flag(:snippets_edit_vue, default_enabled: false)
......
...@@ -5,7 +5,6 @@ require 'spec_helper' ...@@ -5,7 +5,6 @@ require 'spec_helper'
shared_examples_for 'snippet editor' do shared_examples_for 'snippet editor' do
before do before do
stub_feature_flags(snippets_edit_vue: false) stub_feature_flags(snippets_edit_vue: false)
stub_feature_flags(monaco_snippets: flag)
end end
def description_field def description_field
...@@ -20,7 +19,7 @@ shared_examples_for 'snippet editor' do ...@@ -20,7 +19,7 @@ shared_examples_for 'snippet editor' do
fill_in 'project_snippet_description', with: 'My Snippet **Description**' fill_in 'project_snippet_description', with: 'My Snippet **Description**'
page.within('.file-editor') do page.within('.file-editor') do
el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) el = find('.inputarea')
el.send_keys 'Hello World!' el.send_keys 'Hello World!'
end end
end end
...@@ -145,15 +144,5 @@ describe 'Projects > Snippets > Create Snippet', :js do ...@@ -145,15 +144,5 @@ describe 'Projects > Snippets > Create Snippet', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public) } let_it_be(:project) { create(:project, :public) }
context 'when using Monaco' do it_behaves_like "snippet editor"
it_behaves_like "snippet editor" do
let(:flag) { true }
end
end
context 'when using ACE' do
it_behaves_like "snippet editor" do
let(:flag) { false }
end
end
end end
...@@ -13,7 +13,6 @@ shared_examples_for 'snippet editor' do ...@@ -13,7 +13,6 @@ shared_examples_for 'snippet editor' do
stub_feature_flags(allow_possible_spam: false) stub_feature_flags(allow_possible_spam: false)
stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_vue: false)
stub_feature_flags(snippets_edit_vue: false) stub_feature_flags(snippets_edit_vue: false)
stub_feature_flags(monaco_snippets: flag)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.update!( Gitlab::CurrentSettings.update!(
...@@ -35,7 +34,7 @@ shared_examples_for 'snippet editor' do ...@@ -35,7 +34,7 @@ shared_examples_for 'snippet editor' do
find('#personal_snippet_visibility_level_20').set(true) find('#personal_snippet_visibility_level_20').set(true)
page.within('.file-editor') do page.within('.file-editor') do
el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) el = find('.inputarea')
el.send_keys 'Hello World!' el.send_keys 'Hello World!'
end end
end end
...@@ -126,15 +125,5 @@ end ...@@ -126,15 +125,5 @@ end
describe 'User creates snippet', :js do describe 'User creates snippet', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
context 'when using Monaco' do it_behaves_like "snippet editor"
it_behaves_like "snippet editor" do
let(:flag) { true }
end
end
context 'when using ACE' do
it_behaves_like "snippet editor" do
let(:flag) { false }
end
end
end end
...@@ -6,7 +6,6 @@ shared_examples_for 'snippet editor' do ...@@ -6,7 +6,6 @@ shared_examples_for 'snippet editor' do
before do before do
stub_feature_flags(snippets_vue: false) stub_feature_flags(snippets_vue: false)
stub_feature_flags(snippets_edit_vue: false) stub_feature_flags(snippets_edit_vue: false)
stub_feature_flags(monaco_snippets: flag)
sign_in(user) sign_in(user)
visit new_snippet_path visit new_snippet_path
end end
...@@ -23,7 +22,7 @@ shared_examples_for 'snippet editor' do ...@@ -23,7 +22,7 @@ shared_examples_for 'snippet editor' do
fill_in 'personal_snippet_description', with: 'My Snippet **Description**' fill_in 'personal_snippet_description', with: 'My Snippet **Description**'
page.within('.file-editor') do page.within('.file-editor') do
el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) el = find('.inputarea')
el.send_keys 'Hello World!' el.send_keys 'Hello World!'
end end
end end
...@@ -136,7 +135,7 @@ shared_examples_for 'snippet editor' do ...@@ -136,7 +135,7 @@ shared_examples_for 'snippet editor' do
fill_in 'personal_snippet_title', with: 'My Snippet Title' fill_in 'personal_snippet_title', with: 'My Snippet Title'
page.within('.file-editor') do page.within('.file-editor') do
find(:xpath, "//input[@id='personal_snippet_file_name']").set 'snippet+file+name' find(:xpath, "//input[@id='personal_snippet_file_name']").set 'snippet+file+name'
el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) el = find('.inputarea')
el.send_keys 'Hello World!' el.send_keys 'Hello World!'
end end
...@@ -154,15 +153,5 @@ describe 'User creates snippet', :js do ...@@ -154,15 +153,5 @@ describe 'User creates snippet', :js do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
context 'when using Monaco' do it_behaves_like "snippet editor"
it_behaves_like "snippet editor" do
let(:flag) { true }
end
end
context 'when using ACE' do
it_behaves_like "snippet editor" do
let(:flag) { false }
end
end
end end
...@@ -8,11 +8,6 @@ jest.mock('~/editor/editor_lite', () => { ...@@ -8,11 +8,6 @@ jest.mock('~/editor/editor_lite', () => {
}); });
}); });
const mockCreateAceInstance = jest.fn();
global.ace = {
edit: mockCreateAceInstance,
};
describe('Blob utilities', () => { describe('Blob utilities', () => {
beforeEach(() => { beforeEach(() => {
Editor.mockClear(); Editor.mockClear();
...@@ -29,21 +24,6 @@ describe('Blob utilities', () => { ...@@ -29,21 +24,6 @@ describe('Blob utilities', () => {
}); });
describe('Monaco editor', () => { describe('Monaco editor', () => {
let origProp;
beforeEach(() => {
origProp = window.gon;
window.gon = {
features: {
monacoSnippets: true,
},
};
});
afterEach(() => {
window.gon = origProp;
});
it('initializes the Editor Lite', () => { it('initializes the Editor Lite', () => {
utils.initEditorLite({ el: editorEl }); utils.initEditorLite({ el: editorEl });
expect(Editor).toHaveBeenCalled(); expect(Editor).toHaveBeenCalled();
...@@ -69,27 +49,5 @@ describe('Blob utilities', () => { ...@@ -69,27 +49,5 @@ describe('Blob utilities', () => {
]); ]);
}); });
}); });
describe('ACE editor', () => {
let origProp;
beforeEach(() => {
origProp = window.gon;
window.gon = {
features: {
monacoSnippets: false,
},
};
});
afterEach(() => {
window.gon = origProp;
});
it('does not initialize the Editor Lite', () => {
utils.initEditorLite({ el: editorEl });
expect(Editor).not.toHaveBeenCalled();
expect(mockCreateAceInstance).toHaveBeenCalledWith(editorEl);
});
});
}); });
}); });
import Editor from '~/editor/editor_lite'; import Editor from '~/editor/editor_lite';
import { initEditor } from '~/snippet/snippet_bundle'; import initEditor from '~/snippet/snippet_bundle';
import { setHTMLFixture } from 'helpers/fixtures'; import { setHTMLFixture } from 'helpers/fixtures';
jest.mock('~/editor/editor_lite', () => jest.fn()); jest.mock('~/editor/editor_lite', () => jest.fn());
describe('Snippet editor', () => { describe('Snippet editor', () => {
describe('Monaco editor for Snippets', () => { let editorEl;
let oldGon; let contentEl;
let editorEl; let fileNameEl;
let contentEl; let form;
let fileNameEl;
let form; const mockName = 'foo.bar';
const mockContent = 'Foo Bar';
const mockName = 'foo.bar'; const updatedMockContent = 'New Foo Bar';
const mockContent = 'Foo Bar';
const updatedMockContent = 'New Foo Bar'; const mockEditor = {
createInstance: jest.fn(),
const mockEditor = { updateModelLanguage: jest.fn(),
createInstance: jest.fn(), getValue: jest.fn().mockReturnValueOnce(updatedMockContent),
updateModelLanguage: jest.fn(), };
getValue: jest.fn().mockReturnValueOnce(updatedMockContent), Editor.mockImplementation(() => mockEditor);
};
Editor.mockImplementation(() => mockEditor); function setUpFixture(name, content) {
setHTMLFixture(`
function setUpFixture(name, content) { <div class="snippet-form-holder">
setHTMLFixture(` <form>
<div class="snippet-form-holder"> <input class="js-snippet-file-name" type="text" value="${name}">
<form> <input class="snippet-file-content" type="hidden" value="${content}">
<input class="js-snippet-file-name" type="text" value="${name}"> <pre id="editor"></pre>
<input class="snippet-file-content" type="hidden" value="${content}"> </form>
<pre id="editor"></pre> </div>
</form> `);
</div> }
`);
} function bootstrap(name = '', content = '') {
setUpFixture(name, content);
function bootstrap(name = '', content = '') { editorEl = document.getElementById('editor');
setUpFixture(name, content); contentEl = document.querySelector('.snippet-file-content');
editorEl = document.getElementById('editor'); fileNameEl = document.querySelector('.js-snippet-file-name');
contentEl = document.querySelector('.snippet-file-content'); form = document.querySelector('.snippet-form-holder form');
fileNameEl = document.querySelector('.js-snippet-file-name');
form = document.querySelector('.snippet-form-holder form'); initEditor();
}
initEditor();
} function createEvent(name) {
return new Event(name, {
function createEvent(name) { view: window,
return new Event(name, { bubbles: true,
view: window, cancelable: true,
bubbles: true,
cancelable: true,
});
}
beforeEach(() => {
oldGon = window.gon;
window.gon = { features: { monacoSnippets: true } };
bootstrap(mockName, mockContent);
}); });
}
afterEach(() => { beforeEach(() => {
window.gon = oldGon; bootstrap(mockName, mockContent);
}); });
it('correctly initializes Editor', () => { it('correctly initializes Editor', () => {
expect(mockEditor.createInstance).toHaveBeenCalledWith({ expect(mockEditor.createInstance).toHaveBeenCalledWith({
el: editorEl, el: editorEl,
blobPath: mockName, blobPath: mockName,
blobContent: mockContent, blobContent: mockContent,
});
}); });
});
it('listens to file name changes and updates syntax highlighting of code', () => { it('listens to file name changes and updates syntax highlighting of code', () => {
expect(mockEditor.updateModelLanguage).not.toHaveBeenCalled(); expect(mockEditor.updateModelLanguage).not.toHaveBeenCalled();
const event = createEvent('change'); const event = createEvent('change');
fileNameEl.value = updatedMockContent; fileNameEl.value = updatedMockContent;
fileNameEl.dispatchEvent(event); fileNameEl.dispatchEvent(event);
expect(mockEditor.updateModelLanguage).toHaveBeenCalledWith(updatedMockContent); expect(mockEditor.updateModelLanguage).toHaveBeenCalledWith(updatedMockContent);
}); });
it('listens to form submit event and populates the hidden field with most recent version of the content', () => { it('listens to form submit event and populates the hidden field with most recent version of the content', () => {
expect(contentEl.value).toBe(mockContent); expect(contentEl.value).toBe(mockContent);
const event = createEvent('submit'); const event = createEvent('submit');
form.dispatchEvent(event); form.dispatchEvent(event);
expect(contentEl.value).toBe(updatedMockContent); expect(contentEl.value).toBe(updatedMockContent);
});
}); });
}); });
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