Skip to content

Commit 7146fbc

Browse files
committed
feat: Edit Sticky Note Content
1 parent c7fd228 commit 7146fbc

1 file changed

Lines changed: 57 additions & 4 deletions

File tree

src/components/shared/ReactFlow/FlowCanvas/FlexNode/FlexNodeEditor.tsx

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { type ChangeEvent, useEffect, useState } from "react";
2+
13
import { ContentBlock } from "@/components/shared/ContextPanel/Blocks/ContentBlock";
24
import { KeyValueList } from "@/components/shared/ContextPanel/Blocks/KeyValueList";
35
import { CopyText } from "@/components/shared/CopyText/CopyText";
@@ -6,7 +8,10 @@ import { Label } from "@/components/ui/label";
68
import { BlockStack, InlineStack } from "@/components/ui/layout";
79
import { Textarea } from "@/components/ui/textarea";
810
import { Paragraph, Text } from "@/components/ui/typography";
11+
import { useComponentSpec } from "@/providers/ComponentSpecProvider";
12+
import { updateSubgraphSpec } from "@/utils/subgraphUtils";
913

14+
import { updateFlexNodeInComponentSpec } from "./interface";
1015
import type { FlexNodeData } from "./types";
1116

1217
interface 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

Comments
 (0)