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

Add scroll navigation to user's location from profile view #316

Merged
merged 11 commits into from
Aug 26, 2024

Conversation

choidabom
Copy link
Contributor

@choidabom choidabom commented Aug 24, 2024

What this PR does / why we need it?

This PR introduces a feature that automatically scrolls to a user's corresponding section in the document when that user's profile is clicked. This functionality is intended to streamline collaboration by minimizing the time users spend searching for specific content tied to team members.

Any background context you want to provide?

In collaborative platforms with extensive documentation, such as Figma, enabling users to readily navigate to pertinent sections based on user profiles significantly boosts productivity and fosters more efficient teamwork. This feature is particularly beneficial in lengthy documents where manually locating information can hinder progress.

Note: The scroll navigation feature requires that the user has selected an editor section. If no section is selected, the navigation will not occur.

What are the relevant tickets?

Fixes #256

Checklist

  • Added relevant tests or not required
  • Didn't break anything

Summary by CodeRabbit

  • New Features

    • Enhanced user presence component to allow direct navigation to user locations in the editor upon avatar clicks.
    • Introduced a new property for improved tracking of user selections in presence data.
  • Refactor

    • Streamlined user presence management in the document header component with a new custom hook.
    • Updated the user presence component to improve state management using Redux.
    • Modified the document management hook for enhanced error resilience and maintainability.

Copy link
Contributor

coderabbitai bot commented Aug 24, 2024

Walkthrough

The changes involve a refactoring of user presence management, including the renaming of components, updates to state management through Redux, and the introduction of new functions for enhanced user interaction. The implementation allows for improved navigation by moving the cursor to a user's profile location in the document, thereby enhancing collaborative functionalities.

Changes

File Change Summary
frontend/src/components/headers/UserPresenceList.tsx Renamed UserPresence to UserPresenceList, updated props interface, and integrated useSelector for Redux state management. Added navigation functionality.
frontend/src/hooks/useYorkieDocument.ts Updated document state type and added helper functions for managing the Yorkie document and client, including error handling improvements.
frontend/src/utils/yorkie/yorkieSync.ts Added a cursor property to the YorkieCodeMirrorPresenceType to enhance user presence tracking.
frontend/src/utils/yorkie/remoteSelection.ts Enhanced selection handling by computing a new cursor variable included in the presence updates.
frontend/src/components/headers/DocumentHeader.tsx Refactored user presence management by replacing the useList hook with a custom useUserPresence hook, simplifying the component's logic and subscription handling.

Assessment against linked issues

Objective Addressed Explanation
Add functionality to move cursor to user's profile when clicked (#256)

🐰 In the meadow where changes bloom,
A cursor leaps to find its room.
With profiles clicked, they dance with glee,
In documents shared, oh, how happy we’ll be!
A hop, a skip, in code we trust,
Collaboration flourishes, it's a must! 🌼


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 testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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.

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (3)
frontend/src/hooks/useUserPresence.ts (1)

43-44: Return additional utility functions if needed.

Currently, only presenceList is returned. Consider if additional utility functions (e.g., for manual updates) might be beneficial for future use cases.

frontend/src/components/headers/UserPresenceList.tsx (1)

50-54: Improve accessibility for avatars.

Consider adding aria-label attributes to avatars for better accessibility, especially for screen readers.

 <Avatar
+  aria-label={`Avatar of ${presence.presence.name}`}
   onClick={() => handleScrollToUserLocation(presence)}
   alt={presence.presence.name}
   sx={{ bgcolor: presence.presence.color }}
 >
frontend/src/routes.tsx (1)

32-32: Typo correction in AccessType comment.

The correction from "Authroized" to "Authorized" in the PRIVATE access type comment improves clarity.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2ca8d32 and d357462.

Files selected for processing (8)
  • frontend/src/components/editor/Editor.tsx (1 hunks)
  • frontend/src/components/headers/DocumentHeader.tsx (2 hunks)
  • frontend/src/components/headers/UserPresenceList.tsx (4 hunks)
  • frontend/src/hooks/useUserPresence.ts (1 hunks)
  • frontend/src/hooks/useYorkieDocument.ts (2 hunks)
  • frontend/src/routes.tsx (2 hunks)
  • frontend/src/utils/yorkie/remoteSelection.ts (1 hunks)
  • frontend/src/utils/yorkie/yorkieSync.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • frontend/src/components/editor/Editor.tsx
Additional comments not posted (15)
frontend/src/hooks/useUserPresence.ts (1)

18-41: Ensure proper cleanup and error handling in useEffect.

The useEffect hook correctly subscribes and unsubscribes to document events. However, consider adding error handling for potential issues during subscription or presence retrieval.

frontend/src/components/headers/UserPresenceList.tsx (2)

36-43: Verify the cursor position handling.

Ensure that the cursor position (presence.presence.cursor) is correctly defined and handled, as incorrect values could lead to errors or unexpected behavior.


82-86: Ensure consistent styling for list items.

Verify that the styling for ListItem components is consistent with the rest of the application, particularly in terms of padding and alignment.

frontend/src/components/headers/DocumentHeader.tsx (1)

31-31: Ensure editorState.doc is always valid.

The useUserPresence hook relies on editorState.doc. Ensure that this value is always valid and correctly initialized to prevent runtime errors.

frontend/src/utils/yorkie/yorkieSync.ts (1)

13-13: Verify the usage of the new cursor property.

The addition of the cursor property to YorkieCodeMirrorPresenceType looks good. Ensure that this property is correctly utilized in the rest of the codebase to track cursor positions effectively.

Run the following script to verify the usage of the cursor property:

Verification successful

The cursor property is correctly utilized. The cursor property in YorkieCodeMirrorPresenceType is effectively used to track and manage cursor positions in the codebase.

  • remoteSelection.ts: Utilizes cursor for calculating position ranges and rendering remote selections.
  • UserPresenceList.tsx: Uses cursor to scroll the editor view to the cursor position.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the `cursor` property in the codebase.

# Test: Search for the usage of the `cursor` property. Expect: Occurrences of `cursor` being accessed or modified.
rg --type js --type ts 'cursor'

Length of output: 5130


Script:

#!/bin/bash
# Extract relevant code snippets from remoteSelection.ts and UserPresenceList.tsx to verify cursor usage.

# Extract code from remoteSelection.ts where cursor is used
rg --type ts 'cursor' -A 5 frontend/src/utils/yorkie/remoteSelection.ts

# Extract code from UserPresenceList.tsx where cursor is used
rg --type tsx 'cursor' -A 5 frontend/src/components/headers/UserPresenceList.tsx

Length of output: 1257


Script:

#!/bin/bash
# Correct the command to extract relevant code snippets from UserPresenceList.tsx to verify cursor usage.

# Extract code from UserPresenceList.tsx where cursor is used
rg --type tsx 'cursor' -A 5 frontend/src/components/headers/UserPresenceList.tsx

Length of output: 108


Script:

#!/bin/bash
# Use a general search command to extract relevant code snippets from UserPresenceList.tsx to verify cursor usage.

# Extract code from UserPresenceList.tsx where cursor is used
rg 'cursor' -A 5 frontend/src/components/headers/UserPresenceList.tsx

Length of output: 231

frontend/src/routes.tsx (1)

6-11: LGTM! Reintroduced imports enhance routing capabilities.

The reintroduction of imports for SettingLayout, NotFound, and ProfileIndex enhances the routing capabilities and aligns with the PR objectives.

frontend/src/hooks/useYorkieDocument.ts (7)

23-23: LGTM! Updated document state type improves functionality.

The update from YorkieCodeMirrorDocType to CodePairDocType aligns with the new requirements and enhances functionality.


25-28: Helper function getYorkieToken improves modularity.

The getYorkieToken function encapsulates token retrieval logic, enhancing code modularity and readability.


30-37: Helper function createYorkieClient enhances modularity and error handling.

The createYorkieClient function encapsulates client creation logic, improving modularity and error handling.


39-54: Helper function createYorkieDocument enhances modularity.

The createYorkieDocument function encapsulates document creation logic, enhancing modularity and readability.


56-65: Error handling in cleanUpYorkieDocument improves resilience.

The addition of error handling in the cleanUpYorkieDocument function enhances error resilience during cleanup.


67-108: Lifecycle management with mounted flag prevents memory leaks.

The use of a mounted flag in the useEffect hook effectively manages the component lifecycle, preventing memory leaks.


11-12: Verify the configuration of new constants.

The introduction of YORKIE_API_ADDR and YORKIE_API_KEY improves configurability. Ensure these constants are correctly set in the environment variables.

Run the following script to verify the configuration of the new constants:

frontend/src/utils/yorkie/remoteSelection.ts (2)

154-154: Ensure correctness of cursor computation.

The cursor is computed using posRangeToIndexRange. Verify that this method correctly converts the position range to an index range and that the cursor value is used appropriately in the context of the application.

If the method posRangeToIndexRange is defined elsewhere, ensure its correctness by reviewing its implementation. Run the following script to locate and review the method:


158-159: Verify the impact of including cursor in presence.set.

The presence.set method now includes cursor along with selection. Ensure that the presence object is designed to handle this additional data and that it doesn't cause any unintended side effects.

If presence.set is defined elsewhere, ensure its correctness by reviewing its implementation. Run the following script to locate and review the method:

frontend/src/hooks/useUserPresence.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d357462 and 792f76c.

Files selected for processing (1)
  • frontend/src/hooks/useYorkieDocument.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/hooks/useYorkieDocument.ts

Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 792f76c and 2eb2dd1.

Files selected for processing (1)
  • frontend/src/components/headers/DocumentHeader.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/headers/DocumentHeader.tsx

Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2eb2dd1 and 8fdcd5b.

Files selected for processing (1)
  • frontend/src/components/headers/DocumentHeader.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/components/headers/DocumentHeader.tsx

Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8fdcd5b and ec7daf2.

Files selected for processing (2)
  • frontend/src/components/headers/DocumentHeader.tsx (3 hunks)
  • frontend/src/hooks/useUserPresence.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • frontend/src/hooks/useUserPresence.ts
Additional comments not posted (3)
frontend/src/components/headers/DocumentHeader.tsx (3)

19-19: Imports look good!

The new import useUserPresence is correctly used in the component.


32-32: Usage of useUserPresence is correct!

The useUserPresence hook is used effectively to manage the presenceList.


90-92: Consider lazy loading for UserPresenceList.

If the presence list is large, consider implementing lazy loading or virtualization to improve performance.

@devleejb devleejb self-requested a review August 25, 2024 08:20
frontend/src/components/headers/DocumentHeader.tsx Outdated Show resolved Hide resolved
frontend/src/components/headers/UserPresenceList.tsx Outdated Show resolved Hide resolved
frontend/src/utils/yorkie/yorkieSync.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ec7daf2 and 5dd28ba.

Files selected for processing (4)
  • frontend/src/components/headers/UserPresenceList.tsx (4 hunks)
  • frontend/src/hooks/useYorkieDocument.ts (2 hunks)
  • frontend/src/utils/yorkie/remoteSelection.ts (2 hunks)
  • frontend/src/utils/yorkie/yorkieSync.ts (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • frontend/src/components/headers/UserPresenceList.tsx
  • frontend/src/utils/yorkie/remoteSelection.ts
  • frontend/src/utils/yorkie/yorkieSync.ts
Additional comments not posted (8)
frontend/src/hooks/useYorkieDocument.ts (8)

3-6: LGTM!

The new imports are necessary for the updated logic.

The code changes are approved.


11-12: LGTM!

The new constants YORKIE_API_ADDR and YORKIE_API_KEY are correctly defined.

The code changes are approved.


23-23: LGTM!

The state initialization for client and doc is correctly implemented.

The code changes are approved.


25-28: LGTM!

The getYorkieToken function is well-implemented and correctly determines the Yorkie token.

The code changes are approved.


30-37: LGTM!

The createYorkieClient function is correctly implemented and activates the Yorkie client.

The code changes are approved.


39-55: LGTM!

The createYorkieDocument function is well-implemented and attaches the document to the client with initial presence settings.

The code changes are approved.


57-66: LGTM!

The cleanUpYorkieDocument function is correctly implemented with appropriate error handling.

The code changes are approved.


68-109: LGTM!

The useEffect hook is well-implemented to manage the lifecycle of the Yorkie client and document. The mounted flag effectively prevents state updates on unmounted components.

The code changes are approved.

@devleejb
Copy link
Member

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 26, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5dd28ba and 296ea58.

Files selected for processing (1)
  • frontend/src/components/headers/DocumentHeader.tsx (2 hunks)
Additional comments not posted (4)
frontend/src/components/headers/DocumentHeader.tsx (4)

18-18: LGTM!

The import statement for useUserPresence is correct.

The code changes are approved.


24-24: LGTM!

The import statement for UserPresenceList is correct.

The code changes are approved.


31-31: LGTM!

The useUserPresence hook is correctly used to get presenceList, improving the separation of concerns.

The code changes are approved.


89-89: LGTM!

The UserPresenceList component is correctly updated to use presenceList.

The code changes are approved.

Copy link
Member

@devleejb devleejb left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution.

@devleejb devleejb merged commit 995e4d0 into yorkie-team:main Aug 26, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Add Feature to Move Cursor to User's Profile when Profile is Clicked
2 participants