Fix two bugs

Fix the flow types for the search bar
Fix that sometimes the UI would not update in the sidebar
This commit is contained in:
uwap 2018-10-20 09:02:24 +02:00
parent c9ec79442b
commit 08aff120bd
3 changed files with 18 additions and 17 deletions

View file

@ -61,14 +61,15 @@ class App extends React.PureComponent<AppProps & Classes, AppState> {
search: "", search: "",
error: null error: null
}; };
this.controlMap = (search: string) => }
controlMap = (search: string) =>
<ControlMap width={1000} height={700} zoom={0} <ControlMap width={1000} height={700} zoom={0}
layers={this.props.config.layers} layers={this.props.config.layers}
controls={this.props.config.controls} controls={this.props.config.controls}
onChangeControl={this.changeControl} onChangeControl={this.changeControl}
search={search} search={search}
/>; />;
}
get topics(): Topics { get topics(): Topics {
return Array.isArray(this.props.config.topics) ? return Array.isArray(this.props.config.topics) ?

View file

@ -4,8 +4,9 @@ import { Map, ImageOverlay, Marker, LayersControl } from "react-leaflet";
import { CRS, point, divIcon } from "leaflet"; import { CRS, point, divIcon } from "leaflet";
import map from "lodash/map"; import map from "lodash/map";
import filter from "lodash/filter"; import filter from "lodash/filter";
import reduce from "lodash/reduce";
import MqttContext from "mqtt/context"; import MqttContext from "mqtt/context";
import type { Controls, Control } from "config/flowtypes"; import type { Controls, Control, UIControl, ControlUI } from "config/flowtypes";
export type Point = [number, number]; export type Point = [number, number];
@ -58,7 +59,7 @@ const renderMarker = (props: ControlMapProps) =>
</MqttContext.Consumer> </MqttContext.Consumer>
); );
const safeIncludes = (o: {type?: string, text?: string, topic?: string}, const safeIncludes = (o: {+type?: string, +text?: string, +topic?: string},
s: string) => { s: string) => {
if (o.type != null) { if (o.type != null) {
if (o.type.toLowerCase().includes(s)) { if (o.type.toLowerCase().includes(s)) {
@ -78,16 +79,14 @@ const safeIncludes = (o: {type?: string, text?: string, topic?: string},
return false; return false;
}; };
const isVisible = (props: ControlMapProps) => (c: UIControl) => { const isVisible = (props: ControlMapProps) =>
(c: UIControl & {ui?: Array<ControlUI>}) => {
if (safeIncludes(c, props.search.toLowerCase())) { if (safeIncludes(c, props.search.toLowerCase())) {
return true; return true;
} }
if (c.ui != null) { if (c.ui != null) {
for (let k in c.ui) { return reduce(c.ui,
if (safeIncludes(c.ui[k], props.search.toLowerCase())) { (b, e) => b || safeIncludes(e, props.search.toLowerCase()), false);
return true;
}
}
} }
return false; return false;
}; };

View file

@ -84,7 +84,8 @@ export class UiControl<I: UIControl> extends UiItem<I> {
// $FlowFixMe // $FlowFixMe
shouldComponentUpdate(nextProps: UiItemProps<I>) { // TODO: Fix Flow shouldComponentUpdate(nextProps: UiItemProps<I>) { // TODO: Fix Flow
return nextProps.state[nextProps.item.topic] !== return nextProps.item.topic !== this.props.item.topic
|| nextProps.state[nextProps.item.topic] !==
this.props.state[this.props.item.topic]; this.props.state[this.props.item.topic];
} }