Skip to content
This repository was archived by the owner on Nov 14, 2020. It is now read-only.

Commit a40d183

Browse files
committed
fetch list of namespaces and pass as child props
1 parent 14398c9 commit a40d183

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/App.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,46 @@ import './App.css';
33
import SimpleTabs from './components/Tabs'
44
import NavBar from './components/NavBar'
55
import NamespaceSelector from './components/NamespaceSelector'
6-
6+
import axios from 'axios'
77

88
class App extends Component {
9+
constructor(props) {
10+
super(props);
11+
this.state = {
12+
selectedNamespace: null,
13+
namespaces: []
14+
}
15+
this.nsChangeHandler = this.nsChangeHandler.bind(this);
16+
}
17+
18+
nsChangeHandler(selectedNs) {
19+
this.setState({selectedNamespace: selectedNs})
20+
}
21+
22+
componentDidMount() {
23+
axios.get('/api/v1/namespaces/').then((response) => {
24+
const namespaceList = response.data.namespaces.map(namespace => namespace.name)
25+
console.log(namespaceList)
26+
this.setState({namespaces: namespaceList})
27+
this.setState({selectedNamespace: namespaceList[0]})
28+
})
29+
}
30+
931
render() {
1032
return (
1133
<div>
1234
<div>
1335
<NavBar />
1436
</div>
1537
<div>
16-
<NamespaceSelector />
38+
<NamespaceSelector
39+
namespaces={this.state.namespaces}
40+
selectedNamespace={this.state.selectedNamespace}
41+
onChange={this.nsChangeHandler}
42+
/>
1743
</div>
1844
<div>
19-
<SimpleTabs />
45+
<SimpleTabs namespace={this.state.selectedNamespace}/>
2046
</div>
2147
</div>
2248
);

0 commit comments

Comments
 (0)