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 React, { ReactNode, useState } from "react";
|
||||||
import { parse_org } from "../../organic/target/wasm32-unknown-unknown/js/wasm";
|
|
||||||
import styles from "./OrgAst.module.css";
|
import styles from "./OrgAst.module.css";
|
||||||
|
|
||||||
const OrgAst = (props: {
|
const OrgAst = (props: {
|
||||||
@ -21,9 +20,10 @@ const OrgAst = (props: {
|
|||||||
return (
|
return (
|
||||||
<div className={styles.OrgAst}>
|
<div className={styles.OrgAst}>
|
||||||
<OrgAstNode
|
<OrgAstNode
|
||||||
|
key="^"
|
||||||
|
uid="^"
|
||||||
selectNode={selectNode}
|
selectNode={selectNode}
|
||||||
node={props.astTree.content}
|
node={props.astTree.content}
|
||||||
parentUniqueId="^"
|
|
||||||
selectedNode={selectedNode}
|
selectedNode={selectedNode}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -34,29 +34,19 @@ const OrgAst = (props: {
|
|||||||
const OrgAstNode = (props: {
|
const OrgAstNode = (props: {
|
||||||
selectNode: Function;
|
selectNode: Function;
|
||||||
node: any;
|
node: any;
|
||||||
parentUniqueId: string;
|
uid: string;
|
||||||
selectedNode: string;
|
selectedNode: string;
|
||||||
}) => {
|
}) => {
|
||||||
const uid =
|
|
||||||
props.parentUniqueId +
|
|
||||||
"_" +
|
|
||||||
props.node["ast-node"] +
|
|
||||||
"/" +
|
|
||||||
props.node["standard-properties"]["begin"] +
|
|
||||||
"/" +
|
|
||||||
props.node["standard-properties"]["end"] +
|
|
||||||
"#";
|
|
||||||
|
|
||||||
function selectNode() {
|
function selectNode() {
|
||||||
props.selectNode(
|
props.selectNode(
|
||||||
uid,
|
props.uid,
|
||||||
props.node["standard-properties"]["begin"] - 1,
|
props.node["standard-properties"]["begin"] - 1,
|
||||||
props.node["standard-properties"]["end"] - 1,
|
props.node["standard-properties"]["end"] - 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const nodeClassName =
|
const nodeClassName =
|
||||||
props.selectedNode === uid
|
props.selectedNode === props.uid
|
||||||
? styles.OrgAstNode + " " + styles.selected
|
? styles.OrgAstNode + " " + styles.selected
|
||||||
: styles.OrgAstNode;
|
: styles.OrgAstNode;
|
||||||
|
|
||||||
@ -86,7 +76,7 @@ const OrgAstNode = (props: {
|
|||||||
<div className={styles.OrgAstChildren}>
|
<div className={styles.OrgAstChildren}>
|
||||||
<OrgAstNodeList
|
<OrgAstNodeList
|
||||||
selectNode={props.selectNode}
|
selectNode={props.selectNode}
|
||||||
parentUniqueId={uid}
|
parentUniqueId={props.uid}
|
||||||
selectedNode={props.selectedNode}
|
selectedNode={props.selectedNode}
|
||||||
node_list={props.node.children}
|
node_list={props.node.children}
|
||||||
/>
|
/>
|
||||||
@ -104,10 +94,20 @@ const OrgAstNodeList = (props: {
|
|||||||
node_list: any[];
|
node_list: any[];
|
||||||
}): React.JSX.Element[] => {
|
}): React.JSX.Element[] => {
|
||||||
return props.node_list.map((node) => {
|
return props.node_list.map((node) => {
|
||||||
|
const uid =
|
||||||
|
props.parentUniqueId +
|
||||||
|
"_" +
|
||||||
|
node["ast-node"] +
|
||||||
|
"/" +
|
||||||
|
node["standard-properties"]["begin"] +
|
||||||
|
"/" +
|
||||||
|
node["standard-properties"]["end"] +
|
||||||
|
"#";
|
||||||
return (
|
return (
|
||||||
<OrgAstNode
|
<OrgAstNode
|
||||||
|
key={uid}
|
||||||
|
uid={uid}
|
||||||
selectNode={props.selectNode}
|
selectNode={props.selectNode}
|
||||||
parentUniqueId={props.parentUniqueId}
|
|
||||||
selectedNode={props.selectedNode}
|
selectedNode={props.selectedNode}
|
||||||
node={node}
|
node={node}
|
||||||
/>
|
/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user