4 * Copyright 2017 RIFT.IO Inc
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 import React from 'react'
21 import _keys from 'lodash/keys'
22 import _get from 'lodash/get'
23 import _isObject from 'lodash/isObject'
24 import _isArray from 'lodash/isArray'
25 import Button from './Button'
26 import PropertyCrumb from './model/PropertyCrumb'
27 import PropertyNavigate from './model/PropertyNavigate'
28 import DescriptorEditorActions from '../actions/DescriptorEditorActions'
29 import Select from 'react-select';
30 import 'react-select/dist/react-select.css'
31 import '../styles/DetailsPanelErrors.scss'
33 export default function (props) {
34 const { container, idMaker, style } = props;
35 const errors = container.uiState.error;
36 const errorOptions = _keys(errors).reduce((outer, k) => {
37 function pieceOfPath(obj, key) {
38 const node = obj[key];
40 const items = node.reduce((inner, v, i) => {
42 const paths = _keys(v).reduce((a, k) => {
43 const paths = pieceOfPath(v, k);
44 return a.concat(paths);
46 // inner = paths.map(p => [i].concat(p));
47 inner = paths.map(p => [i].concat(p));
51 return items.map(i => [key].concat(i));
52 } else if (_isObject(node)) {
53 return _keys(node).reduce((inner, k) => {
54 const paths = pieceOfPath(node, k);
55 return inner.concat(paths);
61 const paths = pieceOfPath(errors, k);
62 return outer.concat(paths);
63 }, []).reduce((a, path) => {
64 // only add if there is an error message
65 _get(errors, path) && a.push({ value: path, label: _isArray(path) ? path.join(' . ') : path})
68 return errorOptions.length ?
69 (<PropertyNavigate container={container} idMaker={idMaker} options={errorOptions}
70 style={style} placeholder="Select error to correct" />)