/
SourceHomeChildrenList.jsx
55 lines (48 loc) · 1.3 KB
/
SourceHomeChildrenList.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React from 'react';
import Search from '../search/Search';
import VersionFilter from '../common/VersionFilter';
import { map, includes } from 'lodash';
class SourceHomeChildrenList extends React.Component {
constructor(props) {
super(props);
this.state = {
selectedVersion: this.props.currentVersion || 'HEAD'
}
}
getURL() {
const { selectedVersion } = this.state;
const { versionedObjectURL, resource } = this.props;
let url = versionedObjectURL;
if(selectedVersion && !includes(['HEAD', 'concepts', 'mappings', 'about', 'history'], selectedVersion))
url += `${selectedVersion}/`
url += `${resource}/`
return url
}
onChange = version => {
this.setState({selectedVersion: version || 'HEAD'})
}
getExtraControls() {
const { selectedVersion } = this.state;
const { versions } = this.props;
return (
<VersionFilter
size='small'
onChange={this.onChange}
versions={map(versions, 'id')}
selected={selectedVersion}
/>
)
}
render() {
return (
<Search
{...this.props}
nested={true}
baseURL={this.getURL()}
fixedFilters={{isTable: true, limit: 25}}
extraControls={this.getExtraControls()}
/>
)
}
}
export default SourceHomeChildrenList;