1
1
import { Alert , Box , Snackbar , Typography , Button } from "@mui/material" ;
2
2
import SaveIcon from "@mui/icons-material/Save" ;
3
3
import CircularProgress from "@mui/material/CircularProgress" ;
4
- import { useState } from "react" ;
4
+ import { useMemo , useState } from "react" ;
5
5
import ListEntryParents from "./ListEntryParents" ;
6
6
import ListEntryChildren from "./ListEntryChildren" ;
7
7
import { ListTranslations } from "./ListTranslations" ;
@@ -12,6 +12,7 @@ import { createURL, getNodeType, toSnakeCase } from "@/utils";
12
12
import { useNavigate } from "react-router-dom" ;
13
13
import { useQuery } from "@tanstack/react-query" ;
14
14
import { DefaultService } from "@/client" ;
15
+ import { DestructuredEntryNode } from "@/backend-types/types" ;
15
16
16
17
interface AccumulateAllComponentsProps {
17
18
id : string ;
@@ -38,7 +39,7 @@ const AccumulateAllComponents = ({
38
39
const isEntry = getNodeType ( id ) === "entry" ;
39
40
40
41
const {
41
- data : node ,
42
+ data : rawNode ,
42
43
isPending,
43
44
isError,
44
45
error,
@@ -58,8 +59,29 @@ const AccumulateAllComponents = ({
58
59
) ;
59
60
} ,
60
61
} ) ;
61
- const [ nodeObject , setNodeObject ] = useState ( null ) ; // Storing updates to node
62
- const [ originalNodeObject , setOriginalNodeObject ] = useState ( null ) ; // For tracking changes
62
+
63
+ // Intermediate destructuring step. Migrate to @/client/models/EntryNode when possible
64
+ const node : DestructuredEntryNode | null = useMemo ( ( ) => {
65
+ if ( ! rawNode ) return null ;
66
+ const {
67
+ tags : _tags ,
68
+ properties : _properties ,
69
+ comments : _comments ,
70
+ ...destructuredNode
71
+ } = {
72
+ ...rawNode ,
73
+ ...rawNode . tags ,
74
+ ...rawNode . properties ,
75
+ ...rawNode . comments ,
76
+ } ;
77
+ return destructuredNode ;
78
+ } , [ rawNode ] ) ;
79
+
80
+ const [ nodeObject , setNodeObject ] = useState < DestructuredEntryNode | null > (
81
+ null
82
+ ) ; // Storing updates to node
83
+ const [ originalNodeObject , setOriginalNodeObject ] =
84
+ useState < DestructuredEntryNode | null > ( null ) ; // For tracking changes
63
85
const [ updateChildren , setUpdateChildren ] = useState ( null ) ; // Storing updates of children in node
64
86
const [ previousUpdateChildren , setPreviousUpdateChildren ] = useState ( null ) ; // Tracking changes of children
65
87
const [ open , setOpen ] = useState ( false ) ; // Used for Dialog component
@@ -118,8 +140,7 @@ const AccumulateAllComponents = ({
118
140
// Function handling updation of node
119
141
const handleSubmit = ( ) => {
120
142
if ( ! nodeObject ) return ;
121
- const data = Object . assign ( { } , nodeObject ) ;
122
- delete data [ "id" ] ; // ID not allowed in POST
143
+ const { id : _ , ...data } = { ...nodeObject } ; // ID not allowed in POST
123
144
124
145
const dataToBeSent = { } ;
125
146
// Remove UUIDs from data
0 commit comments