ConceptPortal-public/rsconcept/frontend/src/pages/RSFormPage/DlgShowAST.tsx

66 lines
1.8 KiB
TypeScript
Raw Normal View History

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();
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}
2023-08-08 23:04:21 +03:00
readonly
2023-07-29 03:31:21 +03:00
>
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'>
2023-08-08 23:04:21 +03:00
<div className='relative w-[1040px] h-[600px] 2xl:w-[1680px] 2xl:h-[600px] max-h-full max-w-full'>
2023-08-01 21:55:18 +03:00
<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;