click row to edit

This commit is contained in:
proddy
2021-11-15 15:22:46 +01:00
parent c0bf623266
commit cb2c898b7e
2 changed files with 29 additions and 8 deletions

View File

@@ -219,7 +219,9 @@ class EMSESPDataForm extends Component<
};
sendCommand = (dv: DeviceValue) => {
if (dv.c && this.props.authenticatedContext.me.admin) {
this.setState({ edit_devicevalue: dv });
}
};
handleSensorChange = (name: keyof Sensor) => (
@@ -285,7 +287,9 @@ class EMSESPDataForm extends Component<
};
sendSensor = (sn: Sensor) => {
if (this.props.authenticatedContext.me.admin) {
this.setState({ edit_Sensor: sn });
}
};
noDevices = () => {
@@ -391,7 +395,11 @@ class EMSESPDataForm extends Component<
</TableHead>
<TableBody>
{data.sensors.map((sensorData) => (
<TableRow key={sensorData.n} hover>
<TableRow
key={sensorData.n}
hover
onClick={() => this.sendSensor(sensorData)}
>
<TableCell padding="checkbox" style={{ width: 18 }}>
{me.admin && (
<CustomTooltip title="edit" placement="left-end">
@@ -553,7 +561,6 @@ class EMSESPDataForm extends Component<
renderDeviceData() {
const { deviceData } = this.state;
const { width } = this.props;
const me = this.props.authenticatedContext.me;
if (this.noDevices()) {
return;
@@ -580,9 +587,13 @@ class EMSESPDataForm extends Component<
<TableHead></TableHead>
<TableBody>
{deviceData.data.map((item, i) => (
<TableRow hover key={i}>
<TableRow
hover
key={i}
onClick={() => this.sendCommand(item)}
>
<TableCell padding="checkbox" style={{ width: 18 }}>
{item.c && me.admin && (
{item.c && this.props.authenticatedContext.me.admin && (
<CustomTooltip
title="change value"
placement="left-end"

View File

@@ -15,7 +15,7 @@ import {
} from '@material-ui/core';
import { FormButton } from '../components';
import { DeviceValue, DeviceValueUOM_s } from './EMSESPtypes';
import { DeviceValue, DeviceValueUOM, DeviceValueUOM_s } from './EMSESPtypes';
interface ValueFormProps {
devicevalue: DeviceValue;
@@ -26,6 +26,16 @@ interface ValueFormProps {
) => (event: React.ChangeEvent<HTMLInputElement>) => void;
}
function formatValue(value: any, uom: number) {
if (uom === DeviceValueUOM.DEGREES) {
return new Intl.NumberFormat(undefined, {
minimumFractionDigits: 1
}).format(value);
}
return value;
}
class ValueForm extends React.Component<ValueFormProps> {
formRef: RefObject<any> = React.createRef();
@@ -69,7 +79,7 @@ class ValueForm extends React.Component<ValueFormProps> {
{!devicevalue.l && (
<OutlinedInput
id="value"
value={devicevalue.v}
value={formatValue(devicevalue.v, devicevalue.u)}
autoFocus
fullWidth
onChange={handleValueChange('v')}