netcreateorg / netcreate-itest

Developing the 2.0 version of NetCreate
https://github.com/netcreateorg/netcreate-2018
Other
0 stars 0 forks source link

Template editor wipes out hand-added fields sometimes #115

Open jdanish opened 9 months ago

jdanish commented 9 months ago

To reproduce:

  1. Generate a network and leave the "Comments" field visible
  2. Stop net.create.
  3. Open the template file externally (e.g., in studio code)
  4. Add a select type property such as ...
[nodeDefs.connotation]
type = "select"
displayLabel = "Connotation"
exportLabel = "Connotation"
help = "Is this positive, negative, or neutral?"
includeInGraphTooltip = true
hidden = false

  [[nodeDefs.connotation.options]]
  color = "#eeeeee"
  label = ""
  replacement = ""
  delete = false

  [[nodeDefs.connotation.options]]
  color = "#eeeeee"
  label = "Positive"
  replacement = ""
  delete = false

  [[nodeDefs.connotation.options]]
  color = "#eeeeee"
  label = "Negative"
  replacement = ""
  delete = false
  1. Run net-create with the revised template.
  2. Nodes have the new connotation attribute as well as comments and all works as expected.
  3. Open template editor and add a node type.
  4. Network looks fine, and new node type is added to the template file on the hard drive.
  5. Change the visibility on the comment field using the template editor.
  6. Screen reloads, and connotations is also gone.
  7. Check the saved template file, and it looks OK but the connotation attribute has been deleted.

We realize that short-term we need to add / edit these node attributes by hand because it is not worth updating the template editor since the plan is, I believe, to replace it. If it is easy to have this not clobber the hand-added fields, that'd be ideal. If that's a major task, we'll just warn the team not to use the template editor on anything that was hand edited.

benloh commented 9 months ago

The core problem here is that the JSON Editor requires the definition of a schema for the template format in order for the JSON Editor to know how to support field editing. e.g. the schema needs to specify that the label field is a string field, show some help for what a label field (e.g. 'Display name of the node'), set a default value, how the field should be exported, etc.

This works well when we're using the standard fields as defined in our template schema. But it breaks when we introduce custom fields. This is true for fancy "select" fields like connotation, but also for simple string fields like location. The basic problem is that we need to define all of that schema meta data for any custom fields. See template-schema.js to get a sense of what is in there.

Right now template editor UI only knows how to deal with the built-in schema of the standard fields. The JSON Editor does not know how to read let alone render custom fields.

So while we can support custom fields by editing the *.template.toml files directly, the JSON Editor is essentially broken for custom fields.

Unfortunately there's no easy way around this. e.g. we can't just allow Node Type edits without breaking the whole template.

We probably want to consider adding a warning, or disabling template editing altogether for any templates that have been modified.

jdanish commented 9 months ago

Thanks for looking into it. To preserve budget let's leave it as-is for now and focus on other things. Thanks!