Skip to content

Commit f61a596

Browse files
committed
Started situating graph view
1 parent cdfe184 commit f61a596

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

packages/feedback-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@macrostrat/ui-components": "workspace:*",
1717
"react": "^17.0.2||^18",
1818
"react-arborist": "^3.4.0",
19+
"react-flow": "^1.0.3",
1920
"react-text-annotate-blend": "^1.2.0"
2021
},
2122
"exports": {

packages/feedback-components/src/feedback/edit-state.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { createContext, Dispatch, useContext, useReducer } from "react";
33
import update, { Spec } from "immutability-helper";
44
import { EntityType } from "../extractions/types";
55

6+
export enum ViewMode {
7+
Tree = "tree",
8+
Graph = "graph",
9+
}
10+
611
interface TreeState {
712
initialTree: TreeData[];
813
tree: TreeData[];
@@ -11,6 +16,7 @@ interface TreeState {
1116
selectedEntityType: EntityType;
1217
lastInternalId: number;
1318
isSelectingEntityType: boolean;
19+
viewMode: ViewMode;
1420
}
1521

1622
type TextRange = {
@@ -27,6 +33,7 @@ type TreeAction =
2733
| { type: "delete-node"; payload: { ids: number[] } }
2834
| { type: "select-node"; payload: { ids: number[] } }
2935
| { type: "toggle-node-selected"; payload: { ids: number[] } }
36+
| { type: "set-view-mode"; payload: ViewMode }
3037
| { type: "create-node"; payload: TextRange }
3138
| { type: "select-entity-type"; payload: EntityType }
3239
| { type: "toggle-entity-type-selector"; payload?: boolean | null }
@@ -50,6 +57,7 @@ export function useUpdatableTree(
5057
selectedEntityType: type,
5158
lastInternalId: 0,
5259
isSelectingEntityType: false,
60+
viewMode: ViewMode.Tree,
5361
});
5462
}
5563

@@ -169,6 +177,8 @@ function treeReducer(state: TreeState, action: TreeAction) {
169177
tree: state.initialTree,
170178
selectedNodes: [],
171179
};
180+
case "set-view-mode":
181+
return { ...state, viewMode: action.payload };
172182
}
173183
}
174184

packages/feedback-components/src/feedback/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ import { FeedbackText } from "./text-visualizer";
77
import type { InternalEntity, TreeData } from "./types";
88
import type { Entity } from "../extractions";
99
import { ModelInfo } from "../extractions";
10-
import { TreeDispatchContext, useUpdatableTree } from "./edit-state";
10+
import { TreeDispatchContext, useUpdatableTree, ViewMode } from "./edit-state";
1111
import { useCallback, useEffect, useRef } from "react";
12-
import { ButtonGroup, Card } from "@blueprintjs/core";
12+
import { ButtonGroup, Card, SegmentedControl } from "@blueprintjs/core";
1313
import { OmniboxSelector } from "./type-selector";
14-
import { CancelButton, DataField, SaveButton } from "@macrostrat/ui-components";
14+
import {
15+
CancelButton,
16+
DataField,
17+
FlexBox,
18+
FlexRow,
19+
SaveButton,
20+
} from "@macrostrat/ui-components";
1521
import useElementDimensions from "use-element-dimensions";
1622

1723
export type { GraphData } from "./edit-state";
@@ -55,7 +61,21 @@ export function FeedbackComponent({
5561
nodes: tree,
5662
selectedNodes,
5763
}),
58-
h(ModelInfo, { data: model }),
64+
h(FlexRow, { alignItems: "baseline", justifyContent: "space-between" }, [
65+
h(ModelInfo, { data: model }),
66+
h(SegmentedControl, {
67+
options: [
68+
{ label: "Tree", value: "tree" },
69+
{ label: "Graph", value: "graph" },
70+
],
71+
value: state.viewMode,
72+
small: true,
73+
onValueChange(value: ViewMode) {
74+
console.log("Setting view mode", value);
75+
dispatch({ type: "set-view-mode", payload: value });
76+
},
77+
}),
78+
]),
5979
h(
6080
"div.entity-panel",
6181
{
@@ -109,7 +129,7 @@ export function FeedbackComponent({
109129
}),
110130
}),
111131
]),
112-
h(ManagedSelectionTree, {
132+
h.if(state.viewMode == "tree")(ManagedSelectionTree, {
113133
selectedNodes,
114134
dispatch,
115135
tree,

0 commit comments

Comments
 (0)