|
1 | 1 | import React, { Component } from 'react'; |
| 2 | +import { isLoadingSelector } from 'ui/redux/modules/pagination'; |
2 | 3 | import PropTypes from 'prop-types'; |
3 | 4 | import * as _ from 'lodash'; |
4 | 5 | import Scroll from 'react-scroll'; |
5 | 6 | import { connect } from 'react-redux'; |
6 | | -import { actions as routerActions } from 'redux-router5'; |
| 7 | +import { actions, routeNodeSelector } from 'redux-router5'; |
7 | 8 | import { withProps, compose, lifecycle, withHandlers, mapProps } from 'recompose'; |
8 | 9 | import { Map, List, is } from 'immutable'; |
9 | 10 | import Input from 'ui/components/Material/Input'; |
10 | 11 | import Spinner from 'ui/components/Spinner'; |
11 | | -import CopyIconButton from 'ui/components/IconButton/CopyIconButton'; |
12 | 12 | import DashboardGrid from 'ui/containers/DashboardGrid'; |
13 | 13 | import DashboardSharing from 'ui/containers/DashboardSharing'; |
14 | | -import DeleteButton from 'ui/containers/DeleteButton'; |
15 | | -import Owner from 'ui/containers/Owner'; |
16 | | -import PrivacyToggleButton from 'ui/containers/PrivacyToggleButton'; |
17 | 14 | import WidgetVisualiseCreator from 'ui/containers/WidgetVisualiseCreator'; |
18 | | -import { withModel } from 'ui/utils/hocs'; |
19 | | -import { COPY_DASHBOARD } from 'ui/redux/modules/dashboard/copyDashboard'; |
20 | | -import { getVisualisationsFromDashboard } from 'ui/redux/modules/dashboard/selectors'; |
| 15 | +import { withModels, withModel } from 'ui/utils/hocs'; |
21 | 16 | import { loggedInUserId } from 'ui/redux/selectors'; |
22 | 17 | import { activeOrgIdSelector } from 'ui/redux/modules/router'; |
23 | | -import { EditInputWrapper, Editor, EditWrapper } from 'ui/containers/Dashboard/styled'; |
24 | | - |
25 | | -const schema = 'dashboard'; |
| 18 | +import { EditWrapper } from 'ui/containers/Dashboard/styled'; |
26 | 19 |
|
27 | 20 | class Dashboard extends Component { |
28 | 21 | static propTypes = { |
29 | 22 | model: PropTypes.instanceOf(Map), |
30 | | - navigateTo: PropTypes.func, |
31 | 23 | updateModel: PropTypes.func, |
32 | 24 | saveModel: PropTypes.func, |
33 | 25 | setMetadata: PropTypes.func, |
34 | 26 | getMetadata: PropTypes.func, |
35 | | - doCopyDashboard: PropTypes.func, |
36 | 27 | }; |
37 | 28 |
|
38 | 29 | static defaultProps = { |
@@ -128,135 +119,134 @@ class Dashboard extends Component { |
128 | 119 | }; |
129 | 120 |
|
130 | 121 | render() { |
131 | | - const { model, organisationId, navigateTo, doCopyDashboard } = this.props; |
| 122 | + const { model, backToDashboard } = this.props; |
132 | 123 |
|
133 | 124 | if (!model.get('_id')) { |
134 | 125 | return <Spinner />; |
135 | 126 | } |
136 | 127 |
|
137 | 128 | return ( |
138 | | - <div className="row"> |
139 | | - <Editor> |
140 | | - <EditWrapper> |
141 | | - <EditInputWrapper> |
| 129 | + <div> |
| 130 | + <header id="topbar"> |
| 131 | + <div className="heading heading-light"> |
| 132 | + <span className="pull-right open_panel_btn" > |
| 133 | + <a |
| 134 | + onClick={this.onClickAddWidget} |
| 135 | + className="btn btn-primary btn-sm"> |
| 136 | + <i className="ion ion-stats-bars" /> Add widget |
| 137 | + </a> |
| 138 | + |
| 139 | + <button |
| 140 | + className="btn btn-default btn-sm flat-btn flat-white" |
| 141 | + title="Share" |
| 142 | + onClick={this.toggleSharing} |
| 143 | + style={{ |
| 144 | + backgroundColor: this.props.getMetadata('isSharing') ? '#F5AB35' : null, |
| 145 | + color: this.props.getMetadata('isSharing') ? 'white' : null, |
| 146 | + marginRight: 0, |
| 147 | + }}> |
| 148 | + <i className="icon ion-android-share-alt" /> |
| 149 | + </button> |
| 150 | + </span> |
| 151 | + <EditWrapper> |
| 152 | + <a |
| 153 | + onClick={backToDashboard} > |
| 154 | + <i className="icon ion-chevron-left" /> |
| 155 | + </a> |
142 | 156 | <Input |
143 | 157 | type="text" |
144 | 158 | name="Title" |
145 | | - label="Enter title" |
146 | 159 | value={model.get('title', ' ')} |
147 | 160 | onChange={this.onTitleChange} |
148 | | - style={{ fontSize: '13px' }} /> |
149 | | - </EditInputWrapper> |
150 | | - |
151 | | - |
152 | | - |
153 | | - <a |
154 | | - onClick={this.onClickAddWidget} |
155 | | - className="btn btn-default btn-sm flat-btn flat-white"> |
156 | | - <i className="ion ion-stats-bars" /> Add widget |
157 | | - </a> |
158 | | - |
159 | | - <PrivacyToggleButton |
160 | | - white |
161 | | - id={model.get('_id')} |
162 | | - schema={schema} /> |
163 | | - |
164 | | - <CopyIconButton |
165 | | - message="This will copy the dashboard and visualisations. Are you sure?" |
166 | | - white |
167 | | - onClickConfirm={doCopyDashboard} /> |
168 | | - |
169 | | - <DeleteButton |
170 | | - white |
171 | | - id={model.get('_id')} |
172 | | - schema={schema} |
173 | | - onDeletedModel={() => |
174 | | - navigateTo('organisation.data.dashboards', { organisationId }) |
175 | | - } /> |
176 | | - |
177 | | - <button |
178 | | - className="btn btn-default btn-sm flat-btn flat-white" |
179 | | - title="Share" |
180 | | - onClick={this.toggleSharing} |
181 | | - style={{ |
182 | | - backgroundColor: this.props.getMetadata('isSharing') ? '#F5AB35' : null, |
183 | | - color: this.props.getMetadata('isSharing') ? 'white' : null |
184 | | - }}> |
185 | | - <i className="icon ion-android-share-alt" /> |
186 | | - </button> |
187 | | - |
188 | | - <span style={{ marginLeft: 'auto' }}> |
189 | | - <Owner model={model} /> |
190 | | - </span> |
191 | | - </EditWrapper> |
| 161 | + style={{ fontSize: '18px', color: '#929292', padding: 0 }} /> |
| 162 | + </EditWrapper> |
| 163 | + </div> |
| 164 | + </header> |
| 165 | + <div className="row"> |
192 | 166 | {this.props.getMetadata('isSharing') && |
193 | | - <div> |
| 167 | + <div className="col-md-12"> |
194 | 168 | <DashboardSharing |
195 | 169 | shareable={model.get('shareable', new List())} |
196 | 170 | id={model.get('_id')} /> |
197 | 171 | </div> |
198 | 172 | } |
199 | | - </Editor> |
200 | 173 |
|
201 | | - <div className="clearfix" /> |
| 174 | + <div className="clearfix" /> |
202 | 175 |
|
203 | | - <WidgetVisualiseCreator |
204 | | - isOpened={this.state.widgetModalOpen} |
205 | | - model={model} |
206 | | - onClickClose={() => this.toggleWidgetModal()} |
207 | | - onChangeVisualisation={this.createPopulatedWidget} /> |
| 176 | + <WidgetVisualiseCreator |
| 177 | + isOpened={this.state.widgetModalOpen} |
| 178 | + model={model} |
| 179 | + onClickClose={() => this.toggleWidgetModal()} |
| 180 | + onChangeVisualisation={this.createPopulatedWidget} /> |
208 | 181 |
|
209 | | - <DashboardGrid |
210 | | - widgets={model.get('widgets')} |
211 | | - onChange={this.onChangeWidgets} |
212 | | - onChangeTitle={this.onChangeWidgetTitle} |
213 | | - onChangeVisualisation={this.onChangeWidgetVisualisation} /> |
| 182 | + <DashboardGrid |
| 183 | + widgets={model.get('widgets')} |
| 184 | + onChange={this.onChangeWidgets} |
| 185 | + onChangeTitle={this.onChangeWidgetTitle} |
| 186 | + onChangeVisualisation={this.onChangeWidgetVisualisation} /> |
| 187 | + </div> |
214 | 188 | </div> |
215 | 189 | ); |
216 | 190 | } |
217 | 191 | } |
218 | 192 |
|
219 | 193 | export default compose( |
220 | | - withProps(({ params, id }) => |
221 | | - ({ |
222 | | - schema, |
223 | | - id: id || params.dashboardId |
| 194 | + connect( |
| 195 | + state => ({ |
| 196 | + isLoading: isLoadingSelector('dashboard', new Map())(state), |
| 197 | + userId: loggedInUserId(state), |
| 198 | + route: routeNodeSelector('organisation.dashboards')(state).route, |
| 199 | + organisation: activeOrgIdSelector(state) |
| 200 | + }), |
| 201 | + { navigateTo: actions.navigateTo } |
| 202 | + ), |
| 203 | + withProps({ |
| 204 | + schema: 'dashboard', |
| 205 | + filter: new Map(), |
| 206 | + first: 300, |
| 207 | + }), |
| 208 | + withModels, |
| 209 | + withProps( |
| 210 | + ({ route }) => ({ |
| 211 | + id: route.name === 'organisation.data.dashboards.add' ? undefined : route.params.dashboardId |
224 | 212 | }) |
225 | 213 | ), |
226 | 214 | withModel, |
| 215 | + withProps( |
| 216 | + ({ |
| 217 | + id, |
| 218 | + models, |
| 219 | + model |
| 220 | + }) => { |
| 221 | + if (model.size === 0 && id) { |
| 222 | + return ({ |
| 223 | + modelsWithModel: models |
| 224 | + }); |
| 225 | + } |
| 226 | + |
| 227 | + return ({ |
| 228 | + modelsWithModel: !id || models.has(id) ? models : models.reverse().set(id, model).reverse() |
| 229 | + }); |
| 230 | + } |
| 231 | + ), |
227 | 232 | lifecycle({ |
228 | 233 | componentDidUpdate(previousProps) { |
229 | | - if (this.props.model.get('widgets').size > previousProps.model.get('widgets').size && window) { |
| 234 | + if ( |
| 235 | + this.props.model.get('widgets') && this.props.model.get('widgets').size && previousProps.size && |
| 236 | + this.props.model.get('widgets').size > previousProps.model.get('widgets').size && window |
| 237 | + ) { |
230 | 238 | const scroll = Scroll.animateScroll; |
231 | 239 | scroll.scrollToBottom({ smooth: true }); |
232 | 240 | } |
233 | 241 | } |
234 | 242 | }), |
235 | | - connect( |
236 | | - state => ({ |
237 | | - organisationId: activeOrgIdSelector(state), |
238 | | - userId: loggedInUserId(state), |
239 | | - state, |
240 | | - }), |
241 | | - dispatch => ({ |
242 | | - navigateTo: () => dispatch(routerActions.navigateTo), |
243 | | - copyDashboard: ({ dashboard, visualisations, organisationId, userId }) => dispatch({ |
244 | | - type: COPY_DASHBOARD, |
245 | | - dispatch, |
246 | | - dashboard, |
247 | | - visualisations, |
248 | | - organisationId, |
249 | | - userId, |
250 | | - }), |
251 | | - }), |
252 | | - ), |
253 | 243 | withHandlers({ |
254 | | - doCopyDashboard: ({ model, state, organisationId, copyDashboard, userId }) => () => copyDashboard({ |
255 | | - dashboard: model, |
256 | | - visualisations: getVisualisationsFromDashboard(model.get('_id'))(state), |
257 | | - organisationId, |
258 | | - userId, |
259 | | - }) |
| 244 | + backToDashboard: ({ route, navigateTo }) => () => { |
| 245 | + const organisationId = route.params.organisationId; |
| 246 | + navigateTo('organisation.data.dashboards', { |
| 247 | + organisationId |
| 248 | + }); |
| 249 | + } |
260 | 250 | }), |
261 | | - mapProps(original => _.pick(original, ['model', 'navigateTo', 'updateModel', 'saveModel', 'setMetadata', 'getMetadata', 'doCopyDashboard'])), |
| 251 | + mapProps(original => _.pick(original, ['model', 'updateModel', 'saveModel', 'setMetadata', 'getMetadata', 'backToDashboard'])), |
262 | 252 | )(Dashboard); |
0 commit comments