From 5b7a23ca30b7eac69720860b61f6e176716f7e2b Mon Sep 17 00:00:00 2001 From: Logan Allen Date: Fri, 12 Jun 2020 15:58:10 -0400 Subject: [PATCH] js: added minimal graph-store reducer --- pkg/interface/src/reducers/graph-update.js | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pkg/interface/src/reducers/graph-update.js diff --git a/pkg/interface/src/reducers/graph-update.js b/pkg/interface/src/reducers/graph-update.js new file mode 100644 index 0000000000..ee1156399b --- /dev/null +++ b/pkg/interface/src/reducers/graph-update.js @@ -0,0 +1,43 @@ +import _ from 'lodash'; + +export default class GraphReducer { + reduce(json, state) { + const data = _.get(json, 'graph-update', false); + if (data) { + this.keys(data, state); + this.addGraph(data, state); + } + } + + keys(json, state) { + const data = _.get(json, 'keys', false); + if (data) { + state.keys = data.map((res) => { + return res.ship + '/' + res.name; + }); + } + } + + addGraph(json, state) { + const data = _.get(json, 'add-graph', false); + if (data) { + if (!('graphs' in state)) { + state.graphs = {}; + } + let resource = data.resource.ship + '/' + data.resource.name; + state.graphs[resource] = data.graph; + } + } + + removeGraph(json, state) { + const data = _.get(json, 'remove-graph', false); + if (data) { + if (!('graphs' in state)) { + state.graphs = {}; + } + let resource = data.resource.ship + '/' + data.resource.name; + delete state.graphs[resource]; + } + } + +}