Fix most eslint warnings
This commit is contained in:
parent
196aa44895
commit
8d2d39cb0e
6 changed files with 16 additions and 12 deletions
|
|
@ -137,6 +137,6 @@ module.exports = {
|
||||||
// flow
|
// flow
|
||||||
"flowtype/no-dupe-keys": "error",
|
"flowtype/no-dupe-keys": "error",
|
||||||
"flowtype/no-weak-types": "warn",
|
"flowtype/no-weak-types": "warn",
|
||||||
"flowtype/require-variable-type": "warn"
|
"flowtype/require-variable-type": "off" // wait for https://github.com/gajus/eslint-plugin-flowtype/issues/198 to be resolved
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ export type AppState = {
|
||||||
selectedControl: ?Control,
|
selectedControl: ?Control,
|
||||||
drawerOpened: boolean,
|
drawerOpened: boolean,
|
||||||
mqttState: State,
|
mqttState: State,
|
||||||
mqttSend: (topic: string, value: any) => void,
|
mqttSend: (topic: string, value: Actual) => void,
|
||||||
mqttConnected: boolean,
|
mqttConnected: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -91,7 +91,7 @@ class App extends React.Component<AppProps & Classes, AppState> {
|
||||||
this.setState({drawerOpened: false});
|
this.setState({drawerOpened: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
changeState(topic: string, value: any) {
|
changeState(topic: string, value: Actual) {
|
||||||
const rawTopic = this.props.config.topics[topic].command;
|
const rawTopic = this.props.config.topics[topic].command;
|
||||||
if (rawTopic == null) {
|
if (rawTopic == null) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -18,9 +18,10 @@ import keyOf from "utils/keyOf";
|
||||||
type UiItemProps<I> = {
|
type UiItemProps<I> = {
|
||||||
item: I,
|
item: I,
|
||||||
state: State,
|
state: State,
|
||||||
onChangeState: (topic: string, nextState: any) => void
|
onChangeState: (topic: string, nextState: Actual) => void
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line flowtype/no-weak-types
|
||||||
export default class UiItem<I:Object> extends React.Component<UiItemProps<I>> {
|
export default class UiItem<I:Object> extends React.Component<UiItemProps<I>> {
|
||||||
constructor(props: UiItemProps<I>) {
|
constructor(props: UiItemProps<I>) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
@ -58,7 +59,7 @@ export class UiControl<I: UIControl> extends UiItem<I> {
|
||||||
super(props);
|
super(props);
|
||||||
}
|
}
|
||||||
|
|
||||||
changeState(next: any) {
|
changeState(next: Actual) {
|
||||||
if (this.props.item.topic == null) {
|
if (this.props.item.topic == null) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Missing topic in ${this.props.item.type} "${this.props.item.text}"`
|
`Missing topic in ${this.props.item.type} "${this.props.item.text}"`
|
||||||
|
|
@ -131,7 +132,7 @@ export class Toggle extends UiControl<UIToggle> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class DropDown extends UiControl<UIDropDown> {
|
export class DropDown extends UiControl<UIDropDown> {
|
||||||
runPrimaryAction = (next?: any) => {
|
runPrimaryAction = (next?: Actual) => {
|
||||||
if (this.isEnabled()) {
|
if (this.isEnabled()) {
|
||||||
const control = this.props.item;
|
const control = this.props.item;
|
||||||
const keys = _.keys(control.options);
|
const keys = _.keys(control.options);
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ import { Toggle, DropDown, Link, Section, Text } from "./UiItem";
|
||||||
export type UiItemListProps = {
|
export type UiItemListProps = {
|
||||||
controls: Array<ControlUI>,
|
controls: Array<ControlUI>,
|
||||||
state: State,
|
state: State,
|
||||||
onChangeState: (topic: string, nextState: any) => void
|
onChangeState: (topic: string, nextState: Actual) => void
|
||||||
};
|
};
|
||||||
|
|
||||||
export default class UiItemList extends React.Component<UiItemListProps> {
|
export default class UiItemList extends React.Component<UiItemListProps> {
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,24 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from "react";
|
import * as React from "react";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
|
import { getInternals, getActuals } from "utils/state";
|
||||||
|
|
||||||
export default function parseIconName(name: string): string {
|
export default function parseIconName(name: string): string {
|
||||||
return `mdi ${name.split(" ").map((icon) => "mdi-".concat(icon)).join(" ")}`;
|
return `mdi ${name.split(" ").map((icon) => "mdi-".concat(icon)).join(" ")}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const renderIcon = (name: string, extraClass?: string) => {
|
export const renderIcon = (name: string, extraClass?: string): React.Node => {
|
||||||
return <i className={`${extraClass || ""} ${parseIconName(name)}`}></i>;
|
return <i className={`${extraClass || ""} ${parseIconName(name)}`}></i>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const controlGetIcon = (control: Control, state: State): string => {
|
export const controlGetIcon = (control: Control, state: State): string => {
|
||||||
const internals = _.mapValues(state, (x) => x.internal || x.actual);
|
const internals: Map<string, Internal> = getInternals(state);
|
||||||
const actuals = _.mapValues(state, (x) => x.actual);
|
const actuals: Map<string, Actual> = getActuals(state);
|
||||||
return typeof control.icon !== "function" ? control.icon
|
return typeof control.icon !== "function" ? control.icon
|
||||||
: control.icon(internals, actuals, state);
|
: control.icon(internals, actuals, state);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderControlIcon = (control: Control,
|
export const renderControlIcon = (control: Control,
|
||||||
state: State, extraClass?: string) => {
|
state: State, extraClass?: string): React.Node => {
|
||||||
return renderIcon(controlGetIcon(control, state), extraClass);
|
return renderIcon(controlGetIcon(control, state), extraClass);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,8 @@ declare type Space = {
|
||||||
mqtt: string
|
mqtt: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
declare type Internal = string;
|
||||||
|
declare type Actual = any;
|
||||||
declare type StateValue = {
|
declare type StateValue = {
|
||||||
internal: string,
|
internal: string,
|
||||||
actual: any
|
actual: any
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue