@@ -4,15 +4,18 @@ import ProjectStatusChangeConfirmation from './ProjectStatusChangeConfirmation'
44import cn from 'classnames'
55import _ from 'lodash'
66import enhanceDropdown from 'appirio-tech-react-components/components/Dropdown/enhanceDropdown'
7+ import Tooltip from 'appirio-tech-react-components/components/Tooltip/Tooltip'
78import {
89 PROJECT_STATUS ,
10+ PROJECT_STATUS_ACTIVE ,
911 PROJECT_STATUS_COMPLETED ,
10- PROJECT_STATUS_CANCELLED
12+ PROJECT_STATUS_CANCELLED ,
13+ TOOLTIP_DEFAULT_DELAY
1114} from '../../config/constants'
1215import CarretDownNormal9px from '../../assets/icons/arrow-9px-carret-down-normal.svg'
1316
1417
15- const hocStatusDropdown = ( CompositeComponent , statusList ) => {
18+ const hocStatusDropdown = ( CompositeComponent , statusList , projectCanBeActive ) => {
1619 class StatusDropdown extends Component {
1720 shouldDropdownUp ( ) {
1821 if ( this . refs . dropdown ) {
@@ -32,6 +35,12 @@ const hocStatusDropdown = (CompositeComponent, statusList) => {
3235 return null
3336 }
3437
38+ const activestatusList = statusList . map ( ( status ) => ( {
39+ ...status ,
40+ disabled : ! projectCanBeActive && status . value === PROJECT_STATUS_ACTIVE ,
41+ toolTipMessage : ( ! projectCanBeActive && status . value === PROJECT_STATUS_ACTIVE ) ? 'To activate project there should be at least one phase in "Planned" status. Please, check "Project Plan" tab.' : null ,
42+ } ) )
43+
3544 this . shouldDropdownUp ( )
3645 return (
3746 < div className = "project-status-dropdown" ref = "dropdown" >
@@ -46,26 +55,51 @@ const hocStatusDropdown = (CompositeComponent, statusList) => {
4655 unifiedHeader = { unifiedHeader }
4756 />
4857 { canEdit && < i className = "caret" >
49- < CarretDownNormal9px className = "icon-carret-down-normal" />
58+ < CarretDownNormal9px className = "icon-carret-down-normal" />
5059 </ i > }
5160 </ div >
5261 { isOpen && canEdit &&
5362 < div className = { cn ( 'status-dropdown' , { 'dropdown-up' : this . shouldDropdownUp ( ) } ) } >
5463 < div className = "status-header" > Project Status</ div >
5564 < ul >
5665 {
57- statusList . sort ( ( a , b ) => a . dropDownOrder > b . dropDownOrder ) . map ( ( item ) =>
58- ( < li key = { item . value } >
59- < a
60- href = "javascript:"
61- className = { cn ( 'status-option' , 'status-' + item . value , { active : item . value === status } ) }
62- onClick = { ( e ) => {
63- onItemSelect ( item . value , e )
64- } }
65- >
66- < CompositeComponent status = { item } showText />
67- </ a >
68- </ li > )
66+ activestatusList . sort ( ( a , b ) => a . dropDownOrder > b . dropDownOrder ) . map ( ( item ) =>
67+ item . toolTipMessage ? (
68+ < Tooltip key = { item . value } theme = "light" tooltipDelay = { TOOLTIP_DEFAULT_DELAY } >
69+ < div className = "tooltip-target" >
70+ < li >
71+ < a
72+ href = "javascript:"
73+ className = { cn ( 'status-option' , 'status-' + item . value , { active : item . value === status , disabled : item . disabled } ) }
74+ onClick = { ( e ) => {
75+ if ( ! item . disabled )
76+ onItemSelect ( item . value , e )
77+ } }
78+ >
79+ < CompositeComponent status = { item } showText />
80+ </ a >
81+ </ li >
82+ </ div >
83+ < div className = "tooltip-body" >
84+ { item . toolTipMessage }
85+ </ div >
86+ </ Tooltip >
87+ ) : (
88+ < div key = { item . value } className = "tooltip-target" >
89+ < li >
90+ < a
91+ href = "javascript:"
92+ className = { cn ( 'status-option' , 'status-' + item . value , { active : item . value === status , disabled : item . disabled } ) }
93+ onClick = { ( e ) => {
94+ if ( ! item . disabled )
95+ onItemSelect ( item . value , e )
96+ } }
97+ >
98+ < CompositeComponent status = { item } showText />
99+ </ a >
100+ </ li >
101+ </ div >
102+ )
69103 )
70104 }
71105 </ ul >
@@ -126,10 +160,10 @@ const editableProjectStatus = (CompositeComponent) => class extends Component {
126160
127161 render ( ) {
128162 const { showStatusChangeDialog, newStatus, statusChangeReason } = this . state
129- const { canEdit } = this . props
163+ const { canEdit, projectCanBeActive } = this . props
130164 const StatusDropdown = canEdit
131- ? enhanceDropdown ( hocStatusDropdown ( CompositeComponent , PROJECT_STATUS ) )
132- : hocStatusDropdown ( CompositeComponent , PROJECT_STATUS )
165+ ? enhanceDropdown ( hocStatusDropdown ( CompositeComponent , PROJECT_STATUS , projectCanBeActive ) )
166+ : hocStatusDropdown ( CompositeComponent , PROJECT_STATUS , projectCanBeActive )
133167 return (
134168 < div className = { cn ( 'EditableProjectStatus' , { 'modal-active' : showStatusChangeDialog } ) } >
135169 < div className = "modal-overlay" onClick = { this . hideStatusChangeDialog } />
@@ -152,7 +186,11 @@ editableProjectStatus.propTypes = {
152186 /**
153187 * Boolean flag to control editability of the project status. It does not render the dropdown if it is not editable.
154188 */
155- canEdit : PropTypes . bool
189+ canEdit : PropTypes . bool ,
190+ /**
191+ * Boolean flag to control if project status can be switched to active.
192+ */
193+ projectCanBeActive : PropTypes . bool
156194}
157195
158196export default editableProjectStatus
0 commit comments