2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 import React from 'react';
23 import NodeVisualElementConstants from './NodeVisualElementConstants.js';
24 import NodeVisualElementFactory from './NodeVisualElementFactory.js';
30 this.visualElementFactory = new NodeVisualElementFactory();
32 this.setNodeMeta = this.setNodeMeta.bind(this);
35 setNodeMeta(metaObject) {
36 this.graphMeta = metaObject;
37 this.visualElementFactory.setVisualElementMeta(metaObject);
39 // hideButton a temporary solution to not display the button.
40 buildNode(nodeType, nodeProps, hideButton) {
42 let translate = `translate(
43 ${nodeProps.renderProps.x},
44 ${nodeProps.renderProps.y})`;
46 ...nodeProps.renderProps,
47 className: this.graphMeta.aaiEntityNodeDescriptors[nodeType].class,
51 let nodeVisualElementsData = this.extractVisualElementArrayFromMeta(
52 nodeType, hideButton);
53 let nodeVisualElements = undefined;
54 if (nodeVisualElementsData) {
55 nodeVisualElements = [];
56 nodeVisualElementsData.map((elementData, index) => {
57 if (elementData.type === NodeVisualElementConstants.BUTTON) {
58 if (nodeProps.buttons) {
59 let isButtonSelected = false;
61 isButtonSelected = nodeProps.buttons[0];
64 isButtonSelected = nodeProps.buttons[1];
68 isSelected: isButtonSelected
72 nodeVisualElements.push(
73 this.visualElementFactory.buildVisualElement(nodeProps.meta,
74 elementData.type, elementData, index));
76 //Draw overlay only if the node is validated
77 if (nodeProps.meta.nodeMeta.nodeValidated) {
79 if (nodeProps.meta.nodeMeta.nodeIssue) {
80 let warningOverlayProps = {
81 name: NodeVisualElementConstants.ICON_WARNING,
83 nodeVisualElements.push(
84 this.visualElementFactory.buildVisualElement(nodeProps,
85 NodeVisualElementConstants.ICON, warningOverlayProps,
86 nodeVisualElementsData.length + 1));
88 let tickOverlayProps = {
89 name: NodeVisualElementConstants.ICON_TICK,
91 nodeVisualElements.push(
92 this.visualElementFactory.buildVisualElement(nodeProps,
93 NodeVisualElementConstants.ICON, tickOverlayProps,
94 nodeVisualElementsData.length + 1));
99 if (nodeVisualElements) {
100 return React.createElement('g', finalProps, nodeVisualElements);
103 return React.createElement('g', finalProps);
106 extractVisualElementArrayFromMeta(nodeClassName, hideButton) {
107 let nodeVisualElements = undefined;
108 if (this.graphMeta.aaiEntityNodeDescriptors) {
110 this.graphMeta.aaiEntityNodeDescriptors[nodeClassName].visualElements;
112 // temp, until BE not sent the triangle button
113 for (var i = 0; i < nodeVisualElements.length; i++) {
114 if (nodeVisualElements[i].type === 'button' && nodeVisualElements[i].name === 'icon_triangle_warning') {
115 nodeVisualElements.splice(i, 1);
121 return nodeVisualElements;
125 export default NodeFactory;