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

[IMP] history: add the possibility to repeat commands at redo #2126

Closed
wants to merge 3 commits into from

Conversation

hokolomopo
Copy link
Contributor

Description:

Now if we do a redo and the redo stack is empty, we will try the redo
the last played command if possible. The list of repeatable commands
is in defined in the repeat_commands_registry.ts file.

Repeated commands are transformed to match the current selection/sheet.
To be able to repeat local commands, the "root" command of a revision
was added to the history.

Odoo task ID : 2508693

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_lt("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Mar 1, 2023

Copy link
Contributor

@anhe-odoo anhe-odoo left a comment

Choose a reason for hiding this comment

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

Good work. Some small questions but else look good to me :)

tests/plugins/repeat_commands.test.ts Outdated Show resolved Hide resolved
src/collaborative/session.ts Outdated Show resolved Hide resolved
src/plugins/ui_stateful/clipboard.ts Show resolved Hide resolved
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

coucou :)

src/collaborative/revisions.ts Outdated Show resolved Hide resolved
src/history/local_history.ts Outdated Show resolved Hide resolved
src/history/factory.ts Show resolved Hide resolved
src/history/repeat_commands/repeat_commands_generic.ts Outdated Show resolved Hide resolved
src/history/repeat_commands/repeat_commands_specific.ts Outdated Show resolved Hide resolved
src/history/repeat_commands/repeat_commands_specific.ts Outdated Show resolved Hide resolved
}

/** Apply generic transforms (sheetID, target, ...) to the core command children of a local command */
export function getRepeatedLocalCommandChildrenGeneric<T extends LocalCommand>(
Copy link
Collaborator

Choose a reason for hiding this comment

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

this function is only used once for STOP_EDITION. maybe we could just move (and rename) this to a specific repeat function repeatStopEdition. It would be easier to understand than this kinda barbaric function name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I don't need to use it as a generic for odoo commands, I'll do that yeah.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like we don't need that in odoo, changed it to repeatStopEdition

Copy link
Contributor Author

@hokolomopo hokolomopo Apr 20, 2023

Choose a reason for hiding this comment

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

Edit: cannot make it into a specific transform because of cyclic imports. repeat_commands_registry.ts need repeatStopEdition to put in the registry => repeatStopEdition need repeatCoreCommand => repeatCoreCommand need the registry.

I put it back in this file, but changed the name to repeatLocalCommandChildren which is less of a mouthful

src/types/commands.ts Show resolved Hide resolved
src/history/repeat_commands/repeat_revision.ts Outdated Show resolved Hide resolved
src/model.ts Outdated Show resolved Hide resolved
@hokolomopo hokolomopo force-pushed the master-redo-command-adrm branch 2 times, most recently from 90b37ac to 367d45e Compare April 12, 2023 08:33
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

bloup bloup :)
Almost ready :)

src/plugins/ui_plugin.ts Outdated Show resolved Hide resolved
return repeatTransform(getters, command, childCommands);
}

export function getRepeatedCoreCommands(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would move those "generic" helper functions to repeat_revision.ts

Copy link
Contributor Author

@hokolomopo hokolomopo Apr 14, 2023

Choose a reason for hiding this comment

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

The reason I put them there is to avoid cyclic dependencies :x

src/registries/repeat_commands_registry.ts Outdated Show resolved Hide resolved
src/registries/repeat_commands_registry.ts Outdated Show resolved Hide resolved
src/registries/repeat_commands_registry.ts Outdated Show resolved Hide resolved
tests/plugins/history.test.ts Outdated Show resolved Hide resolved
tests/test_helpers/constants.ts Show resolved Hide resolved
src/model.ts Show resolved Hide resolved
@hokolomopo hokolomopo force-pushed the master-redo-command-adrm branch 4 times, most recently from b5cfc58 to b871128 Compare April 19, 2023 06:41
repeatPositionDependantCommand,
];

export function repeatSheetDependantCommand<T extends Command>(getters: Getters, command: T): T {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just realized this but it's actually spelled dependent in American English, we should change that at some point

src/plugins/ui_feature/local_history.ts Show resolved Hide resolved
src/types/misc.ts Outdated Show resolved Hide resolved
src/registries/repeat_commands_registry.ts Outdated Show resolved Hide resolved
@@ -193,6 +200,17 @@ export class Session extends EventBus<CollaborativeEvent> {
return this.pendingMessages.length === 0;
}

/** Get the last local revision that doesn't come from a REQUEST_REDO command */
getLastLocalNonRedoRevision(): Revision | undefined {
const revisions = this.revisions.getRevertedExecution();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick as most of my comments but I don't like this function - it could technically capture a "REQUEST_UNDO" command, it's just that we don't call the function in that case because the presence of request undo in the session implies the existence of some commands in the undo stack inside local history but the session is unaware of the undo/redo stack. I think it should be more 'draconian' or at least add some comments/check where it is called.

Copy link
Contributor Author

@hokolomopo hokolomopo Apr 20, 2023

Choose a reason for hiding this comment

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

After looking a bit into that, if I understand correctly revisions from standard undo/redo are created inside the selective_history, and are empty. So they are not returned in this method. But this isn't very intuitive, so I changed things a bit and added a comment.

LMK if the code looks clearer now

src/history/factory.ts Outdated Show resolved Hide resolved
@rrahir
Copy link
Collaborator

rrahir commented Apr 19, 2023

forgot to mention the circular dependency at build :/

doc/extending/command.md Outdated Show resolved Hide resolved
doc/extending/command.md Outdated Show resolved Hide resolved
The commit transform the history into a standard UI feature plugin. To do
that :

- the session is now given to the constructor of the UI plugins
- `session.on("revison-redone")` and `session.on("revison-undone")` are
now handled directly in the model, as they need `dispatchFromCorePlugin`

Task: 2508693
Now if we do a redo and the redo stack is empty, we will try the redo
the last played command if possible. The list of repeatable commands
is defined in the repeat_commands_registry.ts file.

Repeated commands are transformed to match the current selection/sheet.
To be able to repeat local commands, the "root" command of a revision
was added to the history.

Locals commands of stateful UI plugins cannot be simply transformed and
repeated, because the state of The plugin may have changed. There is 2
strategies to solve this :

1. If possible, transform core sub-commands instead (eg. STOP_EDITION)
2. If not possible, we have to store the last state of the plugin, and
dispatch a new commands REPEAT_* (eg. REPEAT_PASTE)

It's not possible to adapt the sub-commands of the paste command, because
they are dependant on the state of the sheet, and may change based on the
paste location. A simple example is that paste create new col/rows for the
clipboard content to fit the sheet. So there will be ADD_COL_ROW_COMMANDS
in the sub commands in the history, but repeating paste might not need them.
Or they could only needed for the repeated paste, not for the original.

Task: 2508693
Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

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

robodoo r+

@LucasLefevre
Copy link
Collaborator

robodoo rebase-ff bordel 😬

robodoo pushed a commit that referenced this pull request Apr 20, 2023
The commit transform the history into a standard UI feature plugin. To do
that :

- the session is now given to the constructor of the UI plugins
- `session.on("revison-redone")` and `session.on("revison-undone")` are
now handled directly in the model, as they need `dispatchFromCorePlugin`

Task: 2508693
Part-of: #2126
robodoo pushed a commit that referenced this pull request Apr 20, 2023
robodoo pushed a commit that referenced this pull request Apr 20, 2023
Now if we do a redo and the redo stack is empty, we will try the redo
the last played command if possible. The list of repeatable commands
is defined in the repeat_commands_registry.ts file.

Repeated commands are transformed to match the current selection/sheet.
To be able to repeat local commands, the "root" command of a revision
was added to the history.

Locals commands of stateful UI plugins cannot be simply transformed and
repeated, because the state of The plugin may have changed. There is 2
strategies to solve this :

1. If possible, transform core sub-commands instead (eg. STOP_EDITION)
2. If not possible, we have to store the last state of the plugin, and
dispatch a new commands REPEAT_* (eg. REPEAT_PASTE)

It's not possible to adapt the sub-commands of the paste command, because
they are dependant on the state of the sheet, and may change based on the
paste location. A simple example is that paste create new col/rows for the
clipboard content to fit the sheet. So there will be ADD_COL_ROW_COMMANDS
in the sub commands in the history, but repeating paste might not need them.
Or they could only needed for the repeated paste, not for the original.

closes #2126

Task: 2508693
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
@robodoo
Copy link
Collaborator

robodoo commented Apr 20, 2023

Merge method set to rebase and fast-forward.

@robodoo robodoo temporarily deployed to merge April 20, 2023 13:14 Inactive
@robodoo robodoo closed this Apr 20, 2023
@robodoo robodoo added the 16.3 label Apr 20, 2023
@fw-bot fw-bot deleted the master-redo-command-adrm branch May 4, 2023 13:46
rrahir added a commit that referenced this pull request May 13, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4201

Task: 3916488
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
fw-bot pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: be5500d
fw-bot pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: be5500d
fw-bot pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: be5500d
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4217

Task: 3916488
X-original-commit: be5500d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4216

Task: 3916488
X-original-commit: be5500d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
rrahir added a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: be5500d
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4218

Task: 3916488
X-original-commit: be5500d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
fw-bot pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: 5b7b84b
rrahir added a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: 5b7b84b
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4219

Task: 3916488
X-original-commit: 5b7b84b
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
fw-bot pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

Task: 3916488
X-original-commit: f0f1e3d
robodoo pushed a commit that referenced this pull request May 15, 2024
Since pull request 2126[^1], the shortcut F4 is handled by the grid
component. Unfortunately, the same shortcut is handled in the composer
as well and its propabation was not stopped. This means that a user
wanting to loop the references inside their formula could see some
unexpected side effects due to the grid replaying some commands.

[^1]: #2126

closes #4221

Task: 3916488
X-original-commit: f0f1e3d
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants