Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Node Update API Payload Structure and Data Handling #2596

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 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 @@ -86,14 +86,27 @@ export const Body = () => {
const handleSave = async () => {
setLoading(true)

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

const nodeData = {
node_type: node?.node_type,
properties: {
name: formData.name?.trim(),
...(formData.image_url && { image_url: formData.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: formData.name?.trim(),
...(formData.image_url && { image_url: formData.image_url }),
} as NodeExtended)

closeHandler()
} catch (error) {
Expand Down
31 changes: 29 additions & 2 deletions src/stores/useDataStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,12 +370,39 @@
setSources: (sources) => set({ sources }),
setHideNodeDetails: (hideNodeDetails) => set({ hideNodeDetails }),
setSeedQuestions: (questions) => set({ seedQuestions: questions }),
updateNode: (updatedNode) => {
console.info(updatedNode)
updateNode: (updatedNode: NodeExtended) => {
set((state) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const { nodesNormalized } = get()
nodesNormalized.set(...)

set({ nodeNormalized })

dm me if I missing something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rassl Please review again

const nodesNormalized = new Map(state.nodesNormalized)
aliraza556 marked this conversation as resolved.
Show resolved Hide resolved

if (updatedNode.ref_id) {
const existingNode = nodesNormalized.get(updatedNode.ref_id)

if (existingNode) {
nodesNormalized.set(updatedNode.ref_id, {
...existingNode,
...updatedNode,
})
}
}

const dataInitial = state.dataInitial
? {
...state.dataInitial,
nodes: state.dataInitial.nodes.map((node) =>
node.ref_id === updatedNode.ref_id ? { ...node, ...updatedNode } : node,
),
}
: null

return {
nodesNormalized,
dataInitial,
}
})
},

removeNode: (id) => {
console.log(id)

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 405 in src/stores/useDataStore/index.ts

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
},

setRunningProjectId: (runningProjectId) => set({ runningProjectId, runningProjectMessages: [] }),
Expand Down
Loading