Rift.IO OSM R1 Initial Submission
[osm/UI.git] / skyquake / plugins / composer / src / src / components / DetailsPanel.js
1
2 /*
3 *
4 * Copyright 2016 RIFT.IO Inc
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19 'use strict';
20
21 import _ from 'lodash'
22 import React from 'react';
23 import PureRenderMixin from 'react-addons-pure-render-mixin'
24 import messages from './messages'
25 import serializers from '../libraries/model/DescriptorModelSerializer'
26 import JSONViewer from 'widgets/JSONViewer/JSONViewer';
27 import PopupWindow from './PopupWindow'
28 import CatalogItemDetailsEditor from './CatalogItemDetailsEditor'
29 import SelectionManager from '../libraries/SelectionManager'
30
31 import '../styles/DetailsPanel.scss'
32
33 const DetailsPanel = React.createClass({
34 mixins: [PureRenderMixin, SelectionManager.reactPauseResumeMixin],
35 getInitialState() {
36 return {};
37 },
38 getDefaultProps() {
39 return {
40 containers: [],
41 showJSONViewer: false
42 };
43 },
44 componentWillMount() {
45 },
46 componentDidMount() {
47 },
48 componentDidUpdate() {
49 SelectionManager.refreshOutline();
50 },
51 componentWillUnmount() {
52 },
53 render() {
54 let json = '{}';
55 let bodyComponent = messages.detailsWelcome();
56 const selected = this.props.containers.filter(d => SelectionManager.isSelected(d));
57 const selectedContainer = selected[0];
58 if (selectedContainer) {
59 bodyComponent = <CatalogItemDetailsEditor container={selectedContainer} width={this.props.layout.right} />;
60 const edit = _.cloneDeep(selectedContainer.model);
61 json = serializers.serialize(edit) || edit;
62 }
63 const jsonViewerTitle = selectedContainer ? selectedContainer.model.name : 'nothing selected';
64 const hasNoCatalogs = this.props.hasNoCatalogs;
65 return (
66 <div className="DetailsPanel" data-resizable="left" data-resizable-handle-offset="0 5" style={{width: this.props.layout.right}} onClick={event => event.preventDefault()}>
67 <div className="DetailsPanelBody">
68 {hasNoCatalogs ? null : bodyComponent}
69 </div>
70 <PopupWindow show={this.props.showJSONViewer} title={jsonViewerTitle}><JSONViewer json={json}/></PopupWindow>
71 </div>
72 );
73 }
74 });
75
76 export default DetailsPanel;