Skip to content

Commit

Permalink
fix(node): update node data payload and store state management
Browse files Browse the repository at this point in the history
  • Loading branch information
aliraza556 committed Jan 7, 2025
1 parent d8b67e1 commit ddc3109
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ export const Body = () => {
const handleSave = async () => {
setLoading(true)

const formData = getValues()
const updatedData = getValues()

const nodeData = {
node_type: node?.node_type,
properties: {
name: formData.name?.trim(),
...(formData.image_url && { image_url: formData.image_url }),
name: updatedData.name,
...(updatedData.image_url && { image_url: updatedData.image_url }),
},
ref_id: node?.ref_id,
}
Expand All @@ -104,8 +104,8 @@ export const Body = () => {

updateNode({
...node,
name: formData.name?.trim(),
...(formData.image_url && { image_url: formData.image_url }),
name: updatedData.name,
...(updatedData.image_url && { image_url: updatedData.image_url }),
} as NodeExtended)

closeHandler()
Expand Down
21 changes: 5 additions & 16 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,25 +370,14 @@ export const useDataStore = create<DataStore>()(
setSources: (sources) => set({ sources }),
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode: NodeExtended) => {
set((state) => {
if (!updatedNode.ref_id) {
return state
}

const existingNode = state.nodesNormalized.get(updatedNode.ref_id)
updateNode: (updatedNode) => {
const { nodesNormalized } = get()

if (!existingNode) {
return state
}
const newNodesNormalized = new Map(nodesNormalized)

state.nodesNormalized.set(updatedNode.ref_id, {
...existingNode,
...updatedNode,
})
newNodesNormalized.set(updatedNode.ref_id, updatedNode)

return state
})
set({ nodesNormalized: newNodesNormalized })
},

removeNode: (id) => {
Expand Down

0 comments on commit ddc3109

Please sign in to comment.