Skip to content

Commit f2575b2

Browse files
committed
projectlistselector
1 parent 949952c commit f2575b2

File tree

5 files changed

+118
-33
lines changed

5 files changed

+118
-33
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.ProjectListSelector .Select-control {
2+
height: 2.5rem
3+
}
4+
5+
.ProjectListSelector .Select-value-label,
6+
.ProjectListSelector .Select-placeholder {
7+
line-height: 2.5rem
8+
}
9+
10+
.ProjectListSelector .btn-apply-labels {
11+
width: 100%;
12+
}
13+
14+
@media (max-width: 768px) {
15+
.ProjectListSelector .btn-apply-labels {
16+
margin: 1rem 0;
17+
}
18+
}

src/Components/ProjectListSelector.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
4+
import Select from 'react-select';
5+
import 'react-select/dist/react-select.css';
6+
7+
import './ProjectListSelector.css';
8+
9+
const projectShape = PropTypes.shape({
10+
value: PropTypes.any.isRequired,
11+
label: PropTypes.string.isRequired,
12+
});
13+
14+
export default class ProjectListSelector extends React.Component {
15+
static propTypes = {
16+
onApply: PropTypes.func.isRequired,
17+
projects: PropTypes.arrayOf(projectShape),
18+
selected: projectShape,
19+
disabled: PropTypes.bool,
20+
}
21+
22+
static defaultProps = {
23+
selected: null,
24+
disabled: false
25+
}
26+
27+
constructor(props) {
28+
super(props);
29+
this.state = {
30+
selectedOption: this.props.selected
31+
};
32+
}
33+
34+
componentWillReceiveProps({ selected }) {
35+
this.setState({ selectedOption: selected });
36+
}
37+
38+
handleSelect(selectedOption) {
39+
this.setState({ selectedOption })
40+
}
41+
42+
handleClick() {
43+
this.props.onApply(this.state.selectedOption)
44+
}
45+
46+
render() {
47+
const { projects, disabled, className } = this.props;
48+
49+
const selectedOption = this.state.selectedOption && this.state.selectedOption.value
50+
const sortedProjects = projects.slice().sort((a, b) => a.label.toLocaleLowerCase() > b.label.toLocaleLowerCase() ? 1 : -1);
51+
52+
return (
53+
<div className={`ProjectListSelector row ${className}`}>
54+
<div className="col-md-10">
55+
<Select
56+
value={selectedOption}
57+
onChange={(e) => this.handleSelect(e)}
58+
options={sortedProjects}
59+
disabled={disabled}
60+
/>
61+
</div>
62+
<div className="col-md-2">
63+
<button className="btn btn-apply-labels btn-primary"
64+
disabled={selectedOption === null || disabled}
65+
onClick={() => this.handleClick()}
66+
>
67+
Apply
68+
</button>
69+
</div>
70+
</div>
71+
);
72+
}
73+
}

src/GitHub/GitHub.css

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,8 @@
1010
width: 100%;
1111
}
1212

13-
.GitHub .Select-control {
14-
height: 2.5rem
15-
}
16-
17-
.GitHub .btn-apply-labels {
18-
width: 100%;
19-
}
20-
21-
@media (max-width: 768px) {
22-
.GitHub .btn-apply-labels {
23-
margin: 1rem 0;
24-
}
13+
.GitHub .applying-status {
14+
margin: 1rem 0;
2515
}
2616

2717
.GitHub .labels .label-item [type=checkbox] {

src/GitHub/GitHub.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react'
22
import Loading from '../Components/Loading';
3+
import ProjectListSelector from '../Components/ProjectListSelector';
34
import { withGithubRepositories } from './withGitHubRepositories';
4-
import Select from 'react-select';
5-
import 'react-select/dist/react-select.css';
65
import LABELS_TO_ADD from '../Labels';
76
import invertColor from '../invertColor';
87
import './GitHub.css';
@@ -11,18 +10,20 @@ class GitHub extends React.Component {
1110

1211
constructor(props) {
1312
super(props)
14-
this.state = { selectedOption: null }
13+
this.state = {
14+
selectedOption: null,
15+
applying: false,
16+
}
1517
}
1618

17-
handleSelect(selectedOption) {
18-
this.setState({ selectedOption })
19+
handleApply(selectedOption) {
20+
console.log(selectedOption)
21+
this.setState({ selectedOption, applying: true })
1922
}
2023

2124
render() {
2225
const { loading, repositories } = this.props;
23-
const selectedOption = this.state.selectedOption && this.state.selectedOption.value
2426

25-
repositories.sort((a, b) => a.full_name.toLocaleLowerCase() > b.full_name.toLocaleLowerCase() ? 1 : -1)
2627
return (
2728
<div className="GitHub">
2829
{loading ?
@@ -32,21 +33,20 @@ class GitHub extends React.Component {
3233
</section>
3334
:
3435
<section>
35-
<div className="row select-group">
36-
<div className="col-md-10">
37-
<Select
38-
value={selectedOption}
39-
onChange={(e) => this.handleSelect(e)}
40-
options={repositories.map(r => Object.assign(r, {
41-
value: r.full_name,
42-
label: r.full_name,
43-
}))}
44-
/>
36+
<ProjectListSelector className="select-group"
37+
disabled={this.state.applying}
38+
selected={this.state.selectedOption}
39+
projects={repositories.map(r => Object.assign(r, {
40+
value: r.full_name,
41+
label: r.full_name,
42+
}))}
43+
onApply={(selected) => this.handleApply(selected)}
44+
/>
45+
{!this.state.applying ? null :
46+
<div className="row applying-status">
47+
<div className="col-md-12"><Loading /></div>
4548
</div>
46-
<div className="col-md-2">
47-
<button className="btn btn-apply-labels btn-primary">Apply</button>
48-
</div>
49-
</div>
49+
}
5050
<div className="row labels">
5151
{LABELS_TO_ADD.map(({ name, color }) => (
5252
<div key={name} className="col-md-4">

src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ body {
1818
box-sizing: inherit;
1919
}
2020

21+
.bg-primary {
22+
background-color: var(--primary)!important;
23+
}
24+
2125
.pull-right {
2226
float: right!important;
2327
}

0 commit comments

Comments
 (0)