Skip to content

Commit c4cb951

Browse files
committed
export to pure reusable component
1 parent ba849c0 commit c4cb951

File tree

9 files changed

+300
-244
lines changed

9 files changed

+300
-244
lines changed

src/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import './App.css';
55
import CoderockrLogo from './assets/images/hand-yellow.svg'
66
import Home from './Home'
77
import Footer from './Footer';
8-
import GitHub from './GitHub/GitHub';
8+
import GitHub from './Origins/GitHub';
99

1010
const App = () => (
1111
<div className="CWSPApp">

src/Components/ProjectListApplyer.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.ProjectListApplyer .select-group {
2+
margin-bottom: 1rem;
3+
}
4+
5+
.ProjectListApplyer .labels .label-item {
6+
text-align: left;
7+
text-overflow: ellipsis;
8+
white-space: nowrap;
9+
overflow: hidden;
10+
width: 100%;
11+
}
12+
13+
.ProjectListApplyer .applying-status {
14+
margin: 1rem 0;
15+
}
16+
17+
.ProjectListApplyer .labels h2 {
18+
font-size: 1.5rem;
19+
}
20+
21+
.ProjectListApplyer .labels .label-item .label-icon {
22+
margin: .5rem;
23+
display: inline-block;
24+
}
25+
26+
.ProjectListApplyer .labels .label-item .label-name {
27+
vertical-align: super;
28+
}

src/Components/ProjectListApplyer.js

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import { Alert } from 'reactstrap'
4+
import Loading from '../Components/Loading'
5+
import ProjectListSelector from './ProjectListSelector'
6+
import LABELS_TO_ADD from '../Labels'
7+
import invertColor from '../invertColor'
8+
import projectShape from './projectShape'
9+
10+
import './ProjectListApplyer.css'
11+
12+
const LabelList = ({ header, labels, className, applyedLabels }) => (
13+
<div className={`row labels ${className}`}>
14+
<h2 className="col-md-12">{header}</h2>
15+
{labels.map(({ name, color }) => (
16+
<div key={name} className="col-md-4">
17+
<label alt={name} className="label-item"
18+
style={{ backgroundColor: '#' + color, color: invertColor('#' + color) }}
19+
>
20+
<i className="material-icons label-icon">
21+
{applyedLabels.indexOf(name) > -1 ? 'check_box' : 'check_box_outline_blank'}
22+
</i>
23+
<span className="label-name" children={name} />
24+
</label>
25+
</div>
26+
))}
27+
</div>
28+
)
29+
30+
const ProjectListApplyer = ({
31+
className,
32+
loading,
33+
projects,
34+
selectedPreject,
35+
applying,
36+
applyedLabels,
37+
applyingStatus,
38+
onApply,
39+
labelsToRemove,
40+
alert
41+
}) => (
42+
<div className={`ProjectListApplyer ${className}`}>
43+
{loading ?
44+
<section>
45+
<h2>Loading...</h2>
46+
<Loading />
47+
</section>
48+
:
49+
<section>
50+
<ProjectListSelector className="select-group"
51+
disabled={applying}
52+
selected={selectedPreject}
53+
projects={projects}
54+
onApply={(selected) => onApply(selected)}
55+
/>
56+
{!alert ? null :
57+
<Alert
58+
color={alert.type}
59+
children={alert.message}
60+
/>
61+
}
62+
{!applying ? null :
63+
<div className="row applying-status">
64+
<div className="col-md-12"><Loading status={applyingStatus} /></div>
65+
</div>
66+
}
67+
{labelsToRemove.length === 0 ? null :
68+
<LabelList
69+
header="Labels to Remove:"
70+
className="labels-to-remove"
71+
labels={labelsToRemove}
72+
applyedLabels={applyedLabels}
73+
/>
74+
}
75+
<LabelList
76+
header="Labels to Add:"
77+
className="labels-to-add"
78+
labels={LABELS_TO_ADD}
79+
applyedLabels={applyedLabels}
80+
/>
81+
</section>
82+
}
83+
</div>
84+
);
85+
86+
ProjectListApplyer.propTypes = {
87+
className: PropTypes.string,
88+
loading: PropTypes.bool,
89+
90+
applying: PropTypes.bool,
91+
applyingStatus: PropTypes.string,
92+
applyedLabels: PropTypes.arrayOf(PropTypes.string).isRequired,
93+
alert: PropTypes.shape({
94+
type: PropTypes.oneOf(['success', 'danger']).isRequired,
95+
message: PropTypes.string.isRequired
96+
}),
97+
onApply: PropTypes.func.isRequired,
98+
99+
projects: PropTypes.arrayOf(projectShape).isRequired,
100+
selectedPreject: projectShape,
101+
102+
labelsToRemove: PropTypes.arrayOf(PropTypes.shape({
103+
name: PropTypes.string.isRequired,
104+
color: PropTypes.string.isRequired,
105+
})).isRequired,
106+
}
107+
108+
ProjectListApplyer.defaultProps = {
109+
className: "",
110+
applying: false,
111+
loading: false,
112+
applyedLabels: [],
113+
labelsToRemove: [],
114+
}
115+
116+
export default ProjectListApplyer

src/Components/ProjectListSelector.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import PropTypes from 'prop-types'
33

44
import Select from 'react-select';
55
import 'react-select/dist/react-select.css';
6+
import projectShape from './projectShape'
67

78
import './ProjectListSelector.css';
89

9-
const projectShape = PropTypes.shape({
10-
value: PropTypes.any.isRequired,
11-
label: PropTypes.string.isRequired,
12-
});
13-
1410
export default class ProjectListSelector extends React.Component {
1511
static propTypes = {
1612
onApply: PropTypes.func.isRequired,

src/Components/projectShape.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import PropTypes from 'prop-types'
2+
3+
const projectShape = PropTypes.shape({
4+
value: PropTypes.any.isRequired,
5+
label: PropTypes.string.isRequired,
6+
});
7+
8+
export default projectShape

src/GitHub/GitHub.css

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/GitHub/GitHub.js

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)