diff --git a/interface/src/project/SettingsEntities.tsx b/interface/src/project/SettingsEntities.tsx index d1d2d6504..aafa602ee 100644 --- a/interface/src/project/SettingsEntities.tsx +++ b/interface/src/project/SettingsEntities.tsx @@ -187,30 +187,28 @@ const SettingsEntities: FC = () => { setSelectedEntityItem({ id: Math.floor(Math.random() * (Math.floor(200) - 100) + 100), name: '', - device_id: 11, - type_id: 0, + device_id: '', + type_id: '', offset: 0, factor: 1, uom: 0, - value_type: 2, + value_type: 0, writeable: false, deleted: false }); setDialogOpen(true); }; - function formatValue(value: any, uom: number) { - if (value === undefined) { - return ''; - } - return new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]); + function formatValue(value: any, uom: any) { + return value === undefined || uom === undefined + ? '' + : new Intl.NumberFormat().format(value) + (uom === 0 ? '' : ' ' + DeviceValueUOM_s[uom]); } function showHex(value: number, digit: number) { - if (digit === 4) { - return '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4); - } - return '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2); + return digit === 4 + ? '0x' + ('000' + value.toString(16).toUpperCase()).slice(-4) + : '0x' + ('0' + value.toString(16).toUpperCase()).slice(-2); } const renderEntity = () => { diff --git a/interface/src/project/SettingsEntitiesDialog.tsx b/interface/src/project/SettingsEntitiesDialog.tsx index f25d6ef8a..f2ef22e21 100644 --- a/interface/src/project/SettingsEntitiesDialog.tsx +++ b/interface/src/project/SettingsEntitiesDialog.tsx @@ -59,8 +59,8 @@ const SettingsEntitiesDialog = ({ // convert to hex strings straight away setEditItem({ ...selectedEntityItem, - device_id: ('0' + selectedEntityItem.device_id.toString(16).toUpperCase()).slice(-2), - type_id: ('000' + selectedEntityItem.type_id.toString(16).toUpperCase()).slice(-4) + device_id: selectedEntityItem.device_id.toString(16).toUpperCase().slice(-2), + type_id: selectedEntityItem.type_id.toString(16).toUpperCase().slice(-4) }); } }, [open, selectedEntityItem]); @@ -123,8 +123,9 @@ const SettingsEntitiesDialog = ({ name="device_id" label={LL.ID_OF(LL.DEVICE())} margin="normal" + type="string" fullWidth - value={editItem.device_id} + value={editItem.device_id as string} onChange={updateFormValue} inputProps={{ style: { textTransform: 'uppercase' } }} InputProps={{ startAdornment: 0x }} @@ -157,7 +158,7 @@ const SettingsEntitiesDialog = ({ } ], device_id: [ - { required: true, message: 'Device ID is required' }, { validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) { if (isNaN(parseInt(value, 16))) { - callback('Must be a hex number'); + callback('Is required and must be in hex format'); } callback(); } } ], type_id: [ - { required: true, message: 'Type ID is required' }, { validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) { if (isNaN(parseInt(value, 16))) { - callback('Must be a hex number'); + callback('Is required and must be in hex format'); } callback(); }