import React, {Component} from 'react'; import './Services.scss'; import {Button, ButtonGroup, Col, Container, Form, FormControl, InputGroup, Modal, Row, Table} from "react-bootstrap"; import axios from 'axios' import {createCurlCommand} from '../utils'; class Services extends Component { constructor(props) { super(props); this.state = { services: {}, port: "", portValid: false } this.portChanged = this.portChanged.bind(this); } componentDidMount() { axios.get("/api/services").then(res => this.setState({services: res.data})) } portChanged(event) { let value = event.target.value.replace(/[^\d]/gi, '') let intValue = parseInt(value) this.setState({port: value, portValid: intValue > 0 && intValue <= 65565}) } render() { let curl = createCurlCommand("/services", { "port": this.state.port, "name": "aaaaa", "color": "#fff", "notes": "aaa" }) let rows = Object.values(this.state.services).map(s => {s.port} {s.name} ) return ( ~/services {rows}
name port
port: {!this.state.portValid ? "assert(1 <= port <= 65565)" : ""} name: {"assert(len(name) >= 3)"} color: notes:
{curl}
); } } export default Services;