1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
import React from 'react';
import FontAwesome from 'react-fontawesome';
import classNames from 'classnames';
import Collapse from 'react-bootstrap/lib/Collapse.js';
import i18n from 'nfvo-utils/i18n/i18n.js';
import {nodeTypes, mouseActions} from './AttachmentsConstants';
const typeToIcon = Object.freeze({
heat: 'building-o',
volume: 'database',
network: 'cloud',
artifact: 'gear',
env: 'server',
other: 'cube'
});
const leftPanelWidth = 250;
class SoftwareProductAttachmentsView extends React.Component {
static propTypes = {
attachmentsTree: React.PropTypes.object.isRequired
};
state = {
treeWidth: '400',
};
render() {
let {attachmentsTree, errorList = []} = this.props;
let {treeWidth} = this.state;
return (
<div className='software-product-attachments'>
<div className='software-product-view'>
<div className='software-product-landing-view-right-side'>
<div className='software-product-attachments-main'>
<div className='software-product-attachments-tree' style={{'width' : treeWidth + 'px'}}>
<div className='tree-wrapper'>
{
attachmentsTree && attachmentsTree.children && attachmentsTree.children.map((child, ind) => this.renderNode(child, [ind]))
}
</div>
</div>
<div className='software-product-attachments-separator' onMouseDown={e => this.onChangeTreeWidth(e)} />
<div className='software-product-attachments-error-list'>
{errorList.length ? this.renderErrorList(errorList) : <div className='no-errors'>{attachmentsTree.children ?
i18n('VALIDATION SUCCESS') : i18n('THERE IS NO HEAT DATA TO PRESENT') }</div>}
</div>
</div>
</div>
</div>
</div>
);
}
renderNode(node, path) {
let isFolder = node.children && node.children.length > 0;
let {onSelectNode} = this.props;
return (
<div key={node.name} className='tree-block-inside'>
{
<div onDoubleClick={() => this.props.toggleExpanded(path)} className={this.getTreeRowClassName(node.name)}>
{
isFolder &&
<div onClick={() => this.props.toggleExpanded(path)} className={classNames('tree-node-expander', {'tree-node-expander-collapsed': !node.expanded})}>
<FontAwesome name='caret-down'/>
</div>
}
{
<span className='tree-node-icon'>
<FontAwesome name={typeToIcon[node.type]}/>
</span>
}
{
<span onClick={() => onSelectNode(node.name)} className={this.getTreeTextClassName(node)}>
{node.name}
</span>
}
</div>
}
{
isFolder &&
<Collapse in={node.expanded}>
<div className='tree-node-children'>
{
node.children.map((child, ind) => this.renderNode(child, [...path, ind]))
}
</div>
</Collapse>
}
</div>
);
}
createErrorList(errorList, node, parent) {
if (node.errors) {
node.errors.forEach(error => errorList.push({
error,
name: node.name,
parentName: parent.name,
type: node.type
}));
}
if (node.children && node.children.length) {
node.children.map((child) => this.createErrorList(errorList, child, node));
}
}
renderErrorList(errors) {
let prevError = {};
let {selectedNode} = this.props;
return errors.map(error => {
let isSameNodeError = error.name === prevError.name && error.parentName === prevError.parentName;
prevError = error;
return (
<div
key={error.name + error.errorMessage + error.parentName}
onClick={() => this.selectNode(error.name)}
className={classNames('error-item', {'clicked': selectedNode === error.name, 'shifted': !isSameNodeError})}>
<span className={classNames('error-item-file-type', {'strong': !isSameNodeError})}>
{
error.hasParent ?
i18n('{type} {name} in {parentName}: ', {
type: nodeTypes[error.type],
name: error.name,
parentName: error.parentName
}) :
i18n('{type} {name}: ', {
type: nodeTypes[error.type],
name: error.name
})
}
</span>
<span className={`error-item-file-type ${error.errorLevel}`}> {error.errorMessage} </span>
</div>
);
});
}
selectNode(currentSelectedNode) {
let {onUnselectNode, onSelectNode, selectedNode} = this.props;
if (currentSelectedNode !== selectedNode) {
onSelectNode(currentSelectedNode);
}else{
onUnselectNode();
}
}
getTreeRowClassName(name) {
let {hoveredNode, selectedNode} = this.props;
return classNames({
'tree-node-row': true,
'tree-node-selected': name === hoveredNode,
'tree-node-clicked': name === selectedNode
});
}
getTreeTextClassName(node) {
let {selectedNode} = this.props;
return classNames({
'tree-element-text': true,
'error-status': node.errors,
'error-status-selected': node.name === selectedNode
});
}
onChangeTreeWidth(e) {
if (e.button === mouseActions.MOUSE_BUTTON_CLICK) {
let onMouseMove = (e) => {
this.setState({treeWidth: e.clientX - leftPanelWidth});
};
let onMouseUp = () => {
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
};
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
}
}
}
export default SoftwareProductAttachmentsView;
|