8000 [Refactoring] Improve shortcuts action by klakhov · Pull Request #9397 · cvat-ai/cvat · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Refactoring] Improve shortcuts action #9397

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

Merged
merged 5 commits into from
May 30, 2025
Merged

Conversation

klakhov
Copy link
Contributor
@klakhov klakhov commented May 6, 2025

Motivation and context

The restoreSettingsAsync function has become quite complex, especially the section with four nested loops. In this PR, I’ve refactored the logic by extracting parts into separate functions to improve readability and maintainability.

Related #9032

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • [ ] I have created a changelog fragment
  • [ ] I have updated the documentation accordingly
  • [ ] I have added tests to cover my changes
  • [ ] I have linked related issues (see GitHub docs)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

@klakhov klakhov added the ui/ux label May 6, 2025
@klakhov klakhov requested a review from bsekachev as a code owner May 6, 2025 09:46
@codecov-commenter
Copy link
codecov-commenter commented May 6, 2025

Codecov Report

Attention: Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.

Project coverage is 73.75%. Comparing base (8e9ad35) to head (c53eb21).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9397      +/-   ##
===========================================
- Coverage    73.75%   73.75%   -0.01%     
===========================================
  Files          447      447              
  Lines        46538    46541       +3     
  Branches      3937     3936       -1     
===========================================
- Hits         34326    34324       -2     
- Misses       12212    12217       +5     
Components Coverage Δ
cvat-ui 77.66% <94.11%> (-0.03%) ⬇️
cvat-server 70.69% <40.81%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@klakhov klakhov changed the title [Refactoring] Improve shourtcuts action [Refactoring] Improve shortcuts action May 7, 2025
@bsekachev
Copy link
Member

It seems that something might have been affected by the recent refactoring.
Could you try adding an intentionally conflicting shortcut to the local storage (for example, another F1 sequence that would conflict with the global SHOW SHORTCUTS)?
In the develop branch, one of the F1 shortcuts is removed in such cases, but with this patch, it appears that isn't happening.

Uh oh!

There was an error while loading. Please reload this page.

@klakhov
Copy link
Contributor Author
klakhov commented May 12, 2025

Thanks, updated.
The fun thing about this case is that we had a cypress test for it, but unfortunately it was passing because of incorrect selectors.😓

Copy link
Member
@bsekachev bsekachev left a comment

Choose a reason for hiding this comment

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

I see several problems in the current approach which probably not related to this refactoring, but please, check it in advance.

The first one has described in the code.

The second one: when we uploading shortcuts from local storage, we are looking for conflicts between local storage shortcuts and current keymap in the application. The problem here is that actually shortcuts from local storage may not have any conflicts between each other, when there may be conflicts between local storage shortcuts and current keymap shortcuts, which are basically just default values defined in the code (however these conflicts just do not make sense as we are going to update all sequences in current keymap from local storage values)

Speaking "update all sequences" I mean, in general, that all sequences are usually re-written, however there are also corner cases when application may have new shortcuts not saved in the local storage, or part shortcuts from local storage have been removed. This case will not work correctly as well.

As consequence, we may see several warnings in the browser console:
image

First conflict detector removes sequence for SWITCH_SHORTCUTS, leaving TOGGLE_ANNOTATION_PAGE equal to f1.
Then in reducer it again runs conflict detector and find the conflict again.

Refactoring LGTM, however the feature still needs some improvements.

Comment on lines +187 to +193
Object.keys(conflicts).forEach((conflictingKey) => {
resultMap[conflictingKey].sequences = removeConflictingSequences(
resultMap[conflictingKey].sequences,
conflicts[conflictingKey].sequences,
);
});
});
Copy link
Member
@bsekachev bsekachev May 27, 2025

Choose a reason for hiding this comment

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

Let's consider:

  • wrongShortcut to be a shortcut which has conflicts with any other shortcuts
  • conflictingShortcut to be a shortcut which conflicts with wrong shortcut

E.g. I set TOGGLE_ANNOTATION_PAGE to f1 in local storage
And we have SWITCH_SHORTCUTS also having f1 sequence

TOGGLE_ANNOTATION_PAGE in this scheme is wrongShortcut
SWITCH_SHORTCUTS isconflictingShortcut

The problem I see: we are filtering sequences of the conflictingShortcut (SWITCH_SHORTCUTS), however it would be more correct to filter sequences of wrongShortcut (TOGGLE_ANNOTATION_PAGE)

Copy link

@klakhov
Copy link
Contributor Author
klakhov commented May 30, 2025

Ok, I see the feature still requires improvements in logic. But refactoring is a step for improving this. Lets merge it for now.

@klakhov klakhov merged commit b23109d into develop May 30, 2025
34 checks passed
@klakhov klakhov deleted the kl/refactor-shortcuts-restore branch May 30, 2025 10:22
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.

3 participants
0