Skip to content

Commit

Permalink
Merge pull request #54 from sc420/38-saveload-operationsnodes
Browse files Browse the repository at this point in the history
Can save/load graph states
  • Loading branch information
sc420 authored Mar 4, 2024
2 parents 2f29104 + ead602f commit 16d9853
Show file tree
Hide file tree
Showing 36 changed files with 1,231 additions and 55 deletions.
13 changes: 13 additions & 0 deletions interactive-computational-graph/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions interactive-computational-graph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/node": "^16.18.38",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"file-saver": "^2.0.5",
"katex": "^0.16.8",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down Expand Up @@ -52,6 +53,7 @@
},
"devDependencies": {
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
"@types/file-saver": "^2.0.7",
"@types/katex": "^0.16.2",
"@types/react-test-renderer": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.62.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ const FeatureNavigator: FunctionComponent<FeatureNavigatorProps> = ({
icon: <EmojiObjectsIcon />,
},
{
id: "load-save",
text: "Load/Save",
id: "save-load",
text: "Save/Load",
icon: <ImportExportIcon />,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test("should trigger event when adding a node", () => {
const handleDeleteOperation = jest.fn();
const handleClearSelection = jest.fn();
const handleSelectNode = jest.fn();
const handleSave = jest.fn();
const handleLoad = jest.fn();
render(
<FeaturePanel
feature="add-nodes"
Expand All @@ -35,6 +37,8 @@ test("should trigger event when adding a node", () => {
onDeleteOperation={handleDeleteOperation}
onClearSelection={handleClearSelection}
onSelectNode={handleSelectNode}
onSave={handleSave}
onLoad={handleLoad}
/>,
);

Expand Down
14 changes: 10 additions & 4 deletions interactive-computational-graph/src/components/FeaturePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,46 @@ import type ExplainDerivativeData from "../features/ExplainDerivativeData";
import type FeatureNodeType from "../features/FeatureNodeType";
import type FeatureOperation from "../features/FeatureOperation";
import type SelectedFeature from "../features/SelectedFeature";
import type GraphContainerState from "../states/GraphContainerState";
import AddNodesPanel from "./AddNodesPanel";
import EditNodesPanel from "./EditNodesPanel";
import ExplainDerivativesPanel from "./ExplainDerivativesPanel";
import SaveLoadPanel from "./SaveLoadPanel";

interface FeaturePanelProps {
feature: SelectedFeature;
featureOperations: FeatureOperation[];
operationIdsAddedAtLeastOnce: Set<string>;
isDarkMode: boolean;
hasNodes: boolean;
hasDerivativeTarget: boolean;
explainDerivativeData: ExplainDerivativeData[];
isDarkMode: boolean;
onAddNode: (featureNodeType: FeatureNodeType) => void;
onAddOperation: () => void;
onEditOperation: (updatedOperation: FeatureOperation) => void;
onDeleteOperation: (operationId: string) => void;
onClearSelection: () => void;
onSelectNode: (nodeId: string) => void;
onSave: () => GraphContainerState;
onLoad: (graphContainerState: GraphContainerState) => void;
}

const FeaturePanel: FunctionComponent<FeaturePanelProps> = ({
feature,
featureOperations,
operationIdsAddedAtLeastOnce,
isDarkMode,
hasNodes,
hasDerivativeTarget,
explainDerivativeData,
isDarkMode,
onAddNode,
onAddOperation,
onEditOperation,
onDeleteOperation,
onClearSelection,
onSelectNode,
onSave,
onLoad,
}) => {
const renderSelectedPanel = (): ReactElement => {
switch (feature) {
Expand Down Expand Up @@ -80,8 +86,8 @@ const FeaturePanel: FunctionComponent<FeaturePanelProps> = ({
);
case "examples":
return <EditNodesPanel />;
case "load-save":
return <EditNodesPanel />;
case "save-load":
return <SaveLoadPanel onSave={onSave} onLoad={onLoad} />;
}
};
return (
Expand Down
Loading

0 comments on commit 16d9853

Please sign in to comment.