Skip to content

Commit 06ef2a3

Browse files
committed
feat: Edit Sticky Note Content
1 parent 58de8d8 commit 06ef2a3

1 file changed

Lines changed: 62 additions & 7 deletions

File tree

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

Lines changed: 62 additions & 7 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 {
@@ -26,7 +31,7 @@ export const FlexNodeEditor = ({
2631
Sticky Note
2732
</Text>
2833

29-
<ContentEditor properties={properties} readOnly={readOnly} />
34+
<ContentEditor flexNode={flexNode} readOnly={readOnly} />
3035

3136
<ColorEditor properties={properties} readOnly={readOnly} />
3237

@@ -55,12 +60,59 @@ export const FlexNodeEditor = ({
5560
};
5661

5762
const ContentEditor = ({
58-
properties,
63+
flexNode,
5964
readOnly,
6065
}: {
61-
properties: FlexNodeData["properties"];
66+
flexNode: FlexNodeData;
6267
readOnly: boolean;
6368
}) => {
69+
const {
70+
componentSpec,
71+
currentSubgraphSpec,
72+
currentSubgraphPath,
73+
setComponentSpec,
74+
} = useComponentSpec();
75+
76+
const { properties } = flexNode;
77+
78+
const [title, setTitle] = useState(properties.title);
79+
const [content, setContent] = useState(properties.content);
80+
81+
const handleTitleChange = (e: ChangeEvent<HTMLInputElement>) => {
82+
setTitle(e.target.value);
83+
};
84+
85+
const handleContentChange = (e: ChangeEvent<HTMLTextAreaElement>) => {
86+
setContent(e.target.value);
87+
};
88+
89+
const saveChanges = () => {
90+
const updatedSubgraphSpec = updateFlexNodeInComponentSpec(
91+
currentSubgraphSpec,
92+
{
93+
...flexNode,
94+
properties: {
95+
...properties,
96+
title,
97+
content,
98+
},
99+
},
100+
);
101+
102+
const newRootSpec = updateSubgraphSpec(
103+
componentSpec,
104+
currentSubgraphPath,
105+
updatedSubgraphSpec,
106+
);
107+
108+
setComponentSpec(newRootSpec);
109+
};
110+
111+
useEffect(() => {
112+
setTitle(properties.title);
113+
setContent(properties.content);
114+
}, [properties]);
115+
64116
if (readOnly) {
65117
return (
66118
<KeyValueList
@@ -72,6 +124,7 @@ const ContentEditor = ({
72124
copyable: true,
73125
},
74126
{
127+
label: "Note",
75128
value: properties.content,
76129
copyable: true,
77130
},
@@ -92,9 +145,10 @@ const ContentEditor = ({
92145
</Label>
93146
<Input
94147
id="flex-node-title"
95-
value={properties.title}
148+
value={title}
149+
onChange={handleTitleChange}
150+
onBlur={saveChanges}
96151
className="text-sm"
97-
readOnly
98152
/>
99153
</BlockStack>
100154
<BlockStack>
@@ -106,9 +160,10 @@ const ContentEditor = ({
106160
</Label>
107161
<Textarea
108162
id="flex-node-content"
109-
value={properties.content}
163+
value={content}
164+
onChange={handleContentChange}
165+
onBlur={saveChanges}
110166
className="text-xs"
111-
readOnly
112167
/>
113168
</BlockStack>
114169
</BlockStack>

0 commit comments

Comments
 (0)