Skip to content

Commit

Permalink
Merge pull request #2596 from aliraza556/fix/node-update-payload-stru…
Browse files Browse the repository at this point in the history
…cture

Fix: Node Update API Payload Structure and Data Handling
  • Loading branch information
Rassl authored Jan 7, 2025
2 parents 3108c37 + ddc3109 commit 8d0a0b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getTopicsData, putNodeData } from '~/network/fetchSourcesData'
import { useDataStore } from '~/stores/useDataStore'
import { useSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { NodeExtended, Topic } from '~/types'
import { NodeExtended, NodeRequest, Topic } from '~/types'
import { colors } from '~/utils/colors'
import { TitleEditor } from '../Title'

Expand Down Expand Up @@ -88,12 +88,25 @@ export const Body = () => {

const updatedData = getValues()

const nodeData = {
node_type: node?.node_type,
properties: {
name: updatedData.name,
...(updatedData.image_url && { image_url: updatedData.image_url }),
},
ref_id: node?.ref_id,
}

try {
await putNodeData(node?.ref_id || '', { node_type: node?.node_type, node_data: updatedData })
await putNodeData(node?.ref_id || '', nodeData as unknown as NodeRequest)

const { updateNode } = useDataStore.getState()

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

closeHandler()
} catch (error) {
Expand Down
8 changes: 7 additions & 1 deletion src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,13 @@ export const useDataStore = create<DataStore>()(
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode) => {
console.info(updatedNode)
const { nodesNormalized } = get()

const newNodesNormalized = new Map(nodesNormalized)

newNodesNormalized.set(updatedNode.ref_id, updatedNode)

set({ nodesNormalized: newNodesNormalized })
},

removeNode: (id) => {
Expand Down

0 comments on commit 8d0a0b7

Please sign in to comment.