From 7d05d0cea014b370601546a30f9e616d1efe5178 Mon Sep 17 00:00:00 2001 From: Emiliano Ciavatta Date: Wed, 8 Jul 2020 13:21:13 +0200 Subject: Add connections display formats --- frontend/src/components/Connection.scss | 2 +- frontend/src/components/ConnectionContent.js | 85 +++++++++++++++++++++----- frontend/src/components/ConnectionContent.scss | 5 +- 3 files changed, 75 insertions(+), 17 deletions(-) (limited to 'frontend/src/components') diff --git a/frontend/src/components/Connection.scss b/frontend/src/components/Connection.scss index d3003bd..5ad195d 100644 --- a/frontend/src/components/Connection.scss +++ b/frontend/src/components/Connection.scss @@ -58,4 +58,4 @@ .arrow::after { border-right-color: $color-primary-4; } -} \ No newline at end of file +} diff --git a/frontend/src/components/ConnectionContent.js b/frontend/src/components/ConnectionContent.js index db63cbe..ece4bd6 100644 --- a/frontend/src/components/ConnectionContent.js +++ b/frontend/src/components/ConnectionContent.js @@ -1,37 +1,90 @@ import React, {Component} from 'react'; import './ConnectionContent.scss'; -import {Dropdown} from 'react-bootstrap'; +import {Col, Container, Dropdown, Row} from 'react-bootstrap'; +import axios from 'axios'; +import {withRouter} from "react-router-dom"; +import {Redirect} from "react-router"; class ConnectionContent extends Component { + + constructor(props) { + super(props); + this.state = { + loading: false, + connectionContent: null, + format: "default" + }; + + this.validFormats = ["default", "hex", "hexdump", "base32", "base64", "ascii", "binary", "decimal", "octal"]; + this.setFormat = this.setFormat.bind(this); + } + + componentDidMount() { + if ('format' in this.props.match.params) { + this.setFormat(this.props.match.params.format); + } + } + + componentDidUpdate(prevProps, prevState, snapshot) { + if (this.props.connection !== null && ( + this.props.connection !== prevProps.connection || this.state.format !== prevState.format)) { + this.setState({loading: true}); + axios.get(`/api/streams/${this.props.connection.id}?format=${this.state.format}`).then(res => { + this.setState({ + connectionContent: res.data, + loading: false + }); + }); + } + } + + setFormat(format) { + if (this.validFormats.includes(format)) { + this.setState({format: format}); + } + } + render() { - let content = this.props.connectionPayload; + let content = this.state.connectionContent; - if (content === undefined) { + if (content === null) { return
nope
; } - let payload = content.map(c => - - {c.content} + const format = this.state.format !== "default" ? `/${this.state.format}` : ""; + const redirect = ; + let payload = content.map((c, i) => + + {c.content} ); return (
- - + + + ciao + + + + + + format - plain - hex - hexdump - base32 - base64 - ascii + plain + hex + hexdump + base32 + base64 + ascii + binary + decimal + octal @@ -40,6 +93,8 @@ class ConnectionContent extends Component {
{payload}
+ {redirect} +
); @@ -48,4 +103,4 @@ class ConnectionContent extends Component { } -export default ConnectionContent; +export default withRouter(ConnectionContent); diff --git a/frontend/src/components/ConnectionContent.scss b/frontend/src/components/ConnectionContent.scss index 61d9f63..a1b4afd 100644 --- a/frontend/src/components/ConnectionContent.scss +++ b/frontend/src/components/ConnectionContent.scss @@ -8,7 +8,10 @@ pre { background-color: $color-primary-0; padding: 10px 20px; - word-break: break-all; + word-break: break-word; + max-width: 100%; + white-space: pre-wrap; + height: 100%; } .from-client { -- cgit v1.2.3-70-g09d2