undoPointSelector
Home > @gooddata/sdk-ui-dashboard > UndoLayoutChangesPayload > undoPointSelector
UndoLayoutChangesPayload.undoPointSelector property
This API is provided as a beta preview for developers and may change based on feedback that we receive. Do not use this API in a production environment.
Specify a function that will be used to select a command up to which the undo should be done.
Signature:
readonly undoPointSelector?: UndoPointSelector;
Remarks
If not provided then the default selector will be used and will undo the very last command.
The undo point selector is essential if you are implementing complex user-facing features that are achieved using multiple commands. For instance drag-and-drop. On drag start, an item is removed - that is one command, and then user drops the item at the new location - that is another command. The commands are dispatched by your code separately, yet if user is able to do undo drag-and-drop operation, you need to get layout to a point before
If you want to trigger a proper undo in this case, then you need to undo both commands. Building on the example above, you can proceed as follows:
- Your drag-and-drop feature should use correlationId convention to tie commands to user-facing feature. - Upon interaction start, your feature computes a correlationId
prefix
= "dnd-" - The first command to remove the dragged item from layout will have correlationId = ${prefix}-drag
- The second command to add the dropped item to a new place on layout will have correlationId =${prefix}-drop
- When the user clicks 'Undo', you dispatch the UndoLayoutChanges with a greedy selector. This will check whether the last command is a 'drop' in the dnd interaction. If so, look at previous command, check if it matches the correlationId and if so undo up to and including that command.