Skip to content

Commit

Permalink
Fix subtrees visualizer bug
Browse files Browse the repository at this point in the history
  • Loading branch information
javizqh committed Oct 20, 2024
1 parent 59fb88d commit c95de9f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 8 additions & 0 deletions frontend/src/components/tree_editor/DiagramVisualizer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ const setStatusNode = (
const DiagramVisualizer = memo(
({
modelJson,
setResultJson,
manager,
treeStructure,
view,
changeView,
setGoBack,
}: {
modelJson: any;
setResultJson: Function;
manager: any;
treeStructure: any;
view: any;
Expand Down Expand Up @@ -115,6 +117,12 @@ const DiagramVisualizer = memo(
engine.current.zoomToFitNodes({ margin: 50 });
};

// Fixes uncomplete first serialization
setTimeout(() => {
console.log("Rendered!");
setResultJson(model.current.serialize())
}, 1);

return (
<div>
<NodeMenu
Expand Down
18 changes: 11 additions & 7 deletions frontend/src/components/tree_editor/MainTreeEditorContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ const MainTreeEditorContainer = ({
previousResultJson: string,
previousName: string,
) => {
if (view === TreeViewType.Visualizer) {
return
}
try {
await saveSubtree(previousResultJson, projectName, previousName);
} catch (error: unknown) {
Expand Down Expand Up @@ -112,16 +115,17 @@ const MainTreeEditorContainer = ({
setWentBack(false);

// Fetch the new subtree or project graph
getBTTree();
// getBTTree();
fetchTree();
console.log("Getting graph!");
}, [projectName, subTreeName, view]);
}, [projectName, subTreeName]);

useEffect(() => {
if (goBack) {
saveSubtreeJson(resultJson, subTreeName); // Save the current subtree
setTreeHierarchy((prevHierarchy) => {
const newHierarchy = prevHierarchy.slice(0, -1);
console.log("SET")
setSubTreeName(newHierarchy[newHierarchy.length - 1] || "");
return newHierarchy;
});
Expand All @@ -135,11 +139,11 @@ const MainTreeEditorContainer = ({
console.log("Updated Subtree hierarchy: ", treeHierarchy);
}, [treeHierarchy]);

// useEffect(() => {
// setInitialJson(modelJson);
// getBTTree();
// console.log("Changing view!");
// }, [view]);
useEffect(() => {
// fetchTree();
getBTTree();
console.log("Changing view!");
}, [view]);

return (
<div id="editor-container">
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/tree_editor/NodeMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { MouseEventHandler, useEffect, useState } from "react";
import "./NodeMenu.css";
import axios from "axios";

import { ReactComponent as DeleteIcon } from "./img/del_node.svg";
import { ReactComponent as SubtreeIcon } from "./img/subtree.svg";
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/tree_editor/TreeEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ const TreeEditor = memo(
{view === TreeViewType.Visualizer ? (
<DiagramVisualizer
modelJson={modelJson}
setResultJson={setResultJson}
manager={CommsManager.getInstance()}
treeStructure={treeStructure}
view={view}
Expand Down

0 comments on commit c95de9f

Please sign in to comment.