import React, { Component } from 'react'; import { RouteComponentProps } from 'react-router'; import { Link } from 'react-router-dom'; import IndexUtil, { Index, INDEX_ID_PUBLIC } from '../../common/IndexUtil'; import ItemUtil, { SortCondition, SearchCallbackFunc } from '../../common/ItemUtil'; import DatabaseListIndex from './DatabaseListIndex'; import DatabaseListItem from './DatabaseListItem'; interface Props extends RouteComponentProps<{ id: string }> { } interface State { index: Index | null; } class DatabaseSearchByIndexId extends Component { constructor(props: Props) { super(props); const { params } = this.props.match; const indexId = params.id ? parseInt(params.id, 10) : INDEX_ID_PUBLIC; this.state = { index: IndexUtil.get(indexId), } this.search = this.search.bind(this); } componentWillReceiveProps(nextProps: Props) { const { params } = nextProps.match; const indexId = params.id ? parseInt(params.id, 10) : INDEX_ID_PUBLIC; const index = IndexUtil.get(indexId); this.setState({ index }); } getUrl() { if (this.state.index === null) { return '/'; } return IndexUtil.getUrl(this.state.index.id); } async search(condition: SortCondition, callback: SearchCallbackFunc) { if (this.state.index === null) { return { total: 0, data: [] }; } const items = ItemUtil.getListByIndexId(this.state.index.id, condition, callback); return items; } render() { if (this.state.index === null) { return null; } const baseUrl = this.getUrl(); const pIndexes = IndexUtil.getParents(this.state.index.id); const parents = pIndexes.map((value: Index) => { const url: string = IndexUtil.getUrl(value.id); return / {value.title}  }); return (

Listing item

{parents}
); } } export default DatabaseSearchByIndexId;