11import React from 'react' ;
22import PropTypes from 'prop-types' ;
3- import { Breadcrumb , Table , Button , notification } from 'antd' ;
3+ import { Breadcrumb , Table , Button , notification , Modal } from 'antd' ;
44import { NavLink } from 'react-router-dom' ;
55import CatalogApi from '../../api/catalogApi' ;
66
@@ -60,23 +60,34 @@ class CatalogPage extends React.Component {
6060 componentDidMount ( ) {
6161 const name = this . props . match . params . name ;
6262
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+ } ) ;
7268
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
7772 } ) ;
73+ } ) ;
7874 }
7975
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+
8091 add = ( ) => {
8192 const path = this . props . location . pathname ;
8293 this . props . history . replace ( `${ path } /object` ) ;
@@ -88,7 +99,26 @@ class CatalogPage extends React.Component {
8899 } ;
89100
90101 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+ } ) ;
92122 } ;
93123
94124 render ( ) {
0 commit comments