From c0967c1c05298ba3fb506f2e7ef05073ed7c709b Mon Sep 17 00:00:00 2001 From: Marco Christian Krenn Date: Tue, 26 Nov 2024 13:14:58 +0100 Subject: [PATCH 1/6] fixes node title not changing --- .changeset/olive-rockets-repeat.md | 5 ++ .../components/panels/nodeSettings/index.tsx | 52 ++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 .changeset/olive-rockets-repeat.md diff --git a/.changeset/olive-rockets-repeat.md b/.changeset/olive-rockets-repeat.md new file mode 100644 index 00000000..05503e82 --- /dev/null +++ b/.changeset/olive-rockets-repeat.md @@ -0,0 +1,5 @@ +--- +"@tokens-studio/graph-editor": patch +--- + +fix token title not changes diff --git a/packages/graph-editor/src/components/panels/nodeSettings/index.tsx b/packages/graph-editor/src/components/panels/nodeSettings/index.tsx index 7534f7fe..d7bc8d16 100644 --- a/packages/graph-editor/src/components/panels/nodeSettings/index.tsx +++ b/packages/graph-editor/src/components/panels/nodeSettings/index.tsx @@ -81,34 +81,48 @@ const Annotations = observer(({ annotations }: Record) => { ); }); -const NodeTitle = ({ selectedNode }: { selectedNode: Node }) => { +const NodeTitle = observer(({ selectedNode }: { selectedNode: Node }) => { + const [localTitle, setLocalTitle] = React.useState( + (selectedNode.annotations[title] as string) || '', + ); + + // Update local state when the annotation changes + React.useEffect(() => { + setLocalTitle((selectedNode.annotations[title] as string) || ''); + }, [selectedNode.annotations[title]]); + const onChangeTitle = useCallback( - (e) => { - selectedNode.annotations[title] = e.target.value; + (e: React.ChangeEvent) => { + const newValue = e.target.value; + setLocalTitle(newValue); + selectedNode.setAnnotation(title, newValue); }, - [selectedNode.annotations], + [selectedNode], ); return ( - + ); -}; +}); + +const NodeDescription = observer(({ selectedNode }: { selectedNode: Node }) => { + const [localDescription, setLocalDescription] = React.useState( + (selectedNode.annotations[description] as string) || '', + ); + + // Update local state when the annotation changes + React.useEffect(() => { + setLocalDescription( + (selectedNode.annotations[description] as string) || '', + ); + }, [selectedNode.annotations[description]]); -const NodeDescription = ({ - selectedNode, - annotations, -}: { - selectedNode: Node; - annotations: Record; -}) => { const onChangeDesc = useCallback( (newString: string) => { + setLocalDescription(newString); selectedNode.setAnnotation(description, newString); }, [selectedNode], @@ -120,11 +134,11 @@ const NodeDescription = ({