sciapp / sampledb

Sample and Measurement Metadata Database
https://scientific-it-systems.iffgit.fz-juelich.de/SampleDB/
MIT License
21 stars 11 forks source link

Added action type 'Template' #28

Closed rnoffke closed 2 years ago

rnoffke commented 3 years ago

Introducing 'Templates' as action type

'Template' is a new special action type like sample, measurement or simulation (id: -96). It does not allow the creation of new objects, which is realized via a new database attribute disable_create_objects. The main purpose of this action type is to encapsulate frequently reused JSON structures as templates.

Possible applications could be a set of standardized generic metadata attributes that one uses time and time again in different actions or more complex structures you also want to use multiple times in different contexts, like a set of tables that represent a chemical reaction for example. Those sets of attributes can now be templated and then included in real actions like samples.

A simple dummy example should help to clarify the implementation and usage.

In our example we have created two template actions:

  1. Chosen Educts:
{
  "title": "Educts",
  "type": "object",
  "properties": {
    "name": {
      "title": "Name",
      "type": "text"
    },
    "educt_steps": {
      "title": "Educt - Step",
      "type": "array",
      "style": "table",
      "minItems": 1,
      "maxItems": 3,
      "items": {
        "type": "object",
        "title": "Step",
        "properties": {
          "educt": {
            "title": "Educt",
            "type": "text",
            "choices": [
              "A",
              "B",
              "C"
            ]
          },
          "step": {
            "title": "Step",
            "type": "text",
            "choices": [
              "1",
              "2",
              "3"
            ]
          }
        }
      }
    }
  },
  "required": [
    "name"
  ]
}
  1. Reaction X Constraints:
{
  "title": "",
  "type": "object",
  "properties": {
    "name": {
      "title": "Name",
      "type": "text"
    },
    "refSample": {
      "title": "Referenceable Sample",
      "type": "sample"
    },
    "respUser": {
      "title": "Responsible User",
      "type": "user"
    },
    "collaborators": {
      "title": "Collaborators",
      "type": "array",
      "style": "list",
      "items": {
        "title": "Collaborators",
        "type": "user"
      }
    },
    "startDate": {
      "title": "Start Date",
      "type": "datetime"
    }
  },
  "required": [
    "name"
  ],
  "propertyOrder": [
    "name",
    "refSample",
    "collaborators",
    "startDate"
  ]
}

You can now include these templates in another action by either using the visual editor:

include_template

Or you can also just insert a empty JSON Dummy that would look like this:

"educts": {
      "title": "Educts",
      "type": "object",
      "template": "34"
    }

The newly created sample action then won't actually only contain this dummy JSON Block, but instead the entire "Chosen Educts" object structure injected in its place. This means the newly created Action, once it is stored in the database, is independent from all used templates. Subsequently all created Objects are also independent, so that the process of updating objects to updated action schemas is completely unaffected.

The only remaining artefact is the otherwise meaningless attribute "template": 34 for the object. This remains in place, so that we can inject the dummy again solely in the context of the action editor (both visual or JSON). That means that once you try to edit this action again, you can still use the visual editor no matter how complex the structure behind the stored templates might be. Even if you use the JSON editor the action remains clear and a lot less cluttered. Once you save your changes to the surrounding structure the template data gets reinjected again.

This has the additional upside to allow small changes to an action via the visual editor for less tech-savvy users.

FlorianRhiem commented 3 years ago

Hey @rnoffke, thank you for the pull request.

This definitely seems useful, but I don't really see why these templates for parts of an action schema should be actions themselves. Actions model processes that generate research data in the form of objects. I can see why an administrator might want to temporarily prevent users from using actions of a given type, so disable_create_objects could be useful, but if an action type is generally not meant for being used and would not make sense if it was used, then why make it an action type in the first place? Wouldn't it be much cleaner to have these action schema templates as their own entities?

rnoffke commented 3 years ago

Hey @FlorianRhiem and @maltedeckers,

thanks for the feedback.

We added the 'Templates' as an action_type to reuse the entrire existing structure of handling actions. In the background templates just are actions and instead of them it's possible to include any action (using the JSON-editor) also. The reason why only template-actions are selectable in the visual editor is to avoid confusing the user and to create a logical seperation. In that sense it would probably be better to further clarify the unique role of templates to the user by creating a completely seperate menubar entry, so that it won't be listed as an action_type explicitly.

FlorianRhiem commented 3 years ago

We added the 'Templates' as an action_type to reuse the entrire existing structure of handling actions. In the background templates just are actions and instead of them it's possible to include any action (using the JSON-editor) also. The reason why only template-actions are selectable in the visual editor is to avoid confusing the user and to create a logical seperation. In that sense it would probably be better to further clarify the unique role of templates to the user by creating a completely seperate menubar entry, so that it won't be listed as an action_type explicitly.

Okay, I can see why it might be useful to include other actions, and if that is possible, then templates being actions is reasonable. Still, in my opinion, there should be a clear distinction in terms of how they appear to the users, e.g. they shouldn't be included in the general actions list, like you already suggested. Perhaps when Show actions of this type in the navbar is checked for this type, Action Templates is shown in the Other section of the navbar?

rnoffke commented 2 years ago

Hey @FlorianRhiem and @maltedeckers,

we changed the 'template feature'.

Now you'll be able to add a 'template-tag' to every action type. By doing so these actions will be listed to include them into other actions as template.

To hide it in the navbar we removed the 'show_in_navbar' tag by default.

Moreover we will not list actions that are not marked as 'show_in_navbar' in the 'actions-list' any more. They'll be only listed if this action type is chosen specifically. We think this is more intuitive if actions that are not listed at the 'actions' dropdown are listed when you click this dropdown.

FlorianRhiem commented 2 years ago

This looks good, but I got a few more suggestions:

Also, please check for code style violations using python3 -m pycodestyle --ignore=E402,E501,W504 sampledb and python3 -m pyflakes sampledb and adjust the pytest tests (currently at least tests/api/server/test_action_types.py::test_get_action_types fails).

rnoffke commented 2 years ago

Hey @FlorianRhiem and @maltedeckers,

we changed the code concerning your annotations.

Moreover some buggs were removed (e.g. keys that are only supported in not root objects will not be added to actions including Schema Templates containing these keys) and the code style has been improved.

We will add the documentation if the current version does not point out any other issues.

maltedeckers commented 2 years ago

Hi @rnoffke,

I think showing template actions in the actions list (/actions/) in a separated section might be more obvious than having to access it by the action types list. That way we could hide the action types list from "normal" users again. Maybe accessing action types not shown in the navbar could still be useful, but then a way to hide action types from users completely might be needed (@FlorianRhiem ?).

maltedeckers commented 2 years ago

grafik

I get this schema validation error in the attempt to use a simple template containing only a simple text value. Am I using the template feature wrong or is this a bug?

The template: grafik

maltedeckers commented 2 years ago

At least tests/logic/test_action_type_translations.py::test_delete_action_translation seems to fail.

Also tests covering this new feature would be great.

FlorianRhiem commented 2 years ago

I agree that showing action types to users with them unable to do anything isn't great. The basic concepts of SampleDB already need some time to get used to, we shouldn't make it any more difficult for new users. Personally, I think a Schema Templates section in the More category of the navbar might be the cleanest. If they are listed among the actions in the action list, then using them as an action should make sense. If it doesn't, then listing them there will lead to confusion.

FlorianRhiem commented 2 years ago

We've merged the changes, along with a few more improvements for handling nested templates, etc. Could you post on the mailing list to explain this new feature and the ideas behind it?