From e3d38f06eb0b0f1b8cc82b9b83df48c91670dddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Fri, 10 Jan 2025 17:47:18 +0300 Subject: [PATCH 1/3] feat: node edition update --- .../EditNodeNameModal/Body/index.tsx | 25 +++++++++++-------- src/types/index.ts | 10 +++----- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx index 5abb8288d..c58e35b9e 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx @@ -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' @@ -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: NodeRequest = { + node_type: node.node_type, + ref_id: node.ref_id, + properties: nodeData.properties as { [key: string]: unknown }, + } + + await putNodeData(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) { diff --git a/src/types/index.ts b/src/types/index.ts index 3df5b7400..70e40cd69 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -109,12 +109,10 @@ export type RadarRequest = { } export type NodeRequest = { - node_type?: string - node_data: { - name?: string - is_muted?: boolean - topic?: string - image_url?: string + node_type: string + ref_id: string + properties: { + [key: string]: unknown } } From eb837055b805e2c59bdc017f3f59bb1ebf7d4bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Fri, 10 Jan 2025 17:54:00 +0300 Subject: [PATCH 2/3] feat: node edition update --- .../ModalsContainer/EditNodeNameModal/Body/index.tsx | 4 ++-- src/types/index.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx index c58e35b9e..8b626eaaa 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx @@ -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, NodeRequest, Topic } from '~/types' +import { NodeEditRequest, NodeExtended, Topic } from '~/types' import { colors } from '~/utils/colors' import { TitleEditor } from '../Title' @@ -97,7 +97,7 @@ export const Body = () => { } try { - const payloadData: NodeRequest = { + const payloadData: NodeEditRequest = { node_type: node.node_type, ref_id: node.ref_id, properties: nodeData.properties as { [key: string]: unknown }, diff --git a/src/types/index.ts b/src/types/index.ts index 70e40cd69..a4bec20c2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -109,6 +109,16 @@ export type RadarRequest = { } export type NodeRequest = { + node_type?: string + node_data: { + name?: string + is_muted?: boolean + topic?: string + image_url?: string + } +} + +export type NodeEditRequest = { node_type: string ref_id: string properties: { From 136bfe207b14b59146b8f83ce55d61ff457bd213 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=B0=D1=81=D1=83=D0=BB?= Date: Fri, 10 Jan 2025 17:58:05 +0300 Subject: [PATCH 3/3] feat: fix build error --- .../ModalsContainer/EditNodeNameModal/Body/index.tsx | 4 ++-- src/network/fetchSourcesData/index.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx index 8b626eaaa..20459e305 100644 --- a/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx +++ b/src/components/ModalsContainer/EditNodeNameModal/Body/index.tsx @@ -5,7 +5,7 @@ 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' @@ -103,7 +103,7 @@ export const Body = () => { properties: nodeData.properties as { [key: string]: unknown }, } - await putNodeData(node?.ref_id || '', payloadData) + await editNodeData(node?.ref_id || '', payloadData) const { updateNode } = useDataStore.getState() diff --git a/src/network/fetchSourcesData/index.ts b/src/network/fetchSourcesData/index.ts index 1a41c5d0f..737446094 100644 --- a/src/network/fetchSourcesData/index.ts +++ b/src/network/fetchSourcesData/index.ts @@ -5,6 +5,7 @@ import { FetchEdgeTypesResponse, FetchRadarResponse, FetchTopicResponse, + NodeEditRequest, NodeExtended, NodeRequest, RadarRequest, @@ -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 }))