-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Update version of react-monaco-editor and monaco-editor libraries * Fix yarn lock file * Fix CI * Fix unit tests * Fix CI * Fix comment * move monaco instance in window.MonacoEnvironment * Replace EuiCodeBlock with Monaco editor in Discover expanded document * Replace EuiCodeBlock with EuiErrorBoundary * Revert changes done by mistake * Remove unused translations * Fix doc_viewer test and snapshots * Add comment and rename the function related to editor height calculation * Remove "value" from JSON tree and fix resizing * Update json_code_editor.test.tsx.snap * Fix JsonCodeEditor props * Fix json_code_editor test * Delete JsonCodeBlock and remove inline style in JsonCodeEditor * Rename jsonCodeEditor CSS class name to dscJsonCodeEditor Co-authored-by: Uladzislau Lasitsa <[email protected]> Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Uladzislau Lasitsa <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
bfff061
commit 79d483a
Showing
12 changed files
with
187 additions
and
69 deletions.
There are no files selected for viewing
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
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
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
20 changes: 0 additions & 20 deletions
20
...public/application/components/json_code_block/__snapshots__/json_code_block.test.tsx.snap
This file was deleted.
Oops, something went wrong.
23 changes: 0 additions & 23 deletions
23
src/plugins/discover/public/application/components/json_code_block/json_code_block.tsx
This file was deleted.
Oops, something went wrong.
71 changes: 71 additions & 0 deletions
71
...blic/application/components/json_code_editor/__snapshots__/json_code_editor.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
src/plugins/discover/public/application/components/json_code_editor/json_code_editor.scss
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,3 @@ | ||
.dscJsonCodeEditor { | ||
width: 100% | ||
} |
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
84 changes: 84 additions & 0 deletions
84
src/plugins/discover/public/application/components/json_code_editor/json_code_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,84 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import './json_code_editor.scss'; | ||
|
||
import React, { useCallback } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { monaco, XJsonLang } from '@kbn/monaco'; | ||
import { EuiButtonEmpty, EuiCopy, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; | ||
import { CodeEditor } from '../../../../../kibana_react/public'; | ||
import { DocViewRenderProps } from '../../../application/doc_views/doc_views_types'; | ||
|
||
const codeEditorAriaLabel = i18n.translate('discover.json.codeEditorAriaLabel', { | ||
defaultMessage: 'Read only JSON view of an elasticsearch document', | ||
}); | ||
const copyToClipboardLabel = i18n.translate('discover.json.copyToClipboardLabel', { | ||
defaultMessage: 'Copy to clipboard', | ||
}); | ||
|
||
export const JsonCodeEditor = ({ hit }: DocViewRenderProps) => { | ||
const jsonValue = JSON.stringify(hit, null, 2); | ||
|
||
// setting editor height based on lines height and count to stretch and fit its content | ||
const setEditorCalculatedHeight = useCallback((editor) => { | ||
const editorElement = editor.getDomNode(); | ||
|
||
if (!editorElement) { | ||
return; | ||
} | ||
|
||
const lineHeight = editor.getOption(monaco.editor.EditorOption.lineHeight); | ||
const lineCount = editor.getModel()?.getLineCount() || 1; | ||
const height = editor.getTopForLineNumber(lineCount + 1) + lineHeight; | ||
|
||
editorElement.style.height = `${height}px`; | ||
editor.layout(); | ||
}, []); | ||
|
||
return ( | ||
<EuiFlexGroup className="dscJsonCodeEditor" direction="column" gutterSize="s"> | ||
<EuiFlexItem grow={true}> | ||
<EuiSpacer size="s" /> | ||
<div className="eui-textRight"> | ||
<EuiCopy textToCopy={jsonValue}> | ||
{(copy) => ( | ||
<EuiButtonEmpty size="xs" flush="right" iconType="copyClipboard" onClick={copy}> | ||
{copyToClipboardLabel} | ||
</EuiButtonEmpty> | ||
)} | ||
</EuiCopy> | ||
</div> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={true}> | ||
<CodeEditor | ||
languageId={XJsonLang.ID} | ||
value={jsonValue} | ||
onChange={() => {}} | ||
editorDidMount={setEditorCalculatedHeight} | ||
aria-label={codeEditorAriaLabel} | ||
options={{ | ||
automaticLayout: true, | ||
fontSize: 12, | ||
minimap: { | ||
enabled: false, | ||
}, | ||
overviewRulerBorder: false, | ||
readOnly: true, | ||
scrollbar: { | ||
alwaysConsumeMouseWheel: false, | ||
}, | ||
scrollBeyondLastLine: false, | ||
wordWrap: 'on', | ||
wrappingIndent: 'indent', | ||
}} | ||
/> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
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
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
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