Skip to content

Commit 206b563

Browse files
authored
Merge pull request #160 from UW-Macrostrat/feedback
Feedback autoselect
2 parents 2ee8e00 + 49fb0b9 commit 206b563

File tree

7 files changed

+62
-17
lines changed

7 files changed

+62
-17
lines changed

packages/feedback-components/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file. The format
44
is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this
55
project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [1.1.7]
7+
## [1.1.8] - 2025-07-30
8+
9+
- On load, have any nodes matching autoselect input automically selected
10+
- View only bugs fixed
11+
12+
## [1.1.7] - 2025-07-25
813

914
- Can't select tree in view only mode
1015
- View matches on hover in view only mode

packages/feedback-components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macrostrat/feedback-components",
3-
"version": "1.1.7",
3+
"version": "1.1.8",
44
"description": "",
55
"source": "src/index.ts",
66
"type": "module",

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,27 @@ export function useUpdatableTree(
6363
entityTypes: Map<number, EntityType>,
6464
viewOnly: boolean,
6565
matchMode: boolean,
66+
autoSelect: string[] = [],
6667
): [TreeState, TreeDispatch] {
6768
// Get the first entity type
6869
// issue: grabs second entity instead of selected one
6970
const type = entityTypes.values().next().value;
7071

72+
let selectedNodes = [];
73+
autoSelect = autoSelect.map((name) => name.toLowerCase());
74+
75+
if (autoSelect.length > 0) {
76+
// If autoSelect is provided, find the nodes with the matching names
77+
selectedNodes = initialTree
78+
.flatMap((node) => node.children ?? [])
79+
.filter((node) => autoSelect.includes(node.name.toLowerCase()))
80+
.map((node) => node.id);
81+
}
82+
7183
return useReducer(treeReducer, {
7284
initialTree,
7385
tree: initialTree,
74-
selectedNodes: [],
86+
selectedNodes,
7587
entityTypesMap: entityTypes,
7688
selectedEntityType: type,
7789
lastInternalId: 0,
@@ -98,7 +110,7 @@ function treeReducer(state: TreeState, action: TreeAction) {
98110
}
99111

100112
if (action.type === "toggle-view-only") {
101-
return { ...state, viewOnly: !state.viewOnly };
113+
return { ...state, viewOnly: !state.viewOnly, selectedNodes: [] };
102114
}
103115

104116
if (state.viewOnly) return viewMode(state, action);

packages/feedback-components/src/feedback/feedback.module.sass

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
& > svg
2828
width: 800px
2929

30-
.node
31-
cursor: pointer
32-
3330
circle
3431
border: 1px solid black
3532

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export function FeedbackComponent({
5757
allowOverlap,
5858
matchLinks,
5959
view = false,
60+
autoSelect = [],
6061
}) {
6162
const [viewOnly, setViewOnly] = useState(view);
6263
const [match, setMatchLinks] = useState(matchLinks);
@@ -68,6 +69,7 @@ export function FeedbackComponent({
6869
entityTypes,
6970
viewOnly,
7071
matchMode,
72+
autoSelect,
7173
);
7274

7375
const {
@@ -321,8 +323,8 @@ function ManagedSelectionTree(props) {
321323
const clickedRef = useRef(false);
322324

323325
const _Node = useCallback(
324-
(props) => h(Node, { ...props, matchComponent }),
325-
[matchComponent],
326+
(props) => h(Node, { ...props, matchComponent, viewOnly }),
327+
[matchComponent, viewOnly],
326328
);
327329

328330
// Update Tree selection when selectedNodes change
@@ -410,7 +412,6 @@ function ManagedSelectionTree(props) {
410412
onSelect: handleSelect,
411413
children: _Node,
412414
idAccessor(d) {
413-
if (viewOnly) return -1;
414415
return d.id.toString();
415416
},
416417
}),

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,32 @@ function isNodeActive(node: NodeApi<TreeData>, tree: TreeApi<TreeData>) {
4141
return false;
4242
}
4343

44-
function Node({ node, style, dragHandle, tree, matchComponent }: any) {
44+
function Node({
45+
node,
46+
style,
47+
dragHandle,
48+
tree,
49+
matchComponent,
50+
viewOnly,
51+
}: any) {
4552
let highlighted: boolean = isNodeHighlighted(node, tree);
4653
let active: boolean = isNodeActive(node, tree);
4754

48-
const dispatch = useTreeDispatch();
55+
console.log("viewOnly", viewOnly);
4956

50-
// console.log("Node render", node.data, highlighted, active);
57+
const dispatch = useTreeDispatch();
5158

5259
if (!node.data?.type) {
5360
node.data.type = { name: "lith", color: "rgb(107, 255, 91)" };
5461
}
5562

5663
return h(
57-
"div.node",
64+
"div.node" + (!viewOnly ? ".clickable" : ""),
5865
{ style, ref: dragHandle },
5966
h(EntityTag, {
6067
data: node.data,
61-
active,
62-
highlighted,
68+
active: viewOnly ? false : active,
69+
highlighted: viewOnly ? true : highlighted,
6370
matchComponent,
6471
onClickType() {
6572
dispatch({ type: "toggle-entity-type-selector" });

packages/feedback-components/stories/feedback.stories.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ import { FeedbackComponent } from "../src";
44
import { data, entityTypes, data2, data3, entityTypes2 } from "./test-data";
55
import h from "@macrostrat/hyper";
66

7-
function FeedbackInterface({ data, types, allowOverlap, matchLinks, view }) {
7+
function FeedbackInterface({
8+
data,
9+
types,
10+
allowOverlap,
11+
matchLinks,
12+
view,
13+
autoSelect,
14+
}) {
815
const { entities = [], paragraph_text, model, model_run, source_text } = data;
916

1017
return h(FeedbackComponent, {
@@ -17,6 +24,7 @@ function FeedbackInterface({ data, types, allowOverlap, matchLinks, view }) {
1724
allowOverlap,
1825
view,
1926
matchLinks,
27+
autoSelect,
2028
});
2129
}
2230
// More on default export: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
@@ -77,6 +85,21 @@ export const ViewOnly: StoryObj<{}> = {
7785
},
7886
};
7987

88+
export const AutoSelect: StoryObj<{}> = {
89+
args: {
90+
data,
91+
types: entityTypes,
92+
matchLinks: {
93+
lithology: `${lexURL}/lithology`,
94+
strat_name: `${lexURL}/strat-names`,
95+
lith_att: `${lexURL}/lith-atts`,
96+
concept: `${lexURL}/strat-name-concepts`,
97+
interval: `${lexURL}/intervals`,
98+
},
99+
autoSelect: ["sandstone", "structure"],
100+
},
101+
};
102+
80103
export const TestData2: StoryObj<{}> = {
81104
args: {
82105
data: data2,

0 commit comments

Comments
 (0)