Skip to content

Commit

Permalink
added description field, fixed read and write fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Codebmk committed Sep 13, 2024
1 parent 53f8b66 commit 33854e7
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ const DeviceView = () => {
});

useEffect(() => {
if (isEmpty(devices)) {
dispatch(getOrgDevices(activeNetwork.net_name));
dispatch(updateDeviceDetails(deviceData));
}
dispatch(getOrgDevices(activeNetwork.net_name));
dispatch(updateDeviceDetails(deviceData));
}, []);

return (
Expand All @@ -46,7 +44,8 @@ const DeviceView = () => {
alignItems: 'center',
justifyContent: 'center',
flexWrap: 'wrap'
}}>
}}
>
<DeviceToolBar deviceName={deviceData.name} />
<DeviceToolBarContainer>
<Switch>
Expand Down
84 changes: 59 additions & 25 deletions netmanager/src/views/components/DataDisplay/Devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,15 @@ const CreateDevice = ({ open, setOpen }) => {
const newDeviceInitState = {
long_name: '',
category: CATEGORIES[0].value,
network: selectedNetwork
network: selectedNetwork,
description: ''
};

const initialErrors = {
long_name: '',
category: '',
network: ''
network: '',
description: ''
};

const [newDevice, setNewDevice] = useState(newDeviceInitState);
Expand Down Expand Up @@ -321,9 +323,10 @@ const CreateDevice = ({ open, setOpen }) => {
setNewDevice({
long_name: '',
category: CATEGORIES[0].value,
network: selectedNetwork
network: selectedNetwork,
description: ''
});
setErrors({ long_name: '', category: '', network: '' });
setErrors({ long_name: '', category: '', network: '', description: '' });
};

const isFormValid = () => {
Expand Down Expand Up @@ -448,6 +451,19 @@ const CreateDevice = ({ open, setOpen }) => {
helperText={errors.network}
disabled
/>

<TextField
margin="dense"
label="Description (Optional)"
variant="outlined"
value={newDevice.description}
onChange={handleDeviceDataChange('description')}
fullWidth
multiline
rows={3}
error={!!errors.description}
helperText={errors.description}
/>
</form>
</DialogContent>

Expand Down Expand Up @@ -482,17 +498,19 @@ const SoftCreateDevice = ({ open, setOpen, network }) => {
category: CATEGORIES[0].value,
network: selectedNetwork,
device_number: '',
write_key: '',
read_key: ''
writeKey: '',
readKey: '',
description: ''
};

const initialErrors = {
long_name: '',
category: '',
network: '',
device_number: '',
write_key: '',
read_key: ''
writeKey: '',
readKey: '',
description: ''
};

const [newDevice, setNewDevice] = useState(newDeviceInitState);
Expand Down Expand Up @@ -534,16 +552,18 @@ const SoftCreateDevice = ({ open, setOpen, network }) => {
category: CATEGORIES[0].value,
network: selectedNetwork,
device_number: '',
write_key: '',
read_key: ''
writeKey: '',
readKey: '',
description: ''
});
setErrors({
long_name: '',
category: '',
network: '',
device_number: '',
write_key: '',
read_key: ''
writeKey: '',
readKey: '',
description: ''
});
};

Expand All @@ -565,20 +585,21 @@ const SoftCreateDevice = ({ open, setOpen, network }) => {
severity: 'error'
})
);
dispatch(loadStatus(false));
return;
} else {
// Create a copy of newDevice
const deviceDataToSend = { ...newDevice };

// Remove device_number, write_key, and read_key if they're empty
// Remove device_number, writeKey, and readKey if they're empty
if (!deviceDataToSend.device_number) {
delete deviceDataToSend.device_number;
}
if (!deviceDataToSend.write_key) {
delete deviceDataToSend.write_key;
if (!deviceDataToSend.writeKey) {
delete deviceDataToSend.writeKey;
}
if (!deviceDataToSend.read_key) {
delete deviceDataToSend.read_key;
if (!deviceDataToSend.readKey) {
delete deviceDataToSend.readKey;
}

const resData = await softCreateDeviceApi(deviceDataToSend, {
Expand Down Expand Up @@ -678,6 +699,19 @@ const SoftCreateDevice = ({ open, setOpen, network }) => {
disabled
></TextField>

<TextField
margin="dense"
label="Description (Optional)"
variant="outlined"
value={newDevice.description}
onChange={handleDeviceDataChange('description')}
fullWidth
multiline
rows={3}
error={!!errors.description}
helperText={errors.description}
/>

<Button onClick={toggleMoreOptions} color="primary" style={{ marginTop: '10px' }}>
{showMoreOptions ? 'Show less options' : 'Show more options'}
</Button>
Expand All @@ -699,22 +733,22 @@ const SoftCreateDevice = ({ open, setOpen, network }) => {
margin="dense"
label="Write Key (Optional)"
variant="outlined"
value={newDevice.write_key}
onChange={handleDeviceDataChange('write_key')}
value={newDevice.writeKey}
onChange={handleDeviceDataChange('writeKey')}
fullWidth
error={!!errors.write_key}
helperText={errors.write_key}
error={!!errors.writeKey}
helperText={errors.writeKey}
/>

<TextField
margin="dense"
label="Read Key (Optional)"
variant="outlined"
value={newDevice.read_key}
onChange={handleDeviceDataChange('read_key')}
value={newDevice.readKey}
onChange={handleDeviceDataChange('readKey')}
fullWidth
error={!!errors.read_key}
helperText={errors.read_key}
error={!!errors.readKey}
helperText={errors.readKey}
/>
</>
)}
Expand Down

0 comments on commit 33854e7

Please sign in to comment.