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 { heat, nested, volume, network, artifacts, other } =
133 validationData.importStructure || {};
142 ? heat.map(mapHeatData)
143 : nested ? nested.map(mapHeatData) : []
152 ? artifacts.map(mapArtifactsData)
163 children: network ? network.map(mapNetworkData) : []
173 children: volume ? volume.map(mapVolumeData) : []
183 children: other ? other.map(mapOtherData) : []
191 const toggleExpanded = (node, path) => {
192 let newNode = { ...node };
193 if (path.length === 0) {
194 newNode.expanded = !node.expanded;
198 ...node.children.slice(0, index),
199 toggleExpanded(node.children[index], path.slice(1)),
200 ...node.children.slice(index + 1)
206 const expandSelected = (node, selectedNode) => {
207 let shouldExpand = node.name === selectedNode;
210 node.children.map(child => {
212 shouldExpand: shouldExpandChild,
214 } = expandSelected(child, selectedNode);
215 shouldExpand = shouldExpand || shouldExpandChild;
222 expanded: node.expanded || shouldExpand,
229 export default (state = { attachmentsTree: {} }, action) => {
230 switch (action.type) {
231 case softwareProductsActionTypes.SOFTWARE_PRODUCT_LOADED:
232 let currentSoftwareProduct = action.response;
233 const packageName = currentSoftwareProduct.networkPackageName;
234 let attachmentsTree = currentSoftwareProduct.validationData
235 ? mapValidationDataToTree(
236 currentSoftwareProduct.validationData,
240 let errorList = createErrorList(attachmentsTree);
245 selectedNode: nodeFilters.ALL
247 case actionTypes.TOGGLE_EXPANDED:
250 attachmentsTree: toggleExpanded(
251 state.attachmentsTree,
255 case actionTypes.SELECTED_NODE:
256 let selectedNode = action.nodeName;
259 attachmentsTree: expandSelected(
260 state.attachmentsTree,
265 case actionTypes.UNSELECTED_NODE:
268 selectedNode: nodeFilters.ALL