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

feat: node edition update #2606

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
27 changes: 16 additions & 11 deletions src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { validateImageInputType } from '~/components/ModalsContainer/EditNodeNameModal/utils'
import { Flex } from '~/components/common/Flex'
import { getTopicsData, putNodeData } from '~/network/fetchSourcesData'
import { editNodeData, getTopicsData } from '~/network/fetchSourcesData'
import { useDataStore } from '~/stores/useDataStore'
import { useSelectedNode } from '~/stores/useGraphStore'
import { useModal } from '~/stores/useModalStore'
import { NodeExtended, Topic } from '~/types'
import { NodeEditRequest, NodeExtended, Topic } from '~/types'
import { colors } from '~/utils/colors'
import { TitleEditor } from '../Title'

Expand Down Expand Up @@ -84,25 +84,30 @@ export const Body = () => {
const node = actualTopicNode || selectedNode

const handleSave = async () => {
if (!node) {
return
}

setLoading(true)

const updatedData = getValues()
const formData: FormData = getValues()

const nodeData = {
node_type: node?.node_type,
node_data: {
name: updatedData.name,
properties: updatedData.properties,
ref_id: updatedData.ref_id,
},
properties: formData.properties,
}

try {
await putNodeData(node?.ref_id || '', nodeData)
const payloadData: NodeEditRequest = {
node_type: node.node_type,
ref_id: node.ref_id,
properties: nodeData.properties as { [key: string]: unknown },
}

await editNodeData(node?.ref_id || '', payloadData)

const { updateNode } = useDataStore.getState()

updateNode({ ...node, ...nodeData.node_data } as NodeExtended)
updateNode({ ...node, ...nodeData } as unknown as NodeExtended)

closeHandler()
} catch (error) {
Expand Down
7 changes: 7 additions & 0 deletions src/network/fetchSourcesData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
FetchEdgeTypesResponse,
FetchRadarResponse,
FetchTopicResponse,
NodeEditRequest,
NodeExtended,
NodeRequest,
RadarRequest,
Expand Down Expand Up @@ -306,6 +307,12 @@ export const putNodeData = async (ref_id: string, data: NodeRequest) => {
return response
}

export const editNodeData = async (ref_id: string, data: NodeEditRequest) => {
const response = await api.put(`/node?ref_id=${ref_id}`, JSON.stringify(data))

return response
}

export const approveRadarData = async (id: string, pubkey: string) => {
const response = await api.put(`/radar/${id}/approve`, JSON.stringify({ approve: 'True', pubkey }))

Expand Down
8 changes: 8 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ export type NodeRequest = {
}
}

export type NodeEditRequest = {
node_type: string
ref_id: string
properties: {
[key: string]: unknown
}
}

export type DataSeriesNode = {
id: string
image_url?: string
Expand Down
Loading