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/ConnectionContent.js | 85 +++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 15 deletions(-) (limited to 'frontend/src/components/ConnectionContent.js') 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
{payload}+ {redirect} +