mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-26 10:23:28 +08:00
Feat: Add a data compilation layer. (#16777)
### Summary Feat: Add a data compilation layer.
This commit is contained in:
@@ -22,6 +22,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
height = '400px',
|
||||
className = '',
|
||||
options = {},
|
||||
defaultExpanded = false,
|
||||
}) => {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const editorRef = useRef<any>(null);
|
||||
@@ -66,6 +67,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
|
||||
if (value) {
|
||||
editorRef.current.set(value);
|
||||
|
||||
if (defaultExpanded) {
|
||||
editorRef.current.expandAll?.();
|
||||
}
|
||||
}
|
||||
|
||||
setIsLoading(false);
|
||||
@@ -138,6 +143,10 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
|
||||
editorRef.current = new JSONEditor(containerRef.current, newOptions);
|
||||
editorRef.current.set(currentData);
|
||||
|
||||
if (defaultExpanded) {
|
||||
editorRef.current.expandAll?.();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(
|
||||
'Failed to reload jsoneditor with new language:',
|
||||
@@ -148,7 +157,7 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
|
||||
initEditorWithNewLanguage();
|
||||
}
|
||||
}, [i18n.language, value, onChange, options]);
|
||||
}, [i18n.language, value, onChange, options, defaultExpanded]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editorRef.current && value !== undefined) {
|
||||
@@ -157,14 +166,22 @@ const JsonEditor: React.FC<JsonEditorProps> = ({
|
||||
const currentJson = editorRef.current.get();
|
||||
if (JSON.stringify(currentJson) !== JSON.stringify(value)) {
|
||||
editorRef.current.set(value);
|
||||
|
||||
if (defaultExpanded) {
|
||||
editorRef.current.expandAll?.();
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
// Skip update if there is a syntax error in the current editor
|
||||
editorRef.current.set(value);
|
||||
|
||||
if (defaultExpanded) {
|
||||
editorRef.current.expandAll?.();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [value]);
|
||||
}, [value, defaultExpanded]);
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -336,4 +336,7 @@ export interface JsonEditorProps {
|
||||
|
||||
// Configuration options for the JSONEditor
|
||||
options?: JsonEditorOptions;
|
||||
|
||||
// Whether to expand all nodes by default in tree/view/form modes
|
||||
defaultExpanded?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user