2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
16 import { actionTypes as softwareProductsActionTypes } from 'sdc-app/onboarding/softwareProduct/SoftwareProductConstants.js';
17 import { actionTypes, nodeFilters } from './HeatValidationConstants.js';
19 const mapNestedData = ({ fileName, env, errors }) => ({
33 const mapVolumeData = ({ fileName, env, errors, nested }) => ({
47 ...(nested ? nested.map(mapNestedData) : [])
52 const mapNetworkData = ({ fileName, env, errors }) => ({
66 const mapArtifactsData = ({ fileName, errors }) => ({
72 const mapOtherData = ({ fileName, errors }) => ({
78 const mapHeatData = ({
93 ...(volume ? volume.map(mapVolumeData) : []),
94 ...(network ? network.map(mapNetworkData) : []),
104 ...(artifacts ? artifacts.map(mapArtifactsData) : []),
105 ...(other ? other.map(mapOtherData) : []),
106 ...(nested ? nested.map(mapHeatData) : [])
110 function createErrorList(node, parent, deep = 0, errorList = []) {
113 ...node.errors.map(error => ({
115 errorMessage: error.message,
118 parentName: parent.name,
123 if (node.children && node.children.length) {
124 node.children.map(child =>
125 createErrorList(child, node, deep + 1, errorList)
131 const mapValidationDataToTree = (validationData, packageName) => {
132 let { errors, heat, nested, volume, network, artifacts, other } =
133 validationData.importStructure || {};
143 ? heat.map(mapHeatData)
144 : nested ? nested.map(mapHeatData) : []
153 ? artifacts.map(mapArtifactsData)
164 children: network ? network.map(mapNetworkData) : []
174 children: volume ? volume.map(mapVolumeData) : []
184 children: other ? other.map(mapOtherData) : []
192 const toggleExpanded = (node, path) => {
193 let newNode = { ...node };
194 if (path.length === 0) {
195 newNode.expanded = !node.expanded;
199 ...node.children.slice(0, index),
200 toggleExpanded(node.children[index], path.slice(1)),
201 ...node.children.slice(index + 1)
207 const expandSelected = (node, selectedNode) => {
208 let shouldExpand = node.name === selectedNode;
211 node.children.map(child => {
213 shouldExpand: shouldExpandChild,
215 } = expandSelected(child, selectedNode);
216 shouldExpand = shouldExpand || shouldExpandChild;
223 expanded: node.expanded || shouldExpand,
230 export default (state = { attachmentsTree: {} }, action) => {
231 switch (action.type) {
232 case softwareProductsActionTypes.SOFTWARE_PRODUCT_LOADED:
233 let currentSoftwareProduct = action.response;
234 const packageName = currentSoftwareProduct.networkPackageName;
235 let attachmentsTree = currentSoftwareProduct.validationData
236 ? mapValidationDataToTree(
237 currentSoftwareProduct.validationData,
241 let errorList = createErrorList(attachmentsTree);
246 selectedNode: nodeFilters.ALL
248 case actionTypes.TOGGLE_EXPANDED:
251 attachmentsTree: toggleExpanded(
252 state.attachmentsTree,
256 case actionTypes.SELECTED_NODE:
257 let selectedNode = action.nodeName;
260 attachmentsTree: expandSelected(
261 state.attachmentsTree,
266 case actionTypes.UNSELECTED_NODE:
269 selectedNode: nodeFilters.ALL