|
1 | 1 | import React, { Component, PropTypes } from 'react'; |
2 | | -import { Alert, Nav, NavItem } from 'react-bootstrap'; |
| 2 | +import AlertMessage from '../AlertMessage'; |
| 3 | +import NormalForm from './Normal'; |
| 4 | +import TabsForm from './Tabs'; |
3 | 5 |
|
4 | 6 | class Group extends Component { |
5 | 7 | static propTypes = { |
@@ -79,86 +81,23 @@ class Group extends Component { |
79 | 81 | ); |
80 | 82 | }); |
81 | 83 | }; |
82 | | - |
83 | | - getHeader = () => { |
84 | | - let { layout } = this.props; |
85 | | - |
86 | | - if (layout.title) { |
87 | | - return ( |
88 | | - <header className="metaform-group-header"> |
89 | | - <span className="metaform-group-title"> |
90 | | - { layout.title } |
91 | | - </span> |
92 | | - </header> |
93 | | - ); |
94 | | - } else { |
95 | | - return null; |
96 | | - } |
97 | | - }; |
98 | | - |
99 | | - handleSelect = (eventKey) => { |
100 | | - event.preventDefault(); |
101 | | - }; |
102 | 84 |
|
103 | 85 | render() { |
104 | | - |
| 86 | + let { layout } = this.props; |
| 87 | + |
105 | 88 | // the passed in layout can contain either fields or groups. |
106 | 89 | // in case it contains 'fields', we're gonna render each of the fields. |
107 | 90 | // in case it contains 'groups', we're gonna render each group, passing the fields as a parameter |
108 | 91 | try { |
109 | 92 | let content = this.getContent(); |
110 | | - let header = this.getHeader(); |
111 | 93 |
|
112 | | - let { layout } = this.props; |
113 | | - |
114 | | - if (layout.type == "tabs") { |
115 | | - return( |
116 | | - <section> |
117 | | - <div className='row'> |
118 | | - <div className="metaform-group"> |
119 | | - { header } |
120 | | - <Nav bsStyle="tabs" onSelect={this.handleSelect}> |
121 | | - { |
122 | | - layout.groups.map((item, index) => ( |
123 | | - <NavItem eventKey={index}> |
124 | | - {item.title} |
125 | | - </NavItem> |
126 | | - )) |
127 | | - } |
128 | | - </Nav> |
129 | | - <div className="metaform-group-content"> |
130 | | - { content } |
131 | | - </div> |
132 | | - </div> |
133 | | - </div> |
134 | | - </section> |
135 | | - ); |
136 | | - } else { |
137 | | - return ( |
138 | | - <section> |
139 | | - <div className='row'> |
140 | | - <div className="metaform-group"> |
141 | | - { header } |
142 | | - <div className="metaform-group-content"> |
143 | | - { content } |
144 | | - </div> |
145 | | - </div> |
146 | | - </div> |
147 | | - </section> |
148 | | - ); |
| 94 | + if (layout.type == 'tabs') { |
| 95 | + return <TabsForm title={layout.title} content={content}/>; |
149 | 96 | } |
150 | | - |
| 97 | + |
| 98 | + return <NormalForm title={layout.title} content={content}/> |
151 | 99 | } catch (ex) { |
152 | | - return ( |
153 | | - <Alert bsStyle='danger'> |
154 | | - <h4> |
155 | | - Could not render the MetaFormGroup component. The schema is not valid. |
156 | | - </h4> |
157 | | - <p>Detailed information: |
158 | | - <b>{ ex.message }</b> |
159 | | - </p> |
160 | | - </Alert> |
161 | | - ) |
| 100 | + return <AlertMessage error={ex}/> |
162 | 101 | } |
163 | 102 | } |
164 | 103 | } |
|
0 commit comments