2023-08-01 21:55:18 +03:00
|
|
|
import { useMemo } from 'react';
|
|
|
|
import { darkTheme, GraphCanvas, GraphEdge, GraphNode, lightTheme } from 'reagraph';
|
|
|
|
|
2023-07-29 03:31:21 +03:00
|
|
|
import Modal from '../../components/Common/Modal';
|
2023-08-01 21:55:18 +03:00
|
|
|
import { useConceptTheme } from '../../context/ThemeContext';
|
|
|
|
import { resources } from '../../utils/constants';
|
2023-07-29 03:31:21 +03:00
|
|
|
import { SyntaxTree } from '../../utils/models';
|
2023-08-01 21:55:18 +03:00
|
|
|
import { getNodeLabel } from '../../utils/staticUI';
|
2023-07-29 03:31:21 +03:00
|
|
|
|
|
|
|
interface DlgShowASTProps {
|
|
|
|
hideWindow: () => void
|
|
|
|
syntaxTree: SyntaxTree
|
2023-08-01 21:55:18 +03:00
|
|
|
expression: string
|
2023-07-29 03:31:21 +03:00
|
|
|
}
|
|
|
|
|
2023-08-01 21:55:18 +03:00
|
|
|
function DlgShowAST({ hideWindow, syntaxTree, expression }: DlgShowASTProps) {
|
|
|
|
const { darkMode } = useConceptTheme();
|
|
|
|
|
|
|
|
function handleSubmit() {
|
2023-07-29 03:31:21 +03:00
|
|
|
// Do nothing
|
2023-08-01 21:55:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const nodes: GraphNode[] = useMemo(
|
|
|
|
() => syntaxTree.map(node => {
|
|
|
|
return {
|
|
|
|
id: String(node.uid),
|
|
|
|
label: getNodeLabel(node)
|
|
|
|
};
|
|
|
|
}), [syntaxTree]);
|
|
|
|
|
|
|
|
const edges: GraphEdge[] = useMemo(
|
|
|
|
() => {
|
|
|
|
const result: GraphEdge[] = [];
|
|
|
|
syntaxTree.forEach(node => {
|
|
|
|
if (node.parent != node.uid) {
|
|
|
|
result.push({
|
|
|
|
id: String(node.uid),
|
|
|
|
source: String(node.parent),
|
|
|
|
target: String(node.uid)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return result;
|
|
|
|
}, [syntaxTree]);
|
2023-07-29 03:31:21 +03:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
hideWindow={hideWindow}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
submitText='Закрыть'
|
|
|
|
canSubmit={true}
|
|
|
|
>
|
2023-08-01 21:55:18 +03:00
|
|
|
<div className='flex flex-col items-start gap-2'>
|
|
|
|
<div className='w-full text-lg text-center'>{expression}</div>
|
|
|
|
<div className='flex-wrap w-full h-full overflow-auto'>
|
|
|
|
<div className='relative w-[1040px] h-[600px] 2xl:w-[1680px] 2xl:h-[600px]'>
|
|
|
|
<GraphCanvas
|
|
|
|
nodes={nodes}
|
|
|
|
edges={edges}
|
|
|
|
layoutType='hierarchicalTd'
|
|
|
|
labelFontUrl={resources.graph_font}
|
|
|
|
theme={darkMode ? darkTheme : lightTheme}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-07-29 03:31:21 +03:00
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgShowAST;
|