@@ -15,7 +15,9 @@ export class ManageCatalogPage extends React.Component {
1515 catalogPath : `/catalog/${ this . props . match . params . name } ` ,
1616 collections : { } ,
1717 isTouched : false ,
18- form : { name : '' } ,
18+ form : {
19+ name : ''
20+ } ,
1921 errors : { } ,
2022 saving : false ,
2123 loading : true
@@ -35,11 +37,26 @@ export class ManageCatalogPage extends React.Component {
3537 }
3638 } ) ;
3739
38- return CatalogApi . getFormObjectById ( this . props . match . params . name , this . props . match . params . id ) ;
40+ const id = this . props . match . params . id ;
41+ const name = this . props . match . params . name ;
42+
43+ if ( id ) {
44+ return CatalogApi . getFormObjectById ( name , id ) ;
45+ }
46+
47+ return { data : { _class : this . state . catalog . class } } ;
3948 } )
4049
41- . then ( ( response ) => {
42- this . setState ( { form : response . data , loading : false } ) ;
50+ . then ( ( { data} ) => {
51+ this . setState ( { form : data , loading : false } ) ;
52+ } )
53+
54+ . catch ( ( { response} ) => {
55+ const summary = ( response && response . data && response . data . summary ) ;
56+
57+ notification . error ( {
58+ message : 'An error has occurred: ' + summary
59+ } ) ;
4360 } ) ;
4461 }
4562
@@ -83,7 +100,17 @@ export class ManageCatalogPage extends React.Component {
83100
84101 this . setState ( { saving : true } ) ;
85102
86- CatalogApi . saveCatalog ( this . props . match . params . name , this . props . match . params . id , this . state . form )
103+ let promise ;
104+ const name = this . props . match . params . name ;
105+ const id = this . props . match . params . id ;
106+
107+ if ( id ) {
108+ promise = CatalogApi . updateObject ( name , id , this . state . form ) ;
109+ } else {
110+ promise = CatalogApi . saveObject ( name , this . state . form ) ;
111+ }
112+
113+ promise
87114 . then ( ( ) => {
88115 notification . success ( {
89116 message : 'Saved successfully!'
@@ -145,7 +172,7 @@ export class ManageCatalogPage extends React.Component {
145172
146173 { ! this . state . loading &&
147174 < div >
148- { ! this . props . match . params . id && < h1 > ' { this . state . catalog . name } : creating new object' </ h1 > }
175+ { ! this . props . match . params . id && < h1 > { this . state . catalog . name } : creating new object</ h1 > }
149176
150177 { this . props . match . params . id &&
151178 ( this . state . catalog . objpermissions . indexOf ( 'U' ) !== - 1 ) &&
0 commit comments