8
8
Typography ,
9
9
Link ,
10
10
Tooltip ,
11
+ Select ,
11
12
} from "@mui/material" ;
12
13
import SaveRoundedIcon from "@mui/icons-material/SaveRounded" ;
13
14
import LoadingButton from "@mui/lab/LoadingButton" ;
@@ -16,6 +17,7 @@ import CheckIcon from "@mui/icons-material/Check";
16
17
import InfoRoundedIcon from "@mui/icons-material/InfoRounded" ;
17
18
import { ContentModel } from "../../../../../shell/services/types" ;
18
19
import { useUpdateContentModelMutation } from "../../../../../shell/services/instance" ;
20
+ import { SelectModelParentInput } from "./SelectModelParentInput" ;
19
21
20
22
interface Props {
21
23
model : ContentModel ;
@@ -24,15 +26,31 @@ interface Props {
24
26
export const FieldsListRight = ( { model } : Props ) => {
25
27
const [ description , setDescription ] = useState ( "" ) ;
26
28
const [ isCopied , setIsCopied ] = useState ( null ) ;
29
+ const [ newParentZUID , setNewParentZUID ] = useState ( null ) ;
30
+ const [ showSaveParentModelButton , setshowSaveParentModelButton ] =
31
+ useState ( false ) ;
27
32
28
- const [ updateContentModel , { isLoading } ] = useUpdateContentModelMutation ( ) ;
33
+ useEffect ( ( ) => {
34
+ if ( model ?. parentZUID ) {
35
+ setNewParentZUID ( model . parentZUID === "0" ? null : model . parentZUID ) ;
36
+ }
37
+ } , [ model ] ) ;
38
+
39
+ const [ updateContentModel , { isLoading, isSuccess } ] =
40
+ useUpdateContentModelMutation ( ) ;
29
41
30
42
useEffect ( ( ) => {
31
43
if ( model ?. description ) {
32
44
setDescription ( model ?. description || "" ) ;
33
45
}
34
46
} , [ model ] ) ;
35
47
48
+ useEffect ( ( ) => {
49
+ if ( isSuccess ) {
50
+ setshowSaveParentModelButton ( false ) ;
51
+ }
52
+ } , [ isSuccess ] ) ;
53
+
36
54
const handleCopyClick = ( data : string ) => {
37
55
navigator ?. clipboard
38
56
?. writeText ( data )
@@ -47,11 +65,28 @@ export const FieldsListRight = ({ model }: Props) => {
47
65
} ) ;
48
66
} ;
49
67
50
- const handleSave = ( ) => {
51
- const body = {
52
- ...model ,
53
- description,
54
- } ;
68
+ const handleSave = ( type : "description" | "parentZUID" ) => {
69
+ let body = { ...model } ;
70
+
71
+ switch ( type ) {
72
+ case "description" :
73
+ body = {
74
+ ...body ,
75
+ description,
76
+ } ;
77
+ break ;
78
+
79
+ case "parentZUID" :
80
+ body = {
81
+ ...body ,
82
+ parentZUID : newParentZUID ?? "0" ,
83
+ } ;
84
+ break ;
85
+
86
+ default :
87
+ break ;
88
+ }
89
+
55
90
updateContentModel ( {
56
91
ZUID : model . ZUID ,
57
92
body,
@@ -140,6 +175,29 @@ export const FieldsListRight = ({ model }: Props) => {
140
175
) ,
141
176
} }
142
177
/>
178
+ < Box mt = { 3 } >
179
+ < SelectModelParentInput
180
+ modelType = { model ?. type }
181
+ value = { newParentZUID }
182
+ onChange = { ( value ) => {
183
+ setshowSaveParentModelButton ( value !== model ?. parentZUID ) ;
184
+ setNewParentZUID ( value ) ;
185
+ } }
186
+ label = "Model Parent"
187
+ />
188
+ { showSaveParentModelButton && (
189
+ < LoadingButton
190
+ color = "primary"
191
+ loading = { isLoading }
192
+ variant = "contained"
193
+ onClick = { ( ) => handleSave ( "parentZUID" ) }
194
+ sx = { { mt : 1.5 } }
195
+ >
196
+ Save
197
+ </ LoadingButton >
198
+ ) }
199
+ </ Box >
200
+
143
201
< InputLabel sx = { { mt : 3 } } >
144
202
Description
145
203
< Tooltip
@@ -166,7 +224,7 @@ export const FieldsListRight = ({ model }: Props) => {
166
224
startIcon = { < SaveRoundedIcon /> }
167
225
loadingPosition = "start"
168
226
variant = "contained"
169
- onClick = { handleSave }
227
+ onClick = { ( ) => handleSave ( "description" ) }
170
228
sx = { { mt : 1.5 } }
171
229
>
172
230
Save
0 commit comments