@@ -11,9 +11,37 @@ const { Row, Col, Grid, Nav, NavItem} = require('react-bootstrap');
1111const ToolsContainer = require ( './containers/ToolsContainer' ) ;
1212const Message = require ( '../components/I18N/Message' ) ;
1313
14- const { withState } = require ( 'recompose ' ) ;
14+ const { connect } = require ( 'react-redux ' ) ;
1515const assign = require ( 'object-assign' ) ;
16+ const { createSelector} = require ( 'reselect' ) ;
17+ const { onTabSelected} = require ( '../actions/contenttabs' ) ;
18+
19+ const selectedSelector = createSelector (
20+ state => state && state . contenttabs && state . contenttabs . selected ,
21+ selected => ( { selected } )
22+ ) ;
23+
1624const DefaultTitle = ( { item = { } , index } ) => < span > { item . title || `Tab ${ index } ` } </ span > ;
25+
26+ /**
27+ * @name ContentTabs
28+ * @memberof plugins
29+ * @class
30+ * @classdesc
31+ * ContentTabs plugin is used in home page allowing to switch between contained plugins (i.e. Maps and Dashboards plugins).
32+ * <br/>Each contained plugin has to have the contenttabs configuration property in its plugin configuration.
33+ * The key property is mandatory following and position property is used to order give tabs order.
34+ * An example of the contenttabs config in Maps plugin
35+ * @example
36+ * ContentTabs: {
37+ * name: 'maps',
38+ * key: 'maps',
39+ * TitleComponent:
40+ * connect(mapsCountSelector)(({ count = "" }) => <Message msgId="resources.maps.title" msgParams={{ count: count + "" }} />),
41+ * position: 1,
42+ * tool: true
43+ * }
44+ */
1745class ContentTabs extends React . Component {
1846 static propTypes = {
1947 selected : PropTypes . number ,
@@ -22,6 +50,7 @@ class ContentTabs extends React.Component {
2250 items : PropTypes . array ,
2351 id : PropTypes . string ,
2452 onSelect : PropTypes . func
53+
2554 } ;
2655 static defaultProps = {
2756 selected : 0 ,
@@ -44,21 +73,21 @@ class ContentTabs extends React.Component {
4473 container = { ( props ) => < div { ...props } >
4574 < div style = { { marginTop : "10px" } } >
4675 < Nav bsStyle = "tabs" activeKey = "1" onSelect = { k => this . props . onSelect ( k ) } >
47- { this . props . items . map (
76+ { [ ... this . props . items ] . sort ( ( a , b ) => a . position - b . position ) . map (
4877 ( { TitleComponent = DefaultTitle , ...item } , idx ) =>
4978 ( < NavItem
50- active = { idx === this . props . selected }
79+ active = { ( item . key || idx ) === this . props . selected }
5180 eventKey = { item . key || idx } >
5281 < TitleComponent index = { idx } item = { item } />
53- </ NavItem > ) ) }
82+ </ NavItem > ) ) }
5483 </ Nav >
5584 </ div >
5685 { props . children }
5786 </ div > }
5887 toolStyle = "primary"
5988 stateSelector = "contentTabs"
6089 activeStyle = "default"
61- tools = { [ ...this . props . items ] . sort ( ( a , b ) => a . position - b . position ) . filter ( ( e , i ) => i === this . props . selected ) }
90+ tools = { [ ...this . props . items ] . sort ( ( a , b ) => a . position - b . position ) . filter ( ( { key } , i ) => ( key || i ) === this . props . selected ) }
6291 panels = { [ ] }
6392 /> </ Col >
6493 </ Row >
@@ -69,13 +98,16 @@ class ContentTabs extends React.Component {
6998}
7099
71100module . exports = {
72- ContentTabsPlugin : assign ( withState ( 'selected' , 'onSelect' , 0 ) ( ContentTabs ) , {
101+ ContentTabsPlugin : assign ( connect ( selectedSelector , {
102+ onSelect : onTabSelected
103+ } ) ( ContentTabs ) , {
73104 NavMenu : {
74105 position : 2 ,
75106 label : < Message msgId = "resources.contents.title" /> ,
76107 linkId : '#content-tabs' ,
77108 glyph : 'dashboard'
78109 }
79110 } ) ,
80- reducers : { }
111+ reducers : { contenttabs : require ( '../reducers/contenttabs' ) } ,
112+ epics : require ( '../epics/contenttabs' )
81113} ;
0 commit comments