Skip to content

Commit

Permalink
Merge pull request #1766 from sophieturner0/PUT-node-formatting-change
Browse files Browse the repository at this point in the history
fix(changeNodeType ): PUT `/node` formatting change
  • Loading branch information
Rassl authored Jul 16, 2024
2 parents 1933de0 + e744c30 commit f1c088b
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/components/ModalsContainer/ChangeNodeTypeModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ const handleSubmitForm = async (
}
})

const properties: { [key: string]: unknown } = {}
const nodeData: { [key: string]: unknown } = {}

Object.keys(selectedNode || {}).forEach((selectedNodeKey) => {
const selectedNodeValue = selectedNode?.[selectedNodeKey as keyof NodeExtended]

Object.entries(swappedValues).forEach(([key, value]) => {
if (value === selectedNodeKey) {
properties[swappedValues[key]] = selectedNodeValue as string
nodeData[swappedValues[key]] = selectedNodeValue as string
}
})
})

Object.keys(requiredFieldsData).forEach((key) => {
if (key !== 'nodeType') {
properties[key] = requiredFieldsData[key]
nodeData[key] = requiredFieldsData[key]
}
})

Expand All @@ -65,7 +65,7 @@ const handleSubmitForm = async (

const body: { [index: string]: unknown } = {
node_type: nodeType,
properties,
node_data: nodeData,
properties_to_be_deleted: propertiesToBeDeleted,
type_to_be_deleted: typeName ? [typeName] : [],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const Body = () => {
const updatedData = { [propName]: topicValue.trim(), image_url: imageUrl.trim() }

try {
await putNodeData(node?.ref_id || '', updatedData)
await putNodeData(node?.ref_id || '', { node_data: updatedData })

const { updateNode } = useDataStore.getState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const EditTopicModal: FC<Props> = ({ topic, onClose }) => {
setLoading(true)

try {
await putNodeData(topic?.ref_id || '', { name })
await putNodeData(topic?.ref_id || '', { node_data: { name } })

if (data) {
const newData = { ...data }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const TableRowComponent: FC<TTableRaw> = ({
setLoading(true)

try {
await putNodeData(refId, { is_muted: shouldMute })
await putNodeData(refId, { node_data: { is_muted: shouldMute } })

useTopicsStore.setState({
ids: ids.filter((i) => i !== refId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const Table: React.FC<TopicTableProps> = ({

if (value) {
try {
await putNodeData(checkedId, { is_muted: !showMuted })
await putNodeData(checkedId, { node_data: { is_muted: !showMuted } })

return checkedId
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const TopicSources = () => {

const handleMute = async (refId: string, action: string) => {
try {
await putNodeData(refId, { is_muted: action === 'mute' })
await putNodeData(refId, { node_data: { is_muted: action === 'mute' } })
useTopicsStore.setState({ ids: ids.filter((i) => i !== refId), total: total - 1 })
} catch (error) {
console.warn(error)
Expand Down
10 changes: 6 additions & 4 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,12 @@ export type RadarRequest = {
}

export type NodeRequest = {
is_muted?: boolean
topic?: string
name?: string
image_url?: string
node_data: {
name?: string
is_muted?: boolean
topic?: string
image_url?: string
}
}

export type Node = {
Expand Down

0 comments on commit f1c088b

Please sign in to comment.