reaflow icon indicating copy to clipboard operation
reaflow copied to clipboard

Feature request - Initialize Undo/Redo with existing history

Open Vadorequest opened this issue 3 years ago • 3 comments

It'd be great to be able to load an external history upon initializing the undo/redo feature.

It's already supported by the Undoo lib, through the import(history) API, so it should be trivial to implement. https://github.com/fabioricali/undoo#undooimporthistory--undoo

I suppose changing the UndoProps by adding a initialHistory prop would do the trick:

export interface UndoProps {
  nodes: NodeData[];
  edges: EdgeData[];
  maxHistory?: number;
  disabled?: boolean;
  onUndoRedo: (state: UndoRedoEvent) => void;
  initialHistory?: { nodes: NodeData[]; edges: EdgeData[]};
}

And then, instead of https://github.com/reaviz/reaflow/blob/147d64c4e8a5013cd12c98a6931e4d9e86519c7e/src/helpers/useUndo.ts#L42-L46:

  const undoo = new Undoo({
      maxLength: maxHistory
    });

  const manager = useRef<Undoo>(undoo);
  manager.import({nodes, edges});

I guess that'd be it?

Vadorequest avatar Feb 09 '21 06:02 Vadorequest

Ya - totally happy to accept that change.

amcdnl avatar Feb 09 '21 12:02 amcdnl

I'll make a PR for this then. Thanks for confirming!

Vadorequest avatar Feb 09 '21 13:02 Vadorequest

Started in https://github.com/reaviz/reaflow/pull/69

Vadorequest avatar Feb 24 '21 18:02 Vadorequest