Skip to content
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

feat(editor): Add undo/redo support for canvas actions #4787

Merged
merged 75 commits into from
Dec 9, 2022

Conversation

MiloradFilipovic
Copy link
Contributor

@MiloradFilipovic MiloradFilipovic commented Dec 1, 2022

Closes ADO-69

See comments this Linear ticket for more info about testing.

* master:
  fix: Update padding for resource filters dropdown (#4751)
  fix: Update workflow save button type and design and share button type (#4752)
  fix: Update owner badge padding (no-changelog) (#4749)
  fix: Remove background for resource ownership selector (#4748)
  fix: Update size of select components in filters dropdown (#4747)
* master:
  test: Skip e2e check of rendered nodes in node creator (#4761)
  feat: Add dynamic translations. Change how sharing unavailable is handled (no-changelog) (#4758)
  ci: Move full E2E tests into their own scheduled workflow (#4757)
  feat(Todoist Node): Update to use latest api version (#4650)
  fix(Google Sheets  Node): Fix exception if no matching rows are found
* master:
  fix: Lazy load nodes for credentials testing (#4760)
  fix(core): Fix `$items().length` in Execute Once mode (#4755)
  feat(Google Calendar Node): Use resource locator component for calendar parameters (#4410)
  fix: Change the currentUserHasAccess flag behavior (no-changelog) (#4763)
* master:
  fix(core): Ensure executions list is properly filtered for all users (#4765)
  ci: Fix linting issues on master (no-changelog) (#4768)
  fix(Microsoft Outlook Node): Fix binary attachment upload (#4766)
* master:
  fix(editor): JSON view values can be mapped like keys (#4702)
  test: E2E NDV (#4712)
  fix: Issue building image with dependency name ending in .vue (no-changelog) (#4773)
  fix: Register community nodes as known nodes (no-changelog) (#4775)
  refactor: Codex updates for Item Lists, Markdown and Date & Time (#4772)
  refactor(editor): Patch ElementUI tooltip memory leak (#4769)
  refactor: Apply lint rule `cred-class-field-display-name-miscased` (#4762)
…x. Adding debounce to undo/redo keyboard calls
@MiloradFilipovic MiloradFilipovic self-assigned this Dec 1, 2022
@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system labels Dec 1, 2022
@MiloradFilipovic MiloradFilipovic changed the title WIP: Feature/undo redo feat (editor): Add undo/redo support for canvas actions Dec 1, 2022
@MiloradFilipovic MiloradFilipovic marked this pull request as draft December 1, 2022 20:39
if (this.isNDVOpen && !event.shiftKey) {
const activeNode = this.ndvStore.activeNode;
if (activeNode) {
this.$telemetry.track(`User hit undo in NDV`, { node_type: activeNode.type });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird we are not tracking the event itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked with Nik about it, looks like we are only interested in the fact that users attempted undo here.

packages/editor-ui/src/mixins/nodeBase.ts Outdated Show resolved Hide resolved
}),
getters: {
currentBulkContainsConnectionCommand() {
return (command: AddConnectionCommand): boolean => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what the exact problem here you are solving is.. but maybe this could be more generic.. if each class had a compareTo method like in Java or a toString representation, you can use that to check if an instance of that event exists in history

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now thinking about it, this may no longer be necessary. It has happened in some weird scenarios when going back and forward in history that the same connection command would end up in undo due to jsplump connections listeners so this prevents it. This may have stopped now that redo is cleared on each new user action which simplifies navigation options. Will have to check, but the generic approach is the way to go here for sure.

Comment on lines +3368 to +3369
this.suspendRecordingDetachedConnections = true;
this.__addConnection(connection, true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you tracked history changes only in __addConnection instead of connection bind event? then you could pass trackHistory: false and not track events.. and not need this flag to suspend recoding events.. same question applies to other events..
not a huge fan of this flag because it seems flaky and easy thing to mess up...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like it ether, but found out not all connections are added and removed ind __addConnection and removeConnection methods, some are added and removed in those events. For example, if you drag a connection on an empty canvas space, it is removed in the connectionDetached event (among other situations, hence the flag), also when reconnecting nodes, some connections are pushed straight to store in conncection event. This made implementation rely on those flags which is a bit of chasing my own tail situation but I couldn't figure out better way to cover all cases.

* master:
  fix: Use license-sdk v1.6.1 (#4872)
  feat(editor): Node creator actions (#4696)
  test(editor): Set e2e test retries (#4870)
  fix: Increase workflow reactivation max timeout to 1 day (#4869)
  fix: Stop returning `UNKNOWN ERROR` in the response if an actual error message is available (#4859)
  fix: Issue listing executions with Postgres (#4856)
  test(editor): Fix flaky e2e tests (#4779)
  fix: Use the same entrypoint for custom docker images as for the other images (no-changelog) (#4849)
  refactor: Deprecate `alwaysOpenEditWindow` for `string` (#4839)
  fix: Upgrade sse-channel to mitigate CVE-2019-10744 (#4835)

# Conflicts:
#	packages/editor-ui/src/App.vue
#	packages/editor-ui/src/views/NodeView.vue
* master:
  fix: Update duplicate action (#4858)
@@ -2620,7 +2620,7 @@ export default mixins(
return;
}

if (trackHistory) {
if (trackHistory && !partOfBulkDelete) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need this? should not it just be bundled as part of current bulk action?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, bulk action inside this function is used when deleting a single connected node. In that case, it will contain removeNode and removeConnection commands. When deleting multiple nodes, this function is called in a loop and recording is started outside of this loop, so starting and stopping recording in each iteration will break the history recording.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha

@@ -2620,7 +2620,7 @@ export default mixins(
return;
}

if (trackHistory && !partOfBulkDelete) {
if (trackHistory && !trackBulk) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick - now it's confusing.. I would change the default to true as trackBulk should track bulk actions..

Suggested change
if (trackHistory && !trackBulk) {
if (trackHistory && trackBulk) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, makes sense.

@MiloradFilipovic MiloradFilipovic merged commit b2aba48 into master Dec 9, 2022
@MiloradFilipovic MiloradFilipovic deleted the feature/undo-redo branch December 9, 2022 14:07
@n8n-assistant n8n-assistant bot added the Upcoming Release Will be part of the upcoming release label Dec 9, 2022
MiloradFilipovic added a commit that referenced this pull request Dec 12, 2022
* master:
  fix(editor): Avoid adding manual trigger node when webhook node is added (#4887)
  ci: Add libc6-compat to nightly docker builds (no-changelog) (#4885)
  fix(Move Binary Data Node): Stringify objects before encoding them in MoveBinaryData (#4882)
  ci: Upgrade pnpm and turborepo (no-changelog) (#4878)
  fix(editor): Fix for broken tab navigation (#4881)
  feat(editor): Add undo/redo support for canvas actions (#4787)
  fix(Split In Batches Node): Fix issue with pairedItem (#4873)
  fix: Update duplicate action (#4858)

# Conflicts:
#	packages/editor-ui/src/Interface.ts
#	packages/editor-ui/src/mixins/history.ts
#	packages/editor-ui/src/views/NodeView.vue
@janober
Copy link
Member

janober commented Dec 12, 2022

Got released with n8n@0.207.0

@janober janober removed the Upcoming Release Will be part of the upcoming release label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team ui Enhancement in /editor-ui or /design-system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants