Ctrl-z undo question

#1

Hi,

How does one handle a node, when the user hits ctrl-z? Is there a function with something like "oneditundo"? My current problem is that my node gets in a bad state, if it is configured, and then undo-ed afterwards with ctrl-z.

0 Likes

#2

Hi,

no, there is no undo event like that. Can you expand a bit on how that causes your node to get into a bad state? The undo of an edit event returns a node to its exact configuration prior to the edit.

0 Likes

#3

My node gets information from a GET command via the "oneditprepare" function.
Hereafter one can configure the node. When the "save" button is pushed, the node sends a POST command with the new settings. Now if I hit ctrl-z the HTTP req/res does not get updated (it does not know that there was an undo action).

0 Likes

#4

Hi Simon (@Simo219h),

Interesting question, but I think you have to redesign it somehow.

This is how Node-RED works:

image

  1. You have some node in your server-side flow (which contains a variable A with value 'X').
  2. This node is transferred to your flow editor.
  3. When you open the node's config screen, the oneditprepare is executed. That is the place to fill your config screen, based on the node variables. For example let's say the checkbox should be checked when the value of variable A is 'X'.
  4. The config screen shows the checkbox, and you can unselect it.
  5. When you leave the config screen via the 'Done' button, the oneditsave is called. That allows you to store values from the config screen in the node. Since the checkbox is unchecked now, we will store value 'Y' into variable A. Remark: when you press the 'Cancel' button, the oneditcancel is executed.
  6. When 'everything' (i.e. the entire configuration of all nodes is your flow) is correct, you press the 'Deploy' button. Then the new value 'Y' is stored in variable A of your node on the server.
  7. And when the user does CTRL-Z in between, the old node status is restored. Which means variable A gets again its original value 'X' (instead of Y).

So the oneditsave is not really saving like you save a document in another application. Your are still dealing with temporary data, until the 'Deploy' is triggered. I 'think' it is not good practice to use the the oneditsave to do things on your server, which need to be reverted in case you do CTRLZ. Normally you should do such things as soon as your new value 'Y' arrives on the server. When you executed CTRL-Z afterwards and deploy the original value 'X' again to the server, that is the point where your server side code should revert the things you have done earlier ...

BTW don't think a new feature like oneditundo would make sense, because at that point you don't have your config screen open anymore. And all those functions (oneditprepare, oneditsave, ...) are part of the config screen...

1 Like