Skip to content

Commit d241f58

Browse files
committed
feat: integrate Monaco Editor for enhanced configuration viewing and add device feedbacks querying
1 parent e7e71b9 commit d241f58

6 files changed

Lines changed: 335 additions & 102 deletions

File tree

package-lock.json

Lines changed: 72 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"type": "module",
55
"private": true,
66
"dependencies": {
7+
"@monaco-editor/react": "^4.7.0",
78
"@reduxjs/toolkit": "^2.11.2",
89
"axios": "^1.14.0",
910
"bootstrap": "^5.3.8",

src/features/ConfigFile.tsx

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
1-
import { useGetConfigQuery } from '../store/apiSlice';
1+
import { Editor, OnMount, useMonaco } from "@monaco-editor/react";
2+
import { useEffect, useRef } from "react";
3+
import { useGetConfigQuery } from "../store/apiSlice";
4+
5+
type IConfigViewer = Parameters<OnMount>[0];
26

37
const ConfigFile = () => {
4-
const {data: config} = useGetConfigQuery();
8+
const { data: config } = useGetConfigQuery();
9+
10+
if (!config) {
11+
return <div>Loading...</div>;
12+
}
13+
14+
return <ConfigFileRender config={config} />;
15+
};
16+
17+
export default ConfigFile;
18+
19+
const ConfigFileRender = ({ config }: { config: any }) => {
20+
console.log("ConfigFileRender == ", config);
21+
const monaco = useMonaco();
22+
const editorRef = useRef<IConfigViewer | null>(null);
523

24+
useEffect(() => {
25+
if (!monaco) return;
626

7-
if(!config) { return <div>Loading...</div> };
27+
(monaco.languages as any).json?.jsonDefaults?.setDiagnosticsOptions({
28+
enableSchemaRequest: false,
29+
allowComments: false,
30+
validate: true,
31+
});
32+
}, [monaco]);
833

9-
return (
10-
<div className="d-flex flex-column overflow-hidden h-100">
11-
<h2 className='mb-2'>Merged Configuration</h2>
12-
<pre className='flex-grow-1 overflow-auto'>
13-
{JSON.stringify(config, null, 2)}
14-
</pre>
15-
</div>
16-
);
17-
}
34+
// Set the editor reference
35+
function handleEditorDidMount(editor: IConfigViewer) {
36+
editorRef.current = editor;
37+
}
1838

19-
export default ConfigFile;
39+
return (
40+
<Editor
41+
height="100%"
42+
defaultLanguage="json"
43+
language="json"
44+
options={{
45+
readOnly: true,
46+
}}
47+
value={JSON.stringify(config, null, 2)}
48+
onMount={handleEditorDidMount}
49+
theme="vs-dark"
50+
/>
51+
);
52+
};

0 commit comments

Comments
 (0)