This repository was archived by the owner on Oct 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 236
/
Copy pathBoardSelector.tsx
64 lines (57 loc) · 2.2 KB
/
BoardSelector.tsx
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as React from "react";
import { Col } from "react-bootstrap";
import Select from "react-select";
import * as API from "../actions/api";
interface IBoardSelectorProps extends React.Props<any> {
installedBoards: any;
loadConfigItems();
}
interface IBoardSelectorState extends React.Props<any> {
selectedBoard: any;
}
export default class BoardSelector extends React.Component<IBoardSelectorProps, IBoardSelectorState> {
constructor(props) {
super(props);
this.state = {
selectedBoard: this.props.installedBoards.find((bd) => bd.isSelected),
};
this.updateSelectedBoard = this.updateSelectedBoard.bind(this);
}
public componentWillReceiveProps(nextProps) {
if (!this.state.selectedBoard && nextProps.installedBoards.length) {
this.setState({
selectedBoard: nextProps.installedBoards.find((bd) => bd.isSelected),
});
}
}
public render() {
const options = this.props.installedBoards.map((b) => {
return {
value: b.key,
label: `${b.name} (${b.platform})`,
};
});
return (<div className="listitem theme-listitem">
<Col className="left-side d-inline-block" xs={3} sm={2} md={2}>Selected Board:</Col>
<Col className="react-selector btn-group">
<Select
clearable={false}
name="select-board"
options={options}
value={this.state.selectedBoard ? this.state.selectedBoard.key : null}
onChange={this.updateSelectedBoard}
placeholder="Select your board" />
</Col>
</div>);
}
private updateSelectedBoard(newValue: any): void {
API.updateSelectedBoard(newValue.value).then((res) => {
this.setState({
selectedBoard: this.props.installedBoards.find((bd) => bd.key === newValue.value),
});
this.props.loadConfigItems();
});
}
}