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: setup the context for keyboard hotkeys #4493

Merged
merged 8 commits into from
Feb 6, 2024

Conversation

vikrantgupta25
Copy link
Collaborator

@vikrantgupta25 vikrantgupta25 commented Feb 5, 2024

Summary

PRD for the below changes :- https://www.notion.so/signoz/Keyboard-Shortcuts-Framework-309c2b67f3c04ddab316c133ef051df3

  • Setup the base context and the hooks for the usage of keyboard hotkeys

Usage in components ->

Case 1 -> Usage of same shortcut l in two components (Services Module and Logs Explorer Module)

Services Trace Component

const { registerShortcut, deregisterShortcut } = useKeyboardHotkeys();

	useEffect(() => {
		registerShortcut('l', () => {
			console.log('Services Traces Table');
		});

		return (): void => {
			deregisterShortcut('l');
		};
		// eslint-disable-next-line react-hooks/exhaustive-deps
	}, []);

Logs Explorer Component

const { registerShortcut, deregisterShortcut } = useKeyboardHotkeys();

	useEffect(() => {
		registerShortcut('l', () => {
			console.log('LogsExplorerList');
		});

		return (): void => {
			deregisterShortcut('l');
		};
		// eslint-disable-next-line react-hooks/exhaustive-deps
	}, []);

Since the components are not present on the screen at the same time no error is thrown and both are supported as expected

Video Reference:-

  • the below video shows example of same shortcut l across two different modules not firing together and the input boxes not triggering the shortcut callbacks
Screen.Recording.2024-02-05.at.3.01.50.PM.mov

Case 2 -> Usage of same shortcuts in the same component tree when both are rendered on the screen at same time

Services Root Component

	const { registerShortcut, deregisterShortcut } = useKeyboardHotkeys();

	useEffect(() => {
		registerShortcut('l', () => {
			console.log('Services');
		});

		return (): void => {
			deregisterShortcut('l');
		};
		// eslint-disable-next-line react-hooks/exhaustive-deps
	}, []);

Services Trace Table Component

const { registerShortcut, deregisterShortcut } = useKeyboardHotkeys();

	useEffect(() => {
		registerShortcut('l', () => {
			console.log('Duplicate Services Traces Table');
		});

		return (): void => {
			deregisterShortcut('l');
		};
		// eslint-disable-next-line react-hooks/exhaustive-deps
	}, []);

Now since both of them are present in the screen at the same time we throw an exception and crash the UI at development stage itself so as the dev should be aware of the same.

Video Reference:-

Screen.Recording.2024-02-05.at.2.59.36.PM.mov

Added Implementation of CMD+B for SideNav Collapse and Open

Screen.Recording.2024-02-05.at.3.16.54.PM.mov

Summary by CodeRabbit

  • New Features
    • Enhanced navigation and usability with hotkey functionality, including shortcuts for sidebar collapse.
  • Tests
    • Ensured reliable operation and integration with added tests for keyboard shortcuts.

Copy link

coderabbitai bot commented Feb 5, 2024

Warning

Rate Limit Exceeded

@Vikrant2520 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 51 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 27157d6 and 6f9e2b7.

Walkthrough

The recent update introduces a new KeyboardHotkeysProvider component that enhances the application with keyboard shortcut functionalities. Alongside this, a new hook named useKeyboardHotkeys has been added to manage keyboard shortcuts efficiently within the application.

Changes

File Path Change Summary
frontend/src/AppRoutes/index.tsx Added KeyboardHotkeysProvider around AppLayout.
frontend/src/constants/shortcuts/globalShortcuts.ts
frontend/src/container/SideNav/SideNav.tsx
Introduced a shortcut for collapsing the sidebar.
Updated sidebar collapse shortcut handling.
frontend/src/hooks/hotkeys/__tests__/useKeyboardHotkeys.test.tsx Added tests for useKeyboardHotkeys hook.

🐰✨
In the world of code, where keys now play,
Shortcuts dance, making tasks a swift ballet.
Each stroke, a command, each combo, a spell,
Productivity blooms where the rabbit's touch dwell.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

@github-actions github-actions bot added the enhancement New feature or request label Feb 5, 2024
Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 26bc94f and 4de2368.
Files selected for processing (2)
  • frontend/src/AppRoutes/index.tsx (2 hunks)
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx (1 hunks)
Additional comments: 6
frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx (5)
  • 16-21: The default context value uses noop from lodash for registerShortcut and deregisterShortcut. Ensure that this aligns with the intended behavior when the context is used outside of its provider.
  • 23-23: The IGNORE_INPUTS array is a good approach to prevent hotkey actions in input fields. Verify that all relevant input types are covered.
  • 26-31: The error thrown in the custom hook ensures it's used within its provider. This is a good practice for context hooks.
  • 59-64: Using useEffect to add and remove the event listener is correct. Ensure that the dependency array is intentionally left empty to only run on mount and unmount.
  • 75-81: The deregisterShortcut function correctly removes a registered shortcut. Ensure that there's a mechanism to prevent memory leaks or dangling references.
frontend/src/AppRoutes/index.tsx (1)
  • 181-198: The integration of KeyboardHotkeysProvider around AppLayout is correctly implemented to provide hotkey functionality across the application. Ensure that this does not introduce any unintended side effects, especially in components deeply nested within AppLayout.

frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx Outdated Show resolved Hide resolved
frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx Outdated Show resolved Hide resolved
frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

1 similar comment
Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 4de2368 and 3a917ef.
Files selected for processing (1)
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

1 similar comment
Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

1 similar comment
Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9d68969 and bdab0ba.
Files selected for processing (4)
  • frontend/src/AppRoutes/index.tsx (2 hunks)
  • frontend/src/container/SideNav/SideNav.tsx (3 hunks)
  • frontend/src/hooks/hotkeys/tests/useKeyboardHotkeys.test.tsx (1 hunks)
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • frontend/src/AppRoutes/index.tsx
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx
Additional comments: 2
frontend/src/container/SideNav/SideNav.tsx (2)
  • 12-12: The import of useKeyboardHotkeys is correctly placed and follows the project's import ordering conventions.
  • 159-173: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [102-169]

The registration and deregistration of the 'b+meta' shortcut for collapsing the sidebar are correctly implemented within a useEffect hook. However, the dependency array of the useEffect hook is empty, which is appropriate in this case since onCollapse is stable and doesn't depend on any props or state. Ensure that onCollapse remains stable if additional dependencies are introduced in the future.

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 554c433 and 27157d6.
Files selected for processing (5)
  • frontend/src/AppRoutes/index.tsx (2 hunks)
  • frontend/src/constants/shortcuts/globalShortcuts.ts (1 hunks)
  • frontend/src/container/SideNav/SideNav.tsx (3 hunks)
  • frontend/src/hooks/hotkeys/tests/useKeyboardHotkeys.test.tsx (1 hunks)
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • frontend/src/AppRoutes/index.tsx
  • frontend/src/constants/shortcuts/globalShortcuts.ts
  • frontend/src/container/SideNav/SideNav.tsx
  • frontend/src/hooks/hotkeys/tests/useKeyboardHotkeys.test.tsx
  • frontend/src/hooks/hotkeys/useKeyboardHotkeys.tsx

Copy link

github-actions bot commented Feb 5, 2024

Build Error! No Linked Issue found. Please link an issue or mention it in the body using #<issue_id>

@Rajat-Dabade Rajat-Dabade merged commit f6ab060 into develop Feb 6, 2024
11 checks passed
@makeavish makeavish deleted the keyboard-shortcuts branch February 13, 2024 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants