Hi folks,
Based on another discussion, I'm trying to rework the Node-RED JSON editor: only allow user input that is defined in the JSON schema. The purpose is to avoid that node developers have to implement large complex user interfaces, and instead only have to specify a JSON schema.
For example I need to build an Onvif device manager, to make my Onvif nodes more user friendly. Instead of building/maintining such a manager in Node-RED (which is rather undoable in my free time), I want use Nick's JSON editor and change it so a JSON schema can be applied. Indeed the Onvif consortium already offers a onvif.xsd file (which I can convert to a JSON schema file), that contains all the logic about Onvif camera configuration.
In this discussion I would like to get feedback about the issues I'm dealing with. Otherwise I'm making assumptions, and end up with a solution that won't be approved anyway.
Question 1 - Where/when specify the item name
My example schema:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/product.schema.json",
"title": "Product",
"description": "A product from my web shop",
"type": "object",
"properties": {
"productId": {
"description": "The unique identifier for a product",
"type": "integer"
},
"productName": {
"description": "Name of the product",
"type": "string"
},
"price": {
"description": "The price of the product",
"type": "number",
"exclusiveMinimum": 0
},
"required": [ "productId", "productName" ]
}
This schema tells the editor that a product needs to have 3 items: "productId", "productName", and "price".
When you add a new item in the editor, I currently select automatically the first item from the schema (that hasn't been used yet). And when you click on an item name, you get a popup with all available items, to change the item afterwards:
I did it like that because that is close to how it works without a JSON schema. However it isn't user friendly:
-
There might be a lot of possible items in the JSON schema, so it is a bit ridiculous that I pick one (which you need to change afterwards).
-
I would like to avoid that you can change the item name (via the dropdown box) afterwards. Indeed then I also have to remove all the children, because they won't belong to the new item name anymore. I.e. the new item whill have other constraints in the schema. In that case you should remove the item and add a new one.
So the question is how I know which item you want to add, when you click the "Add item" button:
-
Should Iwork with sub-menu items (after the "Add item" menu), but don't know if Node-RED supports that. And not sure if it is user friendly.
-
Should I show a popup with a dropdown, where you need to select an item before you can add it.
-
Should I leave the item name empty (or an "Unknown" label), and that you have to click on it to show a dropdown box:
*My personal choice is the last one, since that matches closest the current behaviour of the JSON editor (without the dropdown). Only disadvantage is that I cannot force the user to specify the item immediately. Although perhaps that is not a problem...
BTW in all 3 cases you can make a selection only once. As soon as you have specified an item, all (required) subitems should be added automatically and become unremovable.
Have a nice sunday,
Bart