1+ import { type ChangeEvent , useEffect , useState } from "react" ;
2+
13import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock" ;
24import { KeyValueList } from "@/components/shared/ContextPanel/Blocks/KeyValueList" ;
35import { CopyText } from "@/components/shared/CopyText/CopyText" ;
@@ -6,7 +8,10 @@ import { Label } from "@/components/ui/label";
68import { BlockStack , InlineStack } from "@/components/ui/layout" ;
79import { Textarea } from "@/components/ui/textarea" ;
810import { Paragraph , Text } from "@/components/ui/typography" ;
11+ import { useComponentSpec } from "@/providers/ComponentSpecProvider" ;
12+ import { updateSubgraphSpec } from "@/utils/subgraphUtils" ;
913
14+ import { updateFlexNodeInComponentSpec } from "./interface" ;
1015import type { FlexNodeData } from "./types" ;
1116
1217interface FlexNodeEditorProps {
@@ -82,8 +87,53 @@ const ContentEditor = ({
8287 flexNode : FlexNodeData ;
8388 readOnly : boolean ;
8489} ) => {
90+ const {
91+ componentSpec,
92+ currentSubgraphSpec,
93+ currentSubgraphPath,
94+ setComponentSpec,
95+ } = useComponentSpec ( ) ;
96+
8597 const { properties } = flexNode ;
8698
99+ const [ title , setTitle ] = useState ( properties . title ) ;
100+ const [ content , setContent ] = useState ( properties . content ) ;
101+
102+ const handleTitleChange = ( e : ChangeEvent < HTMLInputElement > ) => {
103+ setTitle ( e . target . value ) ;
104+ } ;
105+
106+ const handleContentChange = ( e : ChangeEvent < HTMLTextAreaElement > ) => {
107+ setContent ( e . target . value ) ;
108+ } ;
109+
110+ const saveChanges = ( ) => {
111+ const updatedSubgraphSpec = updateFlexNodeInComponentSpec (
112+ currentSubgraphSpec ,
113+ {
114+ ...flexNode ,
115+ properties : {
116+ ...properties ,
117+ title,
118+ content,
119+ } ,
120+ } ,
121+ ) ;
122+
123+ const newRootSpec = updateSubgraphSpec (
124+ componentSpec ,
125+ currentSubgraphPath ,
126+ updatedSubgraphSpec ,
127+ ) ;
128+
129+ setComponentSpec ( newRootSpec ) ;
130+ } ;
131+
132+ useEffect ( ( ) => {
133+ setTitle ( properties . title ) ;
134+ setContent ( properties . content ) ;
135+ } , [ properties ] ) ;
136+
87137 if ( readOnly ) {
88138 return (
89139 < KeyValueList
@@ -95,6 +145,7 @@ const ContentEditor = ({
95145 copyable : true ,
96146 } ,
97147 {
148+ label : "Note" ,
98149 value : properties . content ,
99150 copyable : true ,
100151 } ,
@@ -115,9 +166,10 @@ const ContentEditor = ({
115166 </ Label >
116167 < Input
117168 id = "flex-node-title"
118- value = { properties . title }
169+ value = { title }
170+ onChange = { handleTitleChange }
171+ onBlur = { saveChanges }
119172 className = "text-sm"
120- readOnly
121173 />
122174 </ BlockStack >
123175 < BlockStack >
@@ -129,9 +181,10 @@ const ContentEditor = ({
129181 </ Label >
130182 < Textarea
131183 id = "flex-node-content"
132- value = { properties . content }
184+ value = { content }
185+ onChange = { handleContentChange }
186+ onBlur = { saveChanges }
133187 className = "text-xs"
134- readOnly
135188 />
136189 </ BlockStack >
137190 </ BlockStack >
0 commit comments