2018-07-19 23:48:32 -06:00
|
|
|
|
import * as React from "react";
|
|
|
|
|
import { Row, Col, BlurableInput } from "../../ui";
|
2019-04-02 13:59:37 -06:00
|
|
|
|
|
2018-07-19 23:48:32 -06:00
|
|
|
|
import { AxisInputBoxGroupState } from "../interfaces";
|
|
|
|
|
import { Xyz } from "../../devices/interfaces";
|
|
|
|
|
import { AxisInputBox } from "../axis_input_box";
|
|
|
|
|
import { isNumber } from "lodash";
|
2018-07-24 21:45:38 -06:00
|
|
|
|
import { LocationSelectionProps } from "./interfaces";
|
2019-01-13 16:39:26 -07:00
|
|
|
|
import { parseIntInput } from "../../util";
|
2019-04-02 13:59:37 -06:00
|
|
|
|
import { t } from "../../i18next_wrapper";
|
2018-07-19 23:48:32 -06:00
|
|
|
|
|
|
|
|
|
/** Select a location filter for sensor readings. */
|
|
|
|
|
export const LocationSelection =
|
|
|
|
|
({ location, deviation, setDeviation, setLocation }: LocationSelectionProps) =>
|
|
|
|
|
<div>
|
|
|
|
|
<Row>
|
|
|
|
|
{["x", "y", "z"].map(axis =>
|
|
|
|
|
<Col key={axis + "_heading"} xs={3}>
|
|
|
|
|
<label>{axis}</label>
|
|
|
|
|
</Col>)}
|
|
|
|
|
<Col xs={3}>
|
|
|
|
|
<label>{t("Deviation")}</label>
|
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
<Row>
|
|
|
|
|
{["x", "y", "z"].map((axis: Xyz) =>
|
|
|
|
|
<AxisInputBox
|
|
|
|
|
key={axis}
|
|
|
|
|
axis={axis}
|
|
|
|
|
value={location ? location[axis] : undefined}
|
|
|
|
|
onChange={(a: Xyz, v) => {
|
|
|
|
|
const newLocation = (location || {});
|
|
|
|
|
newLocation[a] = v;
|
|
|
|
|
setLocation(newLocation);
|
|
|
|
|
}} />)}
|
|
|
|
|
<Col xs={3}>
|
|
|
|
|
<BlurableInput
|
2019-01-13 16:39:26 -07:00
|
|
|
|
type="number"
|
2018-07-19 23:48:32 -06:00
|
|
|
|
value={deviation}
|
2019-01-13 16:39:26 -07:00
|
|
|
|
onCommit={e => setDeviation(parseIntInput(e.currentTarget.value))} />
|
2018-07-19 23:48:32 -06:00
|
|
|
|
</Col>
|
|
|
|
|
</Row>
|
|
|
|
|
</div>;
|
|
|
|
|
|
|
|
|
|
/** Display sensor reading location filter settings. */
|
|
|
|
|
export const LocationDisplay = ({ location, deviation }: {
|
|
|
|
|
location: AxisInputBoxGroupState | undefined,
|
|
|
|
|
deviation: number
|
|
|
|
|
}) => {
|
|
|
|
|
return <div className="location">
|
|
|
|
|
{["x", "y", "z"].map((axis: Xyz) => {
|
|
|
|
|
const axisString = () => {
|
|
|
|
|
if (location) {
|
|
|
|
|
const axisValue = location[axis];
|
|
|
|
|
if (isNumber(axisValue)) {
|
|
|
|
|
return deviation
|
|
|
|
|
? `${axisValue - deviation}–${axisValue + deviation}`
|
|
|
|
|
: `${axisValue}`;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return <div key={axis}>
|
|
|
|
|
<label>{axis}:</label>
|
|
|
|
|
<span>{axisString() || t("any")}</span>
|
|
|
|
|
</div>;
|
|
|
|
|
})}
|
|
|
|
|
</div>;
|
|
|
|
|
};
|