ui: Make device metric name optional.

If enabled, metrics will be automatically detected and created based on
the decoded payload. The key will be set, but the name is left blank for
the user to configure. This can be confusing as it leads to validation
errors in the device-profile form if the name is not filled in.
The UI does show that one of the fields failed to validate, but even
with such notification, it is not clear that users have to check one
of the form tabs which they didn't edit on save.

This makes the name optional and uses the key as fallback such that
saving the form no longer fails in case the name is still blank.

Closes #313.
This commit is contained in:
Orne Brocaar 2023-11-10 16:49:48 +00:00
parent b0ed12a1f5
commit 464937169b
2 changed files with 5 additions and 2 deletions

View File

@ -714,7 +714,11 @@ impl DeviceService for Device {
out.metrics.insert(
k.to_string(),
common::Metric {
name: v.name.to_string(),
name: if v.name.is_empty() {
k.to_string()
} else {
v.name.to_string()
},
timestamps: m
.iter()
.map(|row| {

View File

@ -1125,7 +1125,6 @@ function DeviceProfileForm(props: IProps) {
{...restField}
name={[name, 1, "name"]}
fieldKey={[name, 1, "name"]}
rules={[{ required: true, message: "Please enter a name!" }]}
>
<Input placeholder="Measurement name" disabled={props.disabled} />
</Form.Item>