Skip to content

Commit 5ae43f9

Browse files
committed
Deleting catalog object
1 parent bca8069 commit 5ae43f9

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

src/api/catalogApi.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class CatalogApi {
5353
});
5454
}
5555

56-
5756
static updateObject(catalogClass, id, catalog) {
5857
return axios({
5958
method: 'put',
@@ -69,6 +68,14 @@ class CatalogApi {
6968
data: catalog
7069
});
7170
}
71+
72+
static deleteObject(catalogClass, id) {
73+
return axios({
74+
method: 'delete',
75+
url: `${server}/form/object/${catalogClass}/${id}`
76+
});
77+
}
78+
7279
}
7380

7481
export default CatalogApi;

src/components/catalog/CatalogPage.js

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import { Breadcrumb, Table, Button, notification } from 'antd';
3+
import { Breadcrumb, Table, Button, notification, Modal } from 'antd';
44
import { NavLink } from 'react-router-dom';
55
import 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

Comments
 (0)