blob: 5f12aa0774bb51997bb09a93efc86d797ac344b2 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
import React from "react";
import { Button } from "semantic-ui-react";
import ObjectComponent from "./ObjectComponent";
import SearchForm from "./SearchForm";
class List extends React.Component {
constructor(props) {
super(props);
this.state = {
objects: [],
filter: {
field: "default-field",
value: ""
}
};
this.getData = this.getData.bind(this);
}
componentDidMount() {
this.getData();
}
// Fetch data from external source, update state
getData() {
fetch("http://localhost:8000/sc/v0/get", {
headers: {
Authorization: "Basic " + btoa("user1:pw1")
}
})
.then(resp => resp.json())
.then(data => this.setState({ objects: data }));
}
filter(field, value) {
this.setState(
{
filter: {
field: field,
value: value
}
},
this.getData
);
}
render() {
return (
<div id="list-container">
<div id="controls">
<div id="action">
<Button.Group>
<Button>Action 1</Button>
<Button>Action 2</Button>
</Button.Group>
</div>
<div id="search">
<SearchForm filter={this.filter} />
</div>
</div>
<div id="main">
{this.state.objects.map(data => {
console.log(data);
return <ObjectComponent {...data} key={data._id} />;
})}
</div>
</div>
);
}
}
export default List;
|