1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { Breadcrumb , Table , Button , notification } from 'antd' ;
3
+ import { Breadcrumb , Table , Button , notification , Modal } from 'antd' ;
4
4
import { NavLink } from 'react-router-dom' ;
5
5
import CatalogApi from '../../api/catalogApi' ;
6
6
@@ -60,23 +60,34 @@ class CatalogPage extends React.Component {
60
60
componentDidMount ( ) {
61
61
const name = this . props . match . params . name ;
62
62
63
- CatalogApi . getCatalogInfo ( name )
64
- . then ( ( response ) => {
65
- this . setState ( { catalog : response . data } ) ;
66
- return CatalogApi . getCatalogExtent ( name ) ;
67
- } )
68
-
69
- . then ( ( response ) => {
70
- this . setState ( { extent : response . data . children } ) ;
71
- } )
63
+ let promise = CatalogApi . getCatalogInfo ( name ) ;
64
+ promise = promise . then ( ( response ) => {
65
+ this . setState ( { catalog : response . data } ) ;
66
+ return this . loadCatalogExtent ( name , promise ) ;
67
+ } ) ;
72
68
73
- . catch ( ( error ) => {
74
- notification . error ( {
75
- message : 'An error has occurred: ' + error . summary
76
- } ) ;
69
+ promise . catch ( ( error ) => {
70
+ notification . error ( {
71
+ message : 'An error has occurred: ' + error . summary
77
72
} ) ;
73
+ } ) ;
78
74
}
79
75
76
+ loadCatalogExtent = ( name , promise ) => {
77
+ if ( promise ) {
78
+ promise = promise . then ( ( ) => {
79
+ return CatalogApi . getCatalogExtent ( name ) ;
80
+ } ) ;
81
+ }
82
+ else {
83
+ promise = CatalogApi . getCatalogExtent ( name ) ;
84
+ }
85
+
86
+ promise = promise . then ( ( response ) => {
87
+ this . setState ( { extent : response . data . children } ) ;
88
+ } ) ;
89
+ } ;
90
+
80
91
add = ( ) => {
81
92
const path = this . props . location . pathname ;
82
93
this . props . history . replace ( `${ path } /object` ) ;
@@ -88,7 +99,26 @@ class CatalogPage extends React.Component {
88
99
} ;
89
100
90
101
remove = ( record ) => {
91
- console . log ( 'Remove item:' + record ) ;
102
+ Modal . confirm ( {
103
+ title : 'Do you really want to remove this object?' ,
104
+ onOk : ( ) => {
105
+ CatalogApi . deleteObject ( this . state . catalog . class , record . _id )
106
+ . then ( ( ) => {
107
+ this . loadCatalogExtent ( this . props . match . params . name ) ;
108
+ notification . success ( {
109
+ message : 'Object removed successfully'
110
+ } ) ;
111
+
112
+ } )
113
+
114
+ . catch ( ( error ) => {
115
+ notification . error ( {
116
+ message : 'An error has occurred: ' + error . summary
117
+ } ) ;
118
+ } ) ;
119
+ } ,
120
+ style : { top : '40vh' }
121
+ } ) ;
92
122
} ;
93
123
94
124
render ( ) {
0 commit comments