/** * Graph React component * Read-only properties */ import * as React from "react"; import { GraphHighlightedNodeData } from "./GraphExplorer"; import * as ViewModels from "../../../Contracts/ViewModels"; export interface ReadOnlyNodePropertiesComponentProps { node: GraphHighlightedNodeData; } export class ReadOnlyNodePropertiesComponent extends React.Component { public render(): JSX.Element { return ( {Object.keys(this.props.node.properties).map(_propkey => { const gremlinValues = this.props.node.properties[_propkey]; return ReadOnlyNodePropertiesComponent.renderReadOnlyPropertyKeyPair(_propkey, gremlinValues); })}
id {this.props.node.id}
label {this.props.node.label}
); } public static renderReadOnlyPropertyKeyPair( key: string, propertyValues: ViewModels.GremlinPropertyValueType[] ): JSX.Element { const renderedValues = propertyValues.map(value => ReadOnlyNodePropertiesComponent.renderSinglePropertyValue(value) ); const stringifiedValues = propertyValues .map(value => ReadOnlyNodePropertiesComponent.singlePropertyValueToString(value)) .join(", "); return ( {key} {renderedValues} ); } public static singlePropertyValueToString(value: ViewModels.GremlinPropertyValueType): string { if (value === null) { return "null"; } else if (typeof value === "undefined") { return "undefined"; } else { return value.toString(); } } public static renderSinglePropertyValue(value: ViewModels.GremlinPropertyValueType): JSX.Element { let singlePropValue = value; let className = "propertyValue"; if (singlePropValue === null) { singlePropValue = "null"; className += " isNull"; } else if (typeof singlePropValue === "undefined") { singlePropValue = "undefined"; } else { singlePropValue = value.toString(); } return (
{singlePropValue}
); } }