import React, {Component} from 'react'; import './Connection.scss'; import axios from 'axios' import {Button, Form, OverlayTrigger, Popover} from "react-bootstrap"; class Connection extends Component { constructor(props) { super(props); this.state = { update: false, copiedMessage: false }; this.copyTextarea = React.createRef(); this.handleAction = this.handleAction.bind(this); } handleAction(name) { if (name === "hide") { const enabled = !this.props.data.hidden; axios.post(`/api/connections/${this.props.data.id}/${enabled ? "hide" : "show"}`) .then(res => { if (res.status === 202) { this.props.onEnabled(!enabled); this.setState({update: true}); } }); } if (name === "mark") { const marked = this.props.data.marked; axios.post(`/api/connections/${this.props.data.id}/${marked ? "unmark" : "mark"}`) .then(res => { if (res.status === 202) { this.props.onMarked(!marked); this.setState({update: true}); } }); } if (name === "copy") { this.copyTextarea.current.select(); document.execCommand('copy'); this.setState({copiedMessage: true}); setTimeout(() => this.setState({copiedMessage: false}), 3000); } } render() { let conn = this.props.data; let serviceName = "/dev/null"; let serviceColor = "#0F192E"; if (conn.service.port !== 0) { serviceName = conn.service.name; serviceColor = conn.service.color; } let startedAt = new Date(conn.started_at); let closedAt = new Date(conn.closed_at); let processedAt = new Date(conn.processed_at); let duration = ((closedAt - startedAt) / 1000).toFixed(3); let timeInfo =
Started at {startedAt.toLocaleDateString() + " " + startedAt.toLocaleTimeString()}
Processed at {processedAt.toLocaleDateString() + " " + processedAt.toLocaleTimeString()}
Closed at {closedAt.toLocaleDateString() + " " + closedAt.toLocaleTimeString()}
; let classes = "connection"; if (this.props.selected) { classes += " connection-selected"; } const popoverFor = function (name, content) { return {content} ; }; const commentPopoverContent =
Click to {conn.comment.length > 0 ? "edit" : "add"} comment {conn.comment && }
; const copyPopoverContent =
{this.state.copiedMessage ? Copied! : Click to copy the connection id}
; return ( this.props.onSelected()}>{conn.ip_src} this.props.onSelected()}>{conn.port_src} this.props.onSelected()}>{conn.ip_dst} this.props.onSelected()}>{conn.port_dst} this.props.onSelected()}> {duration}s this.props.onSelected()}>{conn.client_bytes} this.props.onSelected()}>{conn.server_bytes} Hide this connection from the list)}> this.handleAction("hide")}>% Mark this connection)}> this.handleAction("mark")}>!! this.handleAction("comment")}>@ this.handleAction("copy")}># ); } } export default Connection;