-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: undo/redo for app builder #1446
Conversation
Please fix the merge conflicts. |
@Navaneeth-pk fixed merge conflict 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, now I think the crash happens whenever the inspector panel is open.
|
Thanks @sherfin94 I was able to reproduce this bug, its related to inspector panel Screen.Recording.2021-12-08.at.4.53.41.PM.mov
It's related to inspector panel click event when it opens, I am looking into it, will post the fix soon |
@sherfin94 added the fix |
Apologies for late question, do we also have to add some buttons as well for undo/redo? |
server/migrations/1638255797809-SetLoadingStateToFalseForExistingTables.ts
Show resolved
Hide resolved
// 2. Whenever you perform an undo – you can always redo and keep doing undo as long as we have a patch for it. | ||
// 3. Whenever you redo – you can always undo and keep doing redo as long as we have a patch for it. | ||
initComponentVersioning = () => { | ||
this.currentVersion = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: will this be confusing later b/w app's current version and immer patch's current version? ́😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually app version can be version 1, but the immer patch's current version can be anywhere between a range of 1-100,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant we store currentVersionId
for apps at db, was speaking in terms of that.
Hey @gondar00, looks like the crash still happens in certain scenarios:
|
This I've added a check it seems to work fine now, thanks ^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a great PR @gondar00 👏🏼 👏🏼
One small thing, unrelated to the main purpose of this PR that we'll have to fix is, the new type of toasts doesn't show different colors when different types of alert is selected (success, failure etc).
Great work @gondar00 🙌🏽 |
* feat: add restore shortcut when component is deleted * change toast messages to hot toast from toastify * change toast messages to hot toast from toastify * change toast messages to hot toast from toastify * on key press match clear the pressed keys * add react hotkeys hook and delete use-shortcuts custom hook * change toast messages to hot toast from toastify * add immer lib * applyPatches from immer + add undo redo on appdefination changes * remove notification on undo * add can-undo + can-redo checks * add missing can-redo to handlePatchAdd * add component versioning on componentDefinitionChanged * set default value of loading state to interpolated boolean false for table * set canUndo on initial load to false * fix last element not getting removed on undo * Remove console log * add migration to change loadingState for existing tables * set loadingstate value based on the previous value * fix: app crash on inspector opening * add check for selectedComponentId inside components def * update template definitions for loadingState * fix alert for success, error, info for button notifications
This PR adds a shortcut i.e
⌘Z
for undo-ing a change made to a componentThis PR adds a shortcut i.e
⌘+shift+Z
for redo-ing a change made to a componentDefine change made to a component?
Change can be user activities such as resizing, deleting, moving the element on the canvas, add-edit component to canvas.
Screen.Recording.2021-11-23.at.5.05.44.PM.mov
Implementing Undo-Redo Functionality in Editor.jsx using Immer
What is Immer patches?
To know more about immer please visit their website.
Immer brings in a feature called Patches. That allows us to implement many cool features – one of them being Undo-Redo.
Immer records all the changes that are performed on the draft object and generates an array of JSON objects indicating what has changed. These arrays are called Patches. Immer also produces inverse patches, which are patches that need to be applied if you want to go back to the previous state.
Implementation
appDefinition is the place where all the components including their layout changes are stored. Whenever a change is made to appDefinition:
appDefinitionChanged
is the callback function invoked every-time any changes toappDefinition
are made.In this callback function have added: immer function i.e
Next,
handleAddPatch
function handles 5 things:canUndo
&canRedo
propertiesdelete currentVersion + 1
currentVersionChanges
are 100 to preserve browser performance due to the deeply nested nature ofappDefinition
thecurrentVersionChanges
can be a very large object.Things to keep in mind