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
0 commit comments