diff --git a/src/components/App.js b/src/components/App.js index 5d1d94a..e8b7d85 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -12,6 +12,9 @@ import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider"; import createMuiTheme from "@material-ui/core/styles/createMuiTheme"; import withStyles from "@material-ui/core/styles/withStyles"; import * as Colors from "@material-ui/core/colors"; +import Snackbar from "@material-ui/core/Snackbar"; +import IconButton from "@material-ui/core/IconButton"; +import Typography from "@material-ui/core/Typography"; import SideBar from "components/SideBar"; import ControlMap from "components/ControlMap"; @@ -30,6 +33,7 @@ export type AppState = { mqttState: State, mqttSend: (topic: string, value: Buffer) => void, mqttConnected: boolean, + error: ?string }; class App extends React.PureComponent { @@ -48,7 +52,8 @@ class App extends React.PureComponent { filter(keys(this.topics), (x) => this.topics[x].state != null), (x) => this.topics[x].state.name) }), - mqttConnected: false + mqttConnected: false, + error: null }; } @@ -74,21 +79,25 @@ class App extends React.PureComponent { } receiveMessage(rawTopic: string, message: Buffer) { - const topics = filter( - keys(this.topics), - (k) => this.topics[k].state != null && - this.topics[k].state.name === rawTopic - ); - if (topics.length === 0) { - return; - } - for (let i in topics) { - const topic = topics[i]; - const stateTopic = this.topics[topic].state; - const parseValue = stateTopic ? stateTopic.type : null; - const val = parseValue == null ? message.toString() : parseValue(message); - this.setState({mqttState: Object.assign({}, merge(this.state.mqttState, - { [topic]: val}))}); + try { + const topics = filter( + keys(this.topics), + (k) => this.topics[k].state != null && + this.topics[k].state.name === rawTopic + ); + if (topics.length === 0) { + return; + } + for (let i in topics) { + const topic = topics[i]; + const stateTopic = this.topics[topic].state; + const parseVal = stateTopic ? stateTopic.type : null; + const val = parseVal == null ? message.toString() : parseVal(message); + this.setState({mqttState: Object.assign({}, merge(this.state.mqttState, + { [topic]: val}))}); + } + } catch (err) { + this.setState({ error: err.toString() }); } } @@ -101,14 +110,19 @@ class App extends React.PureComponent { } changeState(topic: string, value: string) { - if (this.topics[topic].command == null) { - return; + try { + if (this.topics[topic].command == null) { + return; + } + const rawTopic = this.topics[topic].command.name; + const transformValue = this.topics[topic].command.type; + const val = + transformValue == null ? value : transformValue(Buffer.from(value)); + this.state.mqttSend(rawTopic, Buffer.from(val)); + throw new Error("test"); + } catch (err) { + this.setState({ error: err.toString() }); } - const rawTopic = this.topics[topic].command.name; - const transformValue = this.topics[topic].command.type; - const val = - transformValue == null ? value : transformValue(Buffer.from(value)); - this.state.mqttSend(rawTopic, Buffer.from(val)); } render() { @@ -138,6 +152,30 @@ class App extends React.PureComponent { onChangeControl={this.changeControl.bind(this)} state={this.state.mqttState} /> + this.setState({ error: null })} + ContentProps={{ + "aria-describedby": "errormsg" + }} + message={ + + {this.state.error} + } + action={ + this.setState({ error: null })}> + + + } /> ); } diff --git a/src/config/types.js b/src/config/types.js index 91bb28b..6867807 100644 --- a/src/config/types.js +++ b/src/config/types.js @@ -12,9 +12,16 @@ export const json = (path: string, innerType?: TopicType): TopicType => { export type TypeOptionParam = { otherwise?: string, [string]: string }; export const option = (values: TypeOptionParam): TopicType => { - // TODO: error - const defaultValue = values.otherwise != null ? values.otherwise : ""; - const mapVal = (x) => (values[x] != null ? values[x] : defaultValue); + const defaultValue = (x) => { + if (values.otherwise != null) { + return values.otherwise; + } else { + throw new Error( + `Value ${x.toString()} cannot by mapped by the option parameters given` + ); + } + }; + const mapVal = (x) => (values[x] != null ? values[x] : defaultValue(x)); return (x) => mapVal(x.toString()); }; diff --git a/yarn.lock b/yarn.lock index d29ef85..b88c152 100644 --- a/yarn.lock +++ b/yarn.lock @@ -47,8 +47,8 @@ js-tokens "^3.0.0" "@babel/runtime@^7.0.0-beta.42": - version "7.0.0-beta.53" - resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.53.tgz#9df22ae34823ce89f790060594b83ee572e2c5d2" + version "7.0.0-beta.54" + resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.0.0-beta.54.tgz#39ebb42723fe7ca4b3e1b00e967e80138d47cadf" dependencies: core-js "^2.5.7" regenerator-runtime "^0.12.0" @@ -86,8 +86,8 @@ to-fast-properties "^2.0.0" "@material-ui/core@^1.2.1": - version "1.3.1" - resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-1.3.1.tgz#8b4e6db9ed4536e8ccbea0eeff3da0d524e6af2c" + version "1.4.0" + resolved "https://registry.yarnpkg.com/@material-ui/core/-/core-1.4.0.tgz#e535fef84576b096c46e1fb7d6c4c61895155fd3" dependencies: "@babel/runtime" "^7.0.0-beta.42" "@types/jss" "^9.5.3" @@ -99,6 +99,7 @@ deepmerge "^2.0.1" dom-helpers "^3.2.1" hoist-non-react-statics "^2.5.0" + is-plain-object "^2.0.4" jss "^9.3.3" jss-camel-case "^6.0.0" jss-default-unit "^8.0.2" @@ -108,18 +109,18 @@ jss-vendor-prefixer "^7.0.0" keycode "^2.1.9" normalize-scroll-left "^0.1.2" + popper.js "^1.0.0" prop-types "^15.6.0" react-event-listener "^0.6.0" react-jss "^8.1.0" - react-popper "^0.10.0" react-transition-group "^2.2.1" recompose "^0.27.0" scroll "^2.0.3" warning "^4.0.1" "@material-ui/lab@^1.0.0-alpha.5": - version "1.0.0-alpha.5" - resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-1.0.0-alpha.5.tgz#2f53a76c4b53aca044c91392ad5e4b47f9a4b241" + version "1.0.0-alpha.6" + resolved "https://registry.yarnpkg.com/@material-ui/lab/-/lab-1.0.0-alpha.6.tgz#ee5c03a8577a9cbc4e41b2bfbdfc15b561822749" "@mdi/font@^2.0.46": version "2.5.94" @@ -547,14 +548,14 @@ babel-core@^6.25.0, babel-core@^6.26.0: source-map "^0.5.7" babel-eslint@^8.0.1: - version "8.2.5" - resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.5.tgz#dc2331c259d36782aa189da510c43dedd5adc7a3" + version "8.2.6" + resolved "https://registry.yarnpkg.com/babel-eslint/-/babel-eslint-8.2.6.tgz#6270d0c73205628067c0f7ae1693a9e797acefd9" dependencies: "@babel/code-frame" "7.0.0-beta.44" "@babel/traverse" "7.0.0-beta.44" "@babel/types" "7.0.0-beta.44" babylon "7.0.0-beta.44" - eslint-scope "~3.7.1" + eslint-scope "3.7.1" eslint-visitor-keys "^1.0.0" babel-generator@^6.26.0: @@ -1614,22 +1615,22 @@ component-emitter@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" -compressible@~2.0.13: +compressible@~2.0.14: version "2.0.14" resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.14.tgz#326c5f507fbb055f54116782b969a81b67a29da7" dependencies: mime-db ">= 1.34.0 < 2" compression@^1.5.2: - version "1.7.2" - resolved "http://registry.npmjs.org/compression/-/compression-1.7.2.tgz#aaffbcd6aaf854b44ebb280353d5ad1651f59a69" + version "1.7.3" + resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.3.tgz#27e0e176aaf260f7f2c2813c3e440adb9f1993db" dependencies: - accepts "~1.3.4" + accepts "~1.3.5" bytes "3.0.0" - compressible "~2.0.13" + compressible "~2.0.14" debug "2.6.9" on-headers "~1.0.1" - safe-buffer "5.1.1" + safe-buffer "5.1.2" vary "~1.1.2" concat-map@0.0.1: @@ -2220,7 +2221,7 @@ eslint-plugin-react@^7.6.1: jsx-ast-utils "^2.0.1" prop-types "^15.6.2" -eslint-scope@^3.7.1, eslint-scope@~3.7.1: +eslint-scope@3.7.1: version "3.7.1" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8" dependencies: @@ -2294,8 +2295,8 @@ espree@^4.0.0: acorn-jsx "^4.1.1" esprima@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804" + version "4.0.1" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.1.tgz#13b04cdb3e6c5d19df91ab6987a8695619b0aa71" esquery@^1.0.1: version "1.0.1" @@ -2988,8 +2989,8 @@ html-entities@^1.2.0: resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-1.2.1.tgz#0df29351f0721163515dfb9e5543e5f6eed5162f" html-minifier@^3.2.3: - version "3.5.18" - resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-3.5.18.tgz#fc8b02826cbbafc6de19a103c41c830a91cffe5a" + version "3.5.19" + resolved "https://registry.yarnpkg.com/html-minifier/-/html-minifier-3.5.19.tgz#ed53c4b7326fe507bc3a1adbcc3bbb56660a2ebd" dependencies: camel-case "3.0.x" clean-css "4.1.x" @@ -3715,8 +3716,8 @@ lcid@^1.0.0: invert-kv "^1.0.0" leaflet@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.3.1.tgz#86f336d2fb0e2d0ff446677049a5dc34cf0ea60e" + version "1.3.2" + resolved "https://registry.yarnpkg.com/leaflet/-/leaflet-1.3.2.tgz#0e3b62ad2dbfcccc7d530a2c512949f56522a12d" leven@^1.0.0: version "1.0.2" @@ -3970,19 +3971,15 @@ miller-rabin@^4.0.0: bn.js "^4.0.0" brorand "^1.0.1" -"mime-db@>= 1.34.0 < 2": - version "1.34.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.34.0.tgz#452d0ecff5c30346a6dc1e64b1eaee0d3719ff9a" - -mime-db@~1.33.0: - version "1.33.0" - resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db" +"mime-db@>= 1.34.0 < 2", mime-db@~1.35.0: + version "1.35.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.35.0.tgz#0569d657466491283709663ad379a99b90d9ab47" mime-types@~2.1.17, mime-types@~2.1.18: - version "2.1.18" - resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8" + version "2.1.19" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.19.tgz#71e464537a7ef81c15f2db9d97e913fc0ff606f0" dependencies: - mime-db "~1.33.0" + mime-db "~1.35.0" mime@1.4.1: version "1.4.1" @@ -4616,7 +4613,7 @@ pluralize@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777" -popper.js@^1.14.1: +popper.js@^1.0.0: version "1.14.3" resolved "https://registry.yarnpkg.com/popper.js/-/popper.js-1.14.3.tgz#1438f98d046acf7b4d78cd502bf418ac64d4f095" @@ -4724,7 +4721,7 @@ promise@^7.1.1: dependencies: asap "~2.0.3" -prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2: +prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.2: version "15.6.2" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.2.tgz#05d5ca77b4453e985d60fc7ff8c859094a497102" dependencies: @@ -4895,13 +4892,6 @@ react-lifecycles-compat@^3.0.2, react-lifecycles-compat@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" -react-popper@^0.10.0: - version "0.10.4" - resolved "https://registry.yarnpkg.com/react-popper/-/react-popper-0.10.4.tgz#af2a415ea22291edd504678d7afda8a6ee3295aa" - dependencies: - popper.js "^1.14.1" - prop-types "^15.6.1" - react-tap-event-plugin@^3.0.0: version "3.0.3" resolved "https://registry.yarnpkg.com/react-tap-event-plugin/-/react-tap-event-plugin-3.0.3.tgz#bc5fd0ee3fd3ab5224c1c2ff6f0750204ae89802" @@ -5199,8 +5189,8 @@ rxjs@^5.5.2: symbol-observable "1.0.1" rxjs@^6.1.0: - version "6.2.1" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.2.1.tgz#246cebec189a6cbc143a3ef9f62d6f4c91813ca1" + version "6.2.2" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.2.2.tgz#eb75fa3c186ff5289907d06483a77884586e1cf9" dependencies: tslib "^1.9.0" @@ -5208,7 +5198,7 @@ safe-buffer@5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" -safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: +safe-buffer@5.1.2, safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@^5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.2" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d" @@ -5824,8 +5814,8 @@ uglify-es@^3.3.4: source-map "~0.6.1" uglify-js@3.4.x: - version "3.4.4" - resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.4.tgz#92e79532a3aeffd4b6c65755bdba8d5bad98d607" + version "3.4.5" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.4.5.tgz#650889c0766cf0f6fd5346cea09cd212f544be69" dependencies: commander "~2.16.0" source-map "~0.6.1" @@ -5959,10 +5949,8 @@ url@^0.11.0: querystring "0.2.0" use@^3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/use/-/use-3.1.0.tgz#14716bf03fdfefd03040aef58d8b4b85f3a7c544" - dependencies: - kind-of "^6.0.2" + version "3.1.1" + resolved "https://registry.yarnpkg.com/use/-/use-3.1.1.tgz#d50c8cac79a19fbc20f2911f56eb973f4e10070f" user-home@^1.1.1: version "1.1.1" @@ -6142,8 +6130,8 @@ webpack-sources@^1.0.1, webpack-sources@^1.1.0: source-map "~0.6.1" webpack@^4.3.0: - version "4.16.0" - resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.16.0.tgz#660dae90890e55b8ed17c6f9d17bebb01dab5b4c" + version "4.16.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.16.1.tgz#2c4b89ea648125c3e67bcca6adf49ce2c14b2d31" dependencies: "@webassemblyjs/ast" "1.5.13" "@webassemblyjs/helper-module-context" "1.5.13" @@ -6156,7 +6144,7 @@ webpack@^4.3.0: ajv-keywords "^3.1.0" chrome-trace-event "^1.0.0" enhanced-resolve "^4.1.0" - eslint-scope "^3.7.1" + eslint-scope "^4.0.0" json-parse-better-errors "^1.0.2" loader-runner "^2.3.0" loader-utils "^1.1.0"