@@ -3,6 +3,7 @@ import React, { useEffect, useState } from "react";
3
3
import { TreeView , TreeItem } from "@material-ui/lab" ;
4
4
import { useFetchContext } from "../context" ;
5
5
import { apiUrl } from "../routes" ;
6
+ import { Link } from "react-router-dom" ;
6
7
7
8
const CreateObject = ( { parentPid = "" , allowNoParentPid = false , allowChangeParentPid = true } ) => {
8
9
// Validate properties
@@ -17,7 +18,7 @@ const CreateObject = ({ parentPid = "", allowNoParentPid = false, allowChangePar
17
18
} = useFetchContext ( ) ;
18
19
const [ models , setModels ] = useState ( { } ) ;
19
20
const [ selectedModel , setSelectedModel ] = useState ( "" ) ;
20
- const [ results , setResults ] = useState ( "" ) ;
21
+ const [ results , setResults ] = useState ( ) ;
21
22
const [ title , setTitle ] = useState ( "" ) ;
22
23
const [ parent , setParent ] = useState ( parentPid ) ;
23
24
const [ noParent , setNoParent ] = useState ( allowNoParentPid && parentPid === "" ) ;
@@ -57,11 +58,17 @@ const CreateObject = ({ parentPid = "", allowNoParentPid = false, allowChangePar
57
58
model : selectedModel ,
58
59
state,
59
60
} ;
61
+ setResults ( "Working..." ) ;
60
62
try {
61
63
const params = { method : "POST" , body : JSON . stringify ( data ) } ;
62
64
const headers = { "Content-Type" : "application/json" } ;
63
65
const result = await makeRequest ( url , params , headers ) ;
64
- setResults ( await result . text ( ) ) ;
66
+ const pid = await result . text ( ) ;
67
+ setResults (
68
+ < span >
69
+ Object created: < Link to = { "/edit/object/" + pid } > { pid } </ Link >
70
+ </ span >
71
+ ) ;
65
72
} catch ( e ) {
66
73
setResults ( "Error: " + e . message ) ;
67
74
}
@@ -136,10 +143,12 @@ const CreateObject = ({ parentPid = "", allowNoParentPid = false, allowChangePar
136
143
< input type = "hidden" value = { parent } name = "parent" />
137
144
) ;
138
145
}
139
-
146
+ // If the form has completed, just display the result:
147
+ if ( results ) {
148
+ return results ;
149
+ }
140
150
return (
141
151
< form onSubmit = { handleSubmit } className = "editor__create-object" >
142
- { results && results . length > 0 ? < div > { "Results: " + results } </ div > : "" }
143
152
< label >
144
153
Title
145
154
< input type = "text" value = { title } name = "title" onChange = { handleTitleChange } required />
0 commit comments