3 * Copyright 2016 RIFT.IO Inc
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 import React from 'react';
19 import RecordViewStore from '../recordViewer/recordViewStore.js';
20 import Utils from 'utils/utils.js';
21 import _ from 'lodash';
22 import './nsVirtualLinks.scss';
23 import UpTime from 'widgets/uptime/uptime.jsx';
24 import NSVirtualLinksStore from './nsVirtualLinksStore.js';
25 import NSVirtualLinksActions from './nsVirtualLinksActions.js';
26 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
27 import TextInput from 'widgets/form_controls/textInput.jsx';
29 class NsVirtualLinkDetails extends React.Component {
32 this.state = NSVirtualLinksStore.getState();
35 resolvePath = (obj, path) => {
36 // supports a.b, a[1] and foo[bar], etc.
37 // where obj is ['nope', 'yes', {a: {b: 1}, foo: 2}]
38 // then [1] returns 'yes'; [2].a.b returns 1; [2].a[foo] returns 2;
39 path = path.split(/[\.\[\]]/).filter(d => d);
40 return path.reduce((r, p) => {
47 transformValue(field, value) {
48 let transformedValue = (field.transform && field.transform(value)) || value;
49 if (typeof transformedValue == 'object') {
50 transformedValue = JSON.stringify(transformedValue);
52 return transformedValue;
60 this.state.column.categories.map((category) => {
63 category.fields && category.fields.map((field) => {
64 let value = this.resolvePath(this.props.virtualLink, field.key);
67 if (_.isArray(value)) {
68 value.map((v, idx) => {
69 let transformedValue = this.transformValue(field, v);
71 <TextInput key={field.key + idx} className='value' type='text' value={transformedValue} readonly='true' defaultValue='--' />
75 let transformedValue = this.transformValue(field, value);
77 <TextInput key={field.key} className='value' label={field.label} type='text' value={transformedValue} readonly='true' defaultValue='--' />
88 <div key={category.key}>
98 return this.props.virtualLink ? (
99 <div className='nsVirtualLinkDetails'>
100 <div className='column'>
108 export default SkyquakeComponent(NsVirtualLinkDetails);