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

check if in popup before triggering shortcut #2789

Merged
merged 3 commits into from
Mar 7, 2025

Conversation

imolorhe
Copy link
Collaborator

@imolorhe imolorhe commented Mar 5, 2025

Fixes

Checks

  • Ran yarn test-build
  • Updated relevant documentations
  • Updated matching config options in altair-static

Changes proposed in this pull request:

Summary by Sourcery

Prevent shortcuts from being triggered when a popup is open. This change ensures that shortcuts are only triggered when the main application window is in focus, preventing unintended actions within popups. Additionally, this PR modifies the dialog component to emit events on save and submit.

Enhancements:

  • Prevent shortcuts from triggering when a popup is open.
  • Modify dialog component to emit events on save and submit.

Copy link

sourcery-ai bot commented Mar 5, 2025

Reviewer's Guide by Sourcery

This pull request introduces changes to prevent keyboard shortcuts from being triggered when the focus is within a popup dialog. It also modifies the dialog component to emit events on form submission, improving event handling.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Added functionality to prevent shortcuts from triggering when the focus is within a popup.
  • Added an allowInPopups parameter to the bindShortcut method.
  • Implemented the isInPopup method to check if the active element is within an nz-modal-container.
  • Modified the shortcut binding logic to prevent execution if allowInPopups is false and the user is in a popup.
packages/altair-app/src/app/modules/altair/services/keybinder/keybinder.service.ts
Updated the toggle variable and header pane shortcuts to not trigger when in a popup.
  • Added a true value to the allowInPopups parameter when calling bindShortcut for the toggle variable and header pane actions.
packages/altair-app/src/app/modules/altair/services/keybinder/keybinder.service.ts
Modified the dialog component to emit events on form submission.
  • Added a form element to the modalContent template.
  • Added a submit button to the form with display: none.
  • Added an onSubmit method to emit the toggleDialog and saveChange events.
  • Updated the onClickSave method to emit the toggleDialog and saveChange events.
packages/altair-app/src/app/modules/altair/components/dialog/dialog.component.ts
packages/altair-app/src/app/modules/altair/components/dialog/dialog.component.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Hello @imolorhe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request addresses an issue where shortcuts were being triggered even when a popup/modal was active. To fix this, I've added a check to ensure that the active element is not within an nz-modal-container before allowing the shortcut to execute. I've also added a hidden submit button to the dialog component to allow submitting the form when pressing enter.

Highlights

  • Shortcut Handling: Added a check to prevent shortcuts from triggering when a modal/popup is active. This is done by checking if the document.activeElement is within an nz-modal-container.
  • Dialog Submission: Added a hidden submit button within the dialog component's form to enable form submission when the user presses the Enter key.
  • Keybinder Service: Modified the bindShortcut function in KeybinderService to accept an allowInPopups parameter, defaulting to false. This parameter controls whether the shortcut should be active when a popup is open.

Changelog

  • packages/altair-app/src/app/modules/altair/components/dialog/dialog.component.html
    • Wrapped the ng-content within a <form> tag and added a hidden submit button. This allows the dialog to be submitted when pressing enter.
  • packages/altair-app/src/app/modules/altair/components/dialog/dialog.component.ts
    • Added an onSubmit method that emits the toggleDialog and saveChange events, similar to the onClickSave method.
  • packages/altair-app/src/app/modules/altair/services/keybinder/keybinder.service.ts
    • Added a check in the shortcut handler to prevent execution if allowInPopups is false and the current element is within a popup.
    • Added a private isInPopup method to check if the active element is within an nz-modal-container.
    • Modified the bindShortcut function to accept an allowInPopups parameter.
    • Set allowInPopups to true for 'Toggle Variable Pane' and 'Toggle Header Pane' shortcuts.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


A shortcut pressed, a function called,
But wait, a popup stands so tall.
No action taken, the popup's the key,
To keep the workflow smooth and free.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request introduces a fix to prevent shortcuts from being triggered when a dialog/popup is open. This is achieved by adding a check to see if the active element is within an nz-modal-container before executing the shortcut callback. Additionally, the PR adds a parameter to the bindShortcut function to allow specifying whether a shortcut should be allowed in popups. Overall, the changes seem reasonable and address the issue effectively.

Summary of Findings

  • Dialog Submission: The dialog component now includes a form that wraps the content. This change might have unintended consequences if the content already contains a form or relies on specific event handling. Ensure that this change doesn't break existing dialog implementations.
  • Shortcut Binding: The bindShortcut function now accepts an allowInPopups parameter. This is a good addition, but it's important to ensure that all existing shortcut bindings are reviewed to determine the appropriate value for this parameter. Some shortcuts might be intended to work in popups, while others should not.
  • Popup Detection: The isInPopup function relies on nz-modal-container to detect if the active element is within a popup. This might not be reliable if a different modal implementation is used. Consider making this more generic or configurable.

Merge Readiness

The pull request addresses a valid issue and the changes seem to be well-structured. However, before merging, it's crucial to address the potential issues identified in the findings summary, particularly regarding the dialog submission and shortcut bindings. I am unable to directly approve the pull request, and users should have others review and approve this code before merging. Given the medium severity comments, I recommend addressing these before merging.

Comment on lines +19 to +22
<form (ngSubmit)="onSubmit($event)">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</form>

Choose a reason for hiding this comment

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

medium

Wrapping the content in a <form> element might interfere with existing form elements within the dialog content. Consider if this is the best approach, or if there's a way to prevent potential conflicts. For example, could you add a class to the form and target that class in your CSS to avoid style conflicts?

Suggested change
<form (ngSubmit)="onSubmit($event)">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</form>
<div class="dialog-form">
<ng-content></ng-content>
<button type="submit" style="display: none"></button>
</div>

Comment on lines +157 to +158
description: string,
allowInPopups = false

Choose a reason for hiding this comment

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

medium

The description parameter is now required. Consider providing a default value that indicates the description is missing, rather than forcing every call site to provide one. Also, the TODO comment is now gone, but it would be good to have a description for each shortcut.

Suggested change
description: string,
allowInPopups = false
description: string = 'No description provided',


private isInPopup() {
const activeElement = document.activeElement as HTMLElement | null;
return !!activeElement?.closest('nz-modal-container');

Choose a reason for hiding this comment

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

medium

This function relies on the presence of nz-modal-container. If a different modal implementation is used, this check will fail. Consider making this more generic or configurable, perhaps by allowing a custom selector to be passed in.

Suggested change
return !!activeElement?.closest('nz-modal-container');
return !!activeElement?.closest('nz-modal-container, .custom-modal-container');

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @imolorhe - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a unit test for the isInPopup method to ensure it correctly identifies when the active element is within an nz-modal-container.
  • It might be helpful to add a comment explaining why certain shortcuts should not be triggered within popups.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

github-actions bot commented Mar 5, 2025

Visit the preview URL for this PR (updated for commit 7731146):

https://altair-gql--pr2789-imolorhe-check-popup-69kc97y4.web.app

(expires Wed, 12 Mar 2025 23:24:28 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 02d6323d75a99e532a38922862e269d63351a6cf

@imolorhe imolorhe added this pull request to the merge queue Mar 7, 2025
Merged via the queue into master with commit 7fbc922 Mar 7, 2025
15 checks passed
@imolorhe imolorhe deleted the imolorhe/check-popup-keyboard-shortcut branch March 7, 2025 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant