From 155f96c218e466fbcdc45a222e879fda2df6ca97 Mon Sep 17 00:00:00 2001 From: slice Date: Fri, 13 Jul 2018 12:29:46 -0700 Subject: [PATCH] update service latency metric upon ws data --- priv/frontend/src/App.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/priv/frontend/src/App.js b/priv/frontend/src/App.js index c0b32dd..a0ae5c7 100644 --- a/priv/frontend/src/App.js +++ b/priv/frontend/src/App.js @@ -51,18 +51,23 @@ export default class App extends Component { const [, name] = channel.split(':'); + log('updating from channel:', channel); + const { metrics } = this.state; const graph = metrics.graph[name].slice(1); const newGraph = [data, ...graph]; log('adding data:', data); - this.setState((prevState, _props) => { - const clone = Object.assign({}, prevState.metrics); - clone.graph[name] = newGraph; + this.setState(({ metrics: oldMetrics }, _props) => { + const newMetrics = { ...oldMetrics }; + newMetrics.graph[name] = newGraph; + + const [, latency] = data; + newMetrics.status[name].latency = latency; return { - metrics: clone, + metrics: newMetrics, }; }); } @@ -128,19 +133,12 @@ export default class App extends Component { return (
-

-elstatus -

+

elstatus

{this.state.loading ? ( -
-Loading metrics... -
+
Loading metrics...
) : null} {this.state.error ? ( -
-Error: - {this.state.error} -
+
Error: {this.state.error}
) : null} {metrics}