Pass uid down from parent.
This fixes an issue where lists of nodes did not have the key attribute.
This commit is contained in:
parent
aac0ebe619
commit
c397688a4a
@ -1,5 +1,4 @@
|
||||
import React, { ReactNode, useState } from "react";
|
||||
import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
|
||||
import styles from "./OrgAst.module.css";
|
||||
|
||||
const OrgAst = (props: {
|
||||
@ -21,9 +20,10 @@ const OrgAst = (props: {
|
||||
return (
|
||||
<div className={styles.OrgAst}>
|
||||
<OrgAstNode
|
||||
key="^"
|
||||
uid="^"
|
||||
selectNode={selectNode}
|
||||
node={props.astTree.content}
|
||||
parentUniqueId="^"
|
||||
selectedNode={selectedNode}
|
||||
/>
|
||||
</div>
|
||||
@ -34,29 +34,19 @@ const OrgAst = (props: {
|
||||
const OrgAstNode = (props: {
|
||||
selectNode: Function;
|
||||
node: any;
|
||||
parentUniqueId: string;
|
||||
uid: string;
|
||||
selectedNode: string;
|
||||
}) => {
|
||||
const uid =
|
||||
props.parentUniqueId +
|
||||
"_" +
|
||||
props.node["ast-node"] +
|
||||
"/" +
|
||||
props.node["standard-properties"]["begin"] +
|
||||
"/" +
|
||||
props.node["standard-properties"]["end"] +
|
||||
"#";
|
||||
|
||||
function selectNode() {
|
||||
props.selectNode(
|
||||
uid,
|
||||
props.uid,
|
||||
props.node["standard-properties"]["begin"] - 1,
|
||||
props.node["standard-properties"]["end"] - 1,
|
||||
);
|
||||
}
|
||||
|
||||
const nodeClassName =
|
||||
props.selectedNode === uid
|
||||
props.selectedNode === props.uid
|
||||
? styles.OrgAstNode + " " + styles.selected
|
||||
: styles.OrgAstNode;
|
||||
|
||||
@ -86,7 +76,7 @@ const OrgAstNode = (props: {
|
||||
<div className={styles.OrgAstChildren}>
|
||||
<OrgAstNodeList
|
||||
selectNode={props.selectNode}
|
||||
parentUniqueId={uid}
|
||||
parentUniqueId={props.uid}
|
||||
selectedNode={props.selectedNode}
|
||||
node_list={props.node.children}
|
||||
/>
|
||||
@ -104,10 +94,20 @@ const OrgAstNodeList = (props: {
|
||||
node_list: any[];
|
||||
}): React.JSX.Element[] => {
|
||||
return props.node_list.map((node) => {
|
||||
const uid =
|
||||
props.parentUniqueId +
|
||||
"_" +
|
||||
node["ast-node"] +
|
||||
"/" +
|
||||
node["standard-properties"]["begin"] +
|
||||
"/" +
|
||||
node["standard-properties"]["end"] +
|
||||
"#";
|
||||
return (
|
||||
<OrgAstNode
|
||||
key={uid}
|
||||
uid={uid}
|
||||
selectNode={props.selectNode}
|
||||
parentUniqueId={props.parentUniqueId}
|
||||
selectedNode={props.selectedNode}
|
||||
node={node}
|
||||
/>
|
||||
|
Loading…
x
Reference in New Issue
Block a user