From a6301b476cd69463b4b675bcc497b2c14d2dba08 Mon Sep 17 00:00:00 2001 From: Tiago Miguel Date: Tue, 25 Jun 2019 13:07:00 -0300 Subject: [PATCH] adjust error configuration --- .../src/configuration/Configuration.jsx | 42 ++++++++----------- .../src/testModule/TestFunctions.jsx | 1 + unbrake-frontend/src/utils/Constants.jsx | 2 +- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/unbrake-frontend/src/configuration/Configuration.jsx b/unbrake-frontend/src/configuration/Configuration.jsx index 5555204e..1b0bf340 100644 --- a/unbrake-frontend/src/configuration/Configuration.jsx +++ b/unbrake-frontend/src/configuration/Configuration.jsx @@ -4,7 +4,7 @@ import { withStyles } from "@material-ui/core/styles"; import { Grid, Button } from "@material-ui/core"; import PropTypes from "prop-types"; import { connect } from "react-redux"; -import { reduxForm } from "redux-form"; +import { reduxForm, initialize } from "redux-form"; import Request from "../utils/Request"; import { API_URL_GRAPHQL } from "../utils/Constants"; import ConfigurationForm from "./ConfigurationForm"; @@ -74,7 +74,7 @@ class Configuration extends React.Component { } componentDidMount() { - const { configId } = this.props; + const { configId, sendMessage, dispatch } = this.props; const url = `${API_URL_GRAPHQL}?query=query{configNotDefault{id, name}}`; const method = "GET"; @@ -83,7 +83,16 @@ class Configuration extends React.Component { if (data !== null) this.setState({ allConfiguration: data }); }); - if (configId > invalidId) this.handleSelectConfig(configId); + if (configId > invalidId) + selectConfigurationDataBase(configId, sendMessage, dispatch); + } + + componentDidUpdate(prevProps) { + const { configId } = this.props; + if (configId !== prevProps.configId) { + return true; + } + return false; } handleNext() { @@ -130,28 +139,8 @@ class Configuration extends React.Component { } } - resetState() { - this.setState({ - configuration: { - CONFIG_ENSAIO: { - LSL: "", - LWT: "", - NOS: "", - TAO: false, - TAS: "", - TAT: "", - TBS: "", - TMO: false, - USL: "", - UWT: "" - } - } - }); - } - handleUpDefault() { - this.resetState(); - const { sendMessage } = this.props; + const { sendMessage, changeConfig, dispatch } = this.props; const url = `${API_URL_GRAPHQL}?query=query{configDefault{${query}}}`; const method = "GET"; @@ -174,13 +163,15 @@ class Configuration extends React.Component { }); const position = response.data.configDefault.length - positionVector; const data = response.data.configDefault[position]; + changeConfig({ configId: data.id }); const configurationDefault = createConfig(data); + + dispatch(initialize("configuration", configurationDefault.CONFIG_ENSAIO)); this.setState({ configuration: configurationDefault }); }); } handleChange(event) { - this.resetState(); const { changeConfig, sendMessage, dispatch } = this.props; const { target } = event; @@ -188,6 +179,7 @@ class Configuration extends React.Component { this.setState({ [event.target.name]: event.target.value }); return; } + const idSelect = target.value === invalidId ? "" : target.value; changeConfig({ configId: idSelect }); diff --git a/unbrake-frontend/src/testModule/TestFunctions.jsx b/unbrake-frontend/src/testModule/TestFunctions.jsx index 7c2d11da..b228e1b0 100644 --- a/unbrake-frontend/src/testModule/TestFunctions.jsx +++ b/unbrake-frontend/src/testModule/TestFunctions.jsx @@ -185,6 +185,7 @@ const requestTest = (states, functions, dispatchs) => { url = `${API_URL_GRAPHQL}?query=mutation{submitTesting(mqttHost:"${MQTT_HOST}",mqttPort:8080,testingId:${ testing.id }){succes}}`; + Request(url, "POST").then(json => { const dataLocal = json.data; const errosLocal = json.errors; diff --git a/unbrake-frontend/src/utils/Constants.jsx b/unbrake-frontend/src/utils/Constants.jsx index 7c5d8796..e984a0cb 100644 --- a/unbrake-frontend/src/utils/Constants.jsx +++ b/unbrake-frontend/src/utils/Constants.jsx @@ -1,6 +1,6 @@ export const API_URL = process.env.REACT_APP_API_URL; export const API_URL_GRAPHQL = process.env.REACT_APP_API_URL; -export const MQTT_HOST = process.env.REACT_APP_MQTT_HOST; +export const MQTT_HOST = "unbrake-hom.ml"; // process.env.REACT_APP_MQTT_HOST; export const MQTT_PORT = process.env.REACT_APP_MQTT_PORT; export const base10 = 10;