|
| 1 | +import React from 'react'; |
| 2 | +import PropTypes from 'prop-types'; |
| 3 | +import {Breadcrumb, Table, Button} from 'antd'; |
| 4 | +import { NavLink } from 'react-router-dom'; |
| 5 | +import CatalogApi from '../../api/catalogApi'; |
| 6 | + |
| 7 | + |
| 8 | +function getBreadcrumbs(catalog = 'Catalog') { |
| 9 | + return ( |
| 10 | + <Breadcrumb style={{margin: '12px 0'}}> |
| 11 | + <Breadcrumb.Item><NavLink to="/">Catalogs</NavLink></Breadcrumb.Item> |
| 12 | + <Breadcrumb.Item>{catalog}</Breadcrumb.Item> |
| 13 | + </Breadcrumb> |
| 14 | + ); |
| 15 | +} |
| 16 | + |
| 17 | +class CatalogPage extends React.Component { |
| 18 | + constructor(props) { |
| 19 | + super(props); |
| 20 | + |
| 21 | + this.columns = [ |
| 22 | + { |
| 23 | + dataIndex: 'displayName', |
| 24 | + key: '_id' |
| 25 | + }, |
| 26 | + { |
| 27 | + key: 'action', |
| 28 | + width: "100px", |
| 29 | + onCellClick: (record, event) => { |
| 30 | + if ( |
| 31 | + event.target.matches('.anticon-edit') || |
| 32 | + (event.target.firstElementChild && |
| 33 | + event.target.firstElementChild.matches('.anticon-edit')) |
| 34 | + ) { |
| 35 | + this.edit(record); |
| 36 | + |
| 37 | + } else if ( |
| 38 | + event.target.matches('.anticon-delete') || |
| 39 | + (event.target.firstElementChild && |
| 40 | + event.target.firstElementChild.matches('.anticon-delete')) |
| 41 | + ) { |
| 42 | + this.remove(record); |
| 43 | + } |
| 44 | + }, |
| 45 | + render: (text, record) => ( |
| 46 | + <span> |
| 47 | + <Button type="primary" icon="edit" style={{margin: "0 5px"}}/> |
| 48 | + <Button type="danger" icon="delete" style={{margin: "0 5px"}}/> |
| 49 | + </span> |
| 50 | + ) |
| 51 | + } |
| 52 | + ]; |
| 53 | + |
| 54 | + this.state = { |
| 55 | + catalog: {}, |
| 56 | + extent: [] |
| 57 | + }; |
| 58 | + } |
| 59 | + |
| 60 | + componentDidMount() { |
| 61 | + const name = this.props.match.params.name; |
| 62 | + |
| 63 | + CatalogApi.getCatalogInfo(name) |
| 64 | + .then((response) => { |
| 65 | + this.setState({catalog: response.data}); |
| 66 | + return CatalogApi.getCatalogExtent(name); |
| 67 | + }) |
| 68 | + .then((response) => { |
| 69 | + this.setState({extent: response.data.children}); |
| 70 | + }); |
| 71 | + } |
| 72 | + |
| 73 | + edit = (record) => { |
| 74 | + const path = this.props.location.pathname; |
| 75 | + this.props.history.replace(`${path}/object/${record._id}`); |
| 76 | + }; |
| 77 | + |
| 78 | + remove = (record) => { |
| 79 | + console.log('Remove item:' + record); |
| 80 | + }; |
| 81 | + |
| 82 | + render() { |
| 83 | + return ( |
| 84 | + <div> |
| 85 | + {getBreadcrumbs(this.state.catalog.name)} |
| 86 | + |
| 87 | + <div style={{background: '#fff', padding: 24, minHeight: 280}}> |
| 88 | + |
| 89 | + <div className="clearfix" style={{width: "100%"}}> |
| 90 | + <h2 style={{display: "inline"}}> |
| 91 | + {this.state.catalog.name || '...'} |
| 92 | + </h2> |
| 93 | + <Button type="primary" |
| 94 | + style={{float: 'right', marginBottom: 8}} |
| 95 | + size="small" |
| 96 | + onClick={this.handleAdd} |
| 97 | + className="clearfix" |
| 98 | + > |
| 99 | + Add |
| 100 | + </Button> |
| 101 | + </div> |
| 102 | + |
| 103 | + <Table |
| 104 | + rowKey="_id" |
| 105 | + dataSource={this.state.extent} |
| 106 | + columns={this.columns} |
| 107 | + showHeader={false} |
| 108 | + bordered |
| 109 | + size="middle" |
| 110 | + pagination={{showSizeChanger: true}} |
| 111 | + /> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + ); |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +CatalogPage.propTypes = { |
| 119 | + history: PropTypes.object, |
| 120 | + match: PropTypes.object, |
| 121 | + location: PropTypes.object |
| 122 | +}; |
| 123 | + |
| 124 | +export default CatalogPage; |
0 commit comments