-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First iteration of editor component with render test
- Loading branch information
1 parent
0cae751
commit 6365349
Showing
9 changed files
with
1,521 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/editor.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import 'brace'; | ||
import 'brace/mode/json'; | ||
|
||
jest.mock('./worker', () => { | ||
return { workerModule: { id: 'ace/mode/json_worker', src: '' } }; | ||
}); | ||
|
||
import { registerTestBed } from '../../../../../../../test_utils'; | ||
import { Editor, Props } from '.'; | ||
|
||
describe('Editor Component', () => { | ||
it('renders', async () => { | ||
const props: Props = { licenseEnabled: true }; | ||
// Ignore the warning about Worker not existing for now... | ||
const init = registerTestBed(Editor); | ||
await init(props); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/editor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { useRef, useEffect } from 'react'; | ||
import { Editor as AceEditor } from 'brace'; | ||
|
||
import { initializeEditor } from './init_editor'; | ||
|
||
export interface Props { | ||
licenseEnabled: boolean; | ||
} | ||
|
||
export const Editor = ({ licenseEnabled }: Props) => { | ||
const containerRef = useRef<HTMLDivElement>(null as any); | ||
const editorInstanceRef = useRef<AceEditor>(null as any); | ||
useEffect(() => { | ||
const divEl = containerRef.current; | ||
editorInstanceRef.current = initializeEditor({ el: divEl, licenseEnabled }); | ||
}); | ||
return <div ref={containerRef} />; | ||
}; |
7 changes: 7 additions & 0 deletions
7
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { Editor, Props } from './editor'; |
31 changes: 31 additions & 0 deletions
31
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/init_editor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import ace from 'brace'; | ||
import { installXJsonMode } from './x_json_mode'; | ||
|
||
export function initializeEditor({ | ||
el, | ||
licenseEnabled, | ||
}: { | ||
el: HTMLDivElement; | ||
licenseEnabled: boolean; | ||
}) { | ||
const editor: ace.Editor = ace.acequire('ace/ace').edit(el); | ||
|
||
installXJsonMode(editor); | ||
editor.$blockScrolling = Infinity; | ||
|
||
if (!licenseEnabled) { | ||
editor.setReadOnly(true); | ||
editor.container.style.pointerEvents = 'none'; | ||
editor.container.style.opacity = '0.5'; | ||
editor.renderer.setStyle('disabled'); | ||
editor.blur(); | ||
} | ||
|
||
return editor; | ||
} |
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/worker/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import src from '!!raw-loader!./worker.js'; | ||
|
||
export const workerModule = { | ||
id: 'ace/mode/json_worker', | ||
src, | ||
}; |
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/searchprofiler/np_ready/public/application/editor/worker/worker.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// Satisfy TS's requirements that the module be declared per './index.ts'. | ||
declare module '!!raw-loader!./worker.js' { | ||
const content: string; | ||
// eslint-disable-next-line import/no-default-export | ||
export default content; | ||
} |
Oops, something went wrong.