Skip to content

Commit 3d6f00f

Browse files
committed
Use monaco-editor in WfoJsonCodeBlock
1 parent 8dd9c14 commit 3d6f00f

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

.changeset/tango-orange-house.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@orchestrator-ui/orchestrator-ui-components': minor
3+
---
4+
5+
Use monaco-editor in WfoJsonCodeBlock

packages/orchestrator-ui-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"@elastic/eui": "101.3.0",
3838
"@emotion/css": "^11.11.2",
3939
"@emotion/react": "^11.11.4",
40+
"@monaco-editor/react": "^4.7.0",
4041
"@rtk-query/graphql-request-base-query": "^2.3.1",
4142
"graphql-request": "^6.1.0",
4243
"invariant": "^2.2.4",

packages/orchestrator-ui-components/src/components/WfoJsonCodeBlock/WfoJsonCodeBlock.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import React, { FC } from 'react';
22

3-
import { EuiCodeBlock } from '@elastic/eui';
3+
import Editor, { Monaco } from "@monaco-editor/react";
4+
import { editor } from "monaco-editor";
45

56
import { useWithOrchestratorTheme } from '@/hooks';
7+
import { useOrchestratorTheme } from '@/hooks';
68

79
import { getStyles } from './styles';
810

@@ -21,19 +23,39 @@ export const WfoJsonCodeBlock: FC<WfoJsonCodeBlockProps> = ({
2123
data,
2224
isBasicStyle = false,
2325
}) => {
26+
const { isDarkThemeActive } = useOrchestratorTheme();
2427
const { euiCodeBlockStyle, euiBasicCodeBlockStyle } =
2528
useWithOrchestratorTheme(getStyles);
2629

2730
const json = JSON.stringify(data, null, 4);
2831

32+
const [editorHeight, setEditorHeight] = React.useState(0);
33+
34+
function editorDidMount(
35+
editor: editor.IStandaloneCodeEditor,
36+
monaco: Monaco
37+
) {
38+
const scrollHeight = editor.getScrollHeight();
39+
setEditorHeight(Math.min(scrollHeight, 500));
40+
}
41+
2942
return (
30-
<EuiCodeBlock
43+
<Editor
44+
height={editorHeight}
3145
css={isBasicStyle ? euiBasicCodeBlockStyle : euiCodeBlockStyle}
32-
isCopyable={true}
46+
theme={isDarkThemeActive ? "vs-dark" : "light"}
47+
options={{
48+
readOnly: true,
49+
lineNumbers: isBasicStyle ? "off" : "on",
50+
scrollBeyondLastLine: false,
51+
contextmenu: false,
52+
minimap: { enabled: false },
53+
mouseWheelZoom: true,
54+
mouseStyle: "copy",
55+
}}
56+
onMount={editorDidMount}
3357
language="json"
34-
lineNumbers={!isBasicStyle}
35-
>
36-
{json}
37-
</EuiCodeBlock>
58+
value={json}
59+
/>
3860
);
3961
};

0 commit comments

Comments
 (0)