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 Root-Only Filter Feature in History Tab #872

Conversation

gwbaik9717
Copy link
Contributor

@gwbaik9717 gwbaik9717 commented Jul 18, 2024

What this PR does / why we need it?

This pull request adds a Root-Only Filter in the History tab, allowing users to focus exclusively on changes to the Root of the Document. Currently, the History tab logs both content changes and Presence events (such as cursor movements), which can result in a high volume of events that may not always be relevant for debugging content changes.

Any background context you want to provide?

What are the relevant tickets?

Fixes #854

Checklist

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

Summary by CodeRabbit

  • New Features

    • Introduced a button in the History tab to toggle the visibility of the Presence tab.
    • Enhanced the Document component to dynamically manage the visibility of the Presence tab.
    • Added categorization for transaction events in the History component.
    • Improved context management to filter transaction events based on user preferences.
  • Style

    • Updated layout and appearance by removing specific width and border styles from elements.
    • Renamed classes for improved clarity in the styles.
    • Adjusted the display of the slider component to reduce visual clutter when only one history item is present.

Copy link

coderabbitai bot commented Jul 18, 2024

Walkthrough

The recent changes enhance the Devtools UI by introducing features that allow developers to filter out the Presence tab, enabling a sharper focus on Root content changes. The addition of state variables hidePresenceTab and hidePresenceEvents provides users with greater control over component visibility, streamlining the debugging process and improving user interaction.

Changes

Files Change Summary
…/panel/index.tsx Introduced hidePresenceTab state for controlling the visibility of the presence tab in the Panel component.
…/panel/styles.css Renamed classes and removed specific styling properties to enhance responsiveness and layout.
…/tabs/Document.tsx Added props hidePresenceTab and setHidePresenceTab for dynamic tab visibility management in Document.
…/tabs/History.tsx Introduced TransactionEventType enum and dynamic event type handling; included parameters for toggling visibility in History.
…/contexts/YorkieSource.tsx Enhanced context management with hidePresenceEvents state to control visibility of presence events.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant History
    participant Panel
    participant Document
    participant YorkieSource

    User->>History: Click toggle button
    History->>Panel: Update hidePresenceTab state
    Panel-->>Document: Adjust styling based on hidePresenceTab
    Panel-->>YorkieSource: Update event filtering based on hidePresenceEvents
Loading

Assessment against linked issues

Objective Addressed Explanation
Enhance Devtools UI with Root-only Filter Feature in History (#854)

Poem

In Devtools' realm where bugs reside,
A toggle switch, our trusty guide,
To filter out the Presence's flair,
And focus on the content rare.
Debugging now, a smoother ride,
With clarity on Root's abide. 🐇✨


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

@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 02111d3 and 85cec51.

Files selected for processing (3)
  • tools/devtools/src/devtools/panel/index.tsx (4 hunks)
  • tools/devtools/src/devtools/panel/styles.css (1 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (2 hunks)
Additional comments not posted (7)
tools/devtools/src/devtools/panel/index.tsx (4)

44-44: LGTM!

The addition of the hidePresenceTab state variable is straightforward and aligns with the PR objectives.


61-67: LGTM!

The conditional styling of the Document component based on the hidePresenceTab state is efficient and maintains a clean UI.


127-128: LGTM!

The addition of hidePresenceTab and setHidePresenceTab props to the History component is necessary for the new feature and is implemented correctly.


139-149: LGTM!

The conditional rendering of the Presence component based on the hidePresenceTab state aligns with the PR objectives and maintains a clean UI.

tools/devtools/src/devtools/tabs/History.tsx (2)

66-67: LGTM!

The addition of hidePresenceTab and setHidePresenceTab props to the History component is necessary for the new feature and is implemented correctly.


185-191: LGTM!

The button to toggle the hidePresenceTab state is implemented correctly and provides a clear user interface. The button text updates accordingly based on the state.

tools/devtools/src/devtools/panel/styles.css (1)

Line range hint 1-1: LGTM!

The removal of styling properties related to width and border for the .yorkie-root class aligns with the changes made to the Document component's style in index.tsx.

@gwbaik9717
Copy link
Contributor Author

gwbaik9717 commented Jul 18, 2024

I've temporarily added a filter icon represented by Y, and ¥, but there might be better icon than those...

Moreover, I'm encountering a TypeScript error in devtools directory that isn't resolved even after running npm i. Is there any solution for this situation?

(I forgot to mention that the error has been occurring since I first pulled the repository. It happens in the History.tsx file in the devtools and possibly other places. )

Screenshot 2024-07-18 at 9 39 39 PM

@chacha912
Copy link
Contributor

chacha912 commented Jul 19, 2024

@gwbaik9717
Thank you for your PR. I have a few comments and suggestions:

  1. Issue Enhance Devtools UI with Root-only Filter Feature In History #854 Scope:

    The original issue was about adding a filtering feature in the history tab to show only root-related events (snapshot, local-change, remote-change). This was intended to make debugging root data changes easier by filtering out the numerous presence-change events caused by cursor movements. The goal was to display only document icon changes (root changes) when filtered, as opposed to cursor icon changes (presence changes).

image

  1. Current PR Focus(Presence Tab Control):

    Your PR seems to focus on adding controls to the Presence tab. The ability to resize tabs by dragging the center line already exists. However, your proposed button control could be a useful addition. I suggest we consider adding arrow icons next to the Presence tab for this control. What are your thoughts on this UI approach?

image

  1. Type Errors:

    There appear to be some type-related errors in the existing code. It seems we need to define a type for the transactionEvent used in Devtools. Could you create a separate issue for this problem? Then I'll fix these type-related errors.

Please let me know if you have any questions or need further clarification. Looking forward to your updates!

@gwbaik9717
Copy link
Contributor Author

  1. Thank you for the detailed explanation! It seems like I totally misunderstood the issue. Now, I totally got it!

  2. I think it's a great idea! I'll give it a try.

  3. As you suggested, I created an issue regarding the type error which is TypeScript Error in Devtools: TransactionEvent #873

This commit adds a Root-Only Filter to the History tab, allowing users to view only changes to the Root of the Document.
This feature helps developers focus specifically on content changes by filtering out the more frequent Presence events that track user presence information such as cursors.
@gwbaik9717 gwbaik9717 force-pushed the enhance-devtools-ui-with-root-only-filter branch from 85cec51 to e191153 Compare July 20, 2024 11:49
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.

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 85cec51 and e191153.

Files selected for processing (3)
  • tools/devtools/src/devtools/panel/index.tsx (5 hunks)
  • tools/devtools/src/devtools/panel/styles.css (1 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (6 hunks)
Files skipped from review as they are similar to previous changes (3)
  • tools/devtools/src/devtools/panel/index.tsx
  • tools/devtools/src/devtools/panel/styles.css
  • tools/devtools/src/devtools/tabs/History.tsx

This enhancement allows users to toggle the visibility of the Presence tab, providing a more focused view of the content they are interested in.
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.

Actionable comments posted: 3

Outside diff range, codebase verification and nitpick comments (4)
tools/devtools/src/devtools/tabs/Document.tsx (1)

26-26: Update function signature in comments and documentation.

The function signature has been updated to include hidePresenceTab and setHidePresenceTab. Ensure that comments and documentation reflect this change.

tools/devtools/src/devtools/panel/index.tsx (3)

63-64: Ensure consistent naming for state variables.

The state variable hidePresenceTab is used to manage the visibility of the presence tab. Ensure consistent naming conventions for state variables throughout the codebase.


140-142: Ensure consistent prop naming in components.

The props hidePresenceEvent and setHidePresenceEvent are passed to the History component. Ensure consistent naming conventions for props throughout the codebase.


153-163: Ensure consistent styling and prop usage.

The Document component is updated to receive hidePresenceTab and setHidePresenceTab as props. Ensure consistent styling and prop usage throughout the codebase.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e191153 and f5e538a.

Files selected for processing (4)
  • tools/devtools/src/devtools/panel/index.tsx (5 hunks)
  • tools/devtools/src/devtools/panel/styles.css (3 hunks)
  • tools/devtools/src/devtools/tabs/Document.tsx (2 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tools/devtools/src/devtools/panel/styles.css
  • tools/devtools/src/devtools/tabs/History.tsx
Additional comments not posted (1)
tools/devtools/src/devtools/panel/index.tsx (1)

Line range hint 83-98: Ensure proper handling of side effects in useEffect.

The useEffect hook should handle side effects properly. Consider adding cleanup functions if necessary.

tools/devtools/src/devtools/tabs/Document.tsx Outdated Show resolved Hide resolved
tools/devtools/src/devtools/panel/index.tsx Show resolved Hide resolved
tools/devtools/src/devtools/panel/index.tsx Outdated Show resolved Hide resolved
@gwbaik9717
Copy link
Contributor Author

I've found a bug in the slider component: when there is only one dot, a redundant trail (-) appears next to its node. I'm not sure if this issue was caused by my commit or if it was pre-existing, but I believe it is about CSS issue within the react-slider library. I've tried to fix it but I'm currently stuck, so I'm asking for help.

Screenshot 2024-07-20 at 9 28 52 PM

This commit refactors the Root-Only Filter feature in the History tab. The filter logic has been moved inside useTransactionEvents to prevent props drilling and to group related functionalities by domain.
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.

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 f5e538a and 437fae5.

Files selected for processing (3)
  • tools/devtools/src/devtools/contexts/YorkieSource.tsx (4 hunks)
  • tools/devtools/src/devtools/panel/index.tsx (4 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tools/devtools/src/devtools/panel/index.tsx
Additional comments not posted (12)
tools/devtools/src/devtools/contexts/YorkieSource.tsx (6)

17-23: LGTM!

The new imports for Dispatch and SetStateAction are appropriate for managing state in the context.


36-40: LGTM!

The TransactionEventsContext has been appropriately enhanced to include events, hidePresenceEvents, and setHidePresenceEvents.


53-55: LGTM!

The state variable hideTransactionPresenceEvents is necessary for managing the visibility of presence events.


110-116: LGTM!

The TransactionEventsContext.Provider value has been correctly updated to include events, hidePresenceEvents, and setHidePresenceEvents.


143-146: LGTM!

The TransactionEventType enum provides clear categorization of transaction events into Document and Presence.


148-163: LGTM!

The getTransactionEventType function correctly determines the type of transaction event based on its properties.

tools/devtools/src/devtools/tabs/History.tsx (6)

22-26: LGTM!

The new imports for TransactionEventType, getTransactionEventType, and useTransactionEvents are necessary for the enhanced functionality of the History component.


74-75: LGTM!

The useTransactionEvents hook is appropriately used to access events, hidePresenceEvents, and setHidePresenceEvents.


84-90: LGTM!

The toggleHidePresenceEvent function correctly manages the visibility of presence events and resets the selected event index.


103-117: LGTM!

The useEffect hook correctly sets the slider marks based on the transaction event type.


194-196: LGTM!

The button correctly toggles the visibility of presence events and updates its label based on the current state.


213-213: LGTM!

The modification of the slider step value from 1 to 0 allows for finer control in the event selection.

@chacha912
Copy link
Contributor

@gwbaik9717
It seems like the issue is with the rc-slider library, and it can be resolved as follows:

// History.tsx
<div
  ref={scrollRef}
  style={{ width: '100%', overflowX: 'auto', minHeight: '46px' }}
  className="history-slider-wrap" // added
  data-length={events.length} // added
>
  <Slider dots ... />
</div>
/* slider.css */
.history-slider-wrap[data-length='1'] .rc-slider-rail {
  display: none;
}

This commit fixes a bug in the slider component: when there is only one dot, a redundant trail (-) appears next to its node.
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.

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 437fae5 and b65dfbb.

Files selected for processing (2)
  • tools/devtools/src/devtools/panel/slider.css (1 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review due to trivial changes (1)
  • tools/devtools/src/devtools/panel/slider.css
Additional comments not posted (6)
tools/devtools/src/devtools/tabs/History.tsx (6)

22-26: LGTM! New imports are necessary and correctly used.

The new imports TransactionEventType, getTransactionEventType, and useTransactionEvents are essential for the added functionality.


74-75: LGTM! New state variables are correctly initialized and used.

The new state variables hidePresenceEvents and setHidePresenceEvents are correctly initialized and used in the code.


84-90: LGTM! New method toggleHidePresenceEvent is correctly implemented and used.

The method toggleHidePresenceEvent is correctly implemented and updates the state as expected.


107-108: LGTM! New method getTransactionEventType is correctly used.

The method getTransactionEventType is correctly used to determine the transaction event type.


Line range hint 134-196:
LGTM! New UI components are correctly implemented and enhance the user experience.

The new button to toggle presence events visibility and adjustments to the slider component are correctly implemented and enhance the user experience.


206-215: LGTM! Adjustments to the slider component are correctly implemented.

The slider component's step value adjustment from 1 to 0 provides finer control over event selection.

@gwbaik9717
Copy link
Contributor Author

Thanks for the reply! I've fixed the bug as you suggested.

@gwbaik9717
Copy link
Contributor Author

@chacha912
I opened a new issue in the yorkie-team.github.io repository regarding the need to update the documentation about the filter function.

If it is okay, I'll assign myself to this issue and proceed with the update. (new Issue)

Copy link
Contributor

@chacha912 chacha912 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Added some nits but overall I love what I'm seeing here :)

  • When we filter out presence events, they won't be applied to the document, which makes the information in the Presence tab inaccurate. In this case, should we set hidePresenceTab to true? Or would it be better to add a note informing users about this limitation? I'd like to hear your thoughts on this approach.

filter-presnce

tools/devtools/src/devtools/tabs/History.tsx Outdated Show resolved Hide resolved
tools/devtools/src/devtools/contexts/YorkieSource.tsx Outdated Show resolved Hide resolved
tools/devtools/src/devtools/tabs/Document.tsx Outdated Show resolved Hide resolved
tools/devtools/src/devtools/tabs/History.tsx Outdated Show resolved Hide resolved
@hackerwins hackerwins removed their request for review July 23, 2024 04:27
@gwbaik9717
Copy link
Contributor Author

gwbaik9717 commented Jul 23, 2024

@chacha912

Regarding the issue of inaccurate Presence tab information when presence events are filtered out,

I have not yet fully understand the root cause of the issue.

Currently, it seems like the Presence tab displays the presences information of the selected transaction event using the following code:

const presences = [doc.getSelfForTest(), ...doc.getOthersForTest()];

And the inaccurate presence tab issue occurs, because doc.getOthersFortTest returns an empty array [].

Screenshot 2024-07-24 at 8 34 35 AM

However, the part I do not get is why it is empty.

As soon as the presence events filter is on, below code will fire.

  useEffect(() => {
    if (selectedEventIndexInfo.index === null) return;

    const doc = new yorkie.Document(currentDocKey);
    for (let i = 0; i <= selectedEventIndexInfo.index; i++) {
      doc.applyTransactionEvent(events[i]);
    }

    setDoc(doc);
    setSelectedEvent(events[selectedEventIndexInfo.index]);
  }, [selectedEventIndexInfo]);

I believe doc.applyTransactionEvent is responsible for setting the event information in the doc,

so I expected it would also set the presences information of filtered out event accordingly.

There must be some parts I'm missing, so could you help me out here?

@chacha912
Copy link
Contributor

@gwbaik9717

Currently, we're building the document based on the point selected in the history slider. When selectedEventIndexInfo changes, we rebuild the document for that specific point and set it using setDoc(doc). We're not storing pre-built documents for the entire history. Instead, we're using a lazy building approach, constructing the document state on-demand as the user interacts with the slider.

useEffect(() => {
    if (selectedEventIndexInfo.index === null) return;

    // Create a new document and apply events up to the selected point 
    // to recreate the document state at that moment.
    const doc = new yorkie.Document(currentDocKey);
    for (let i = 0; i <= selectedEventIndexInfo.index; i++) {
      doc.applyTransactionEvent(events[i]);
    }
  
    setDoc(doc);
    setSelectedEvent(events[selectedEventIndexInfo.index]);
  }, [selectedEventIndexInfo]);

When building the document from events, we use the applyTransactionEvent method. This allows us to apply the information from each event to the document. However, when presence events are filtered out, events like watched, unwatched, and presence-changed are removed from the sequence. As a result, the document doesn't apply information about which Peers watched/unwatched or how their presence changed. This is why doc.getOthersForTest() returns an empty array - the presence information simply isn't there in the rebuilt document.

A potential solution could be to maintain an original, unfiltered array of events. Even when filtering is applied, we could use this original event array to build the document. This would ensure that all necessary information, including presence data, is incorporated into the document state.

I'd be happy to discuss further or explore alternative solutions.

This commit fixes the issue where presence events were filtered out, causing them not to be applied to the document and resulting in inaccurate information in the Presence tab.
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.

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 b65dfbb and 00ed6d4.

Files selected for processing (3)
  • tools/devtools/src/devtools/contexts/YorkieSource.tsx (4 hunks)
  • tools/devtools/src/devtools/panel/index.tsx (5 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tools/devtools/src/devtools/panel/index.tsx
  • tools/devtools/src/devtools/tabs/History.tsx
Additional comments not posted (7)
tools/devtools/src/devtools/contexts/YorkieSource.tsx (7)

17-23: Ensure all necessary imports are present.

The import statements look correct and necessary for the changes made.


36-40: Context definition looks good.

The TransactionEventsContext is correctly defined with the new state variables.


53-55: State variables are correctly initialized.

The state variables for hiding presence events are correctly initialized.


110-116: Provider value is correctly set.

The TransactionEventsContext.Provider value correctly includes the new state variables.


143-146: Enum definition looks good.

The TransactionEventType enum is correctly defined with Document and Presence types.


148-163: Function implementation looks good.

The getTransactionEventType function is correctly implemented to determine the event type.


166-207: Hook implementation looks good.

The useTransactionEvents hook is correctly implemented to include logic for filtering presence events.

This commit addresses the problem of certain icons appearing incorrectly or as squares in some browsers.
This commit adds presence event filter button which helps users understand the role of the button.
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.

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 00ed6d4 and 302225b.

Files selected for processing (2)
  • tools/devtools/src/devtools/tabs/Document.tsx (2 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (2)
  • tools/devtools/src/devtools/tabs/Document.tsx
  • tools/devtools/src/devtools/tabs/History.tsx

@chacha912 chacha912 self-requested a review July 25, 2024 02:30
@gwbaik9717
Copy link
Contributor Author

gwbaik9717 commented Jul 25, 2024

@chacha912

Thank you for the detailed explanation.

I have resolved the issue regarding the inaccurate Presence tab by maintaining both the 'original' and 'filtered' arrays of events. (also applied previous comments in terms of icon issues, and title)

Basically, It works as follows.

When a user clicks an event in the History tab with the presence event filter applied, the original array is referenced to build the document up to that event.

To map the filtered index to the original array index, I created variable named presenceMarkedEvents. This array has the same length as the original array, but with null values replacing the indices of Presence events.

const presenceMarkedEvents = useMemo(() => {
  if (!hidePresenceEvents) {
    return events;
  }

  return events.map((event) => {
    if (getTransactionEventType(event) === TransactionEventType.Presence) {
      return null;
    }
    return event;
  });
}, [events, hidePresenceEvents]);

In theory, instead of using this separate mapping variable, I could have implemented by checking the type of each event (Presence or Document) up to the selected event every time the user clicks.

Just to clarify, it would roughly look like below.

useEffect(() => {
    if (selectedEventIndexInfo.index === null) return;

    const doc = new yorkie.Document(currentDocKey);

    let eventIndex = 0;
    let filteredEventIndex = 0;

    while (
      eventIndex < originalEvents.length &&
      filteredEventIndex <= selectedEventIndexInfo.index
    ) {
      // it is checking the type of every single event until the selected event, and it will repeat every time user selects
      if (
        getTransactionEventType(originalEvents[eventIndex]) ===
        TransactionEventType.Document
      ) {
        filteredEventIndex++;
      }

      doc.applyTransactionEvent(originalEvents[eventIndex]);
      eventIndex++;
    }

    setDoc(doc);
    setSelectedEvent(events[selectedEventIndexInfo.index]);
  }, [selectedEventIndexInfo]);

However, this approach would require recalculating the event types every time an event is clicked, which is less efficient compared to calculating the types once when the events change.

Therefore, I opted for the current method for better performance.

If you have better idea, please let me know.

Copy link
Contributor

@chacha912 chacha912 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 hard work on this. I love all the changes you've made!
However, I had a small concern about needing to maintain presenceMarkedEvents to show the selected document. So, I've made a tiny modification to your changes - would you mind checking if it looks okay? Everything else looks great! :)

tools/devtools/src/devtools/contexts/YorkieSource.tsx Outdated Show resolved Hide resolved
tools/devtools/src/devtools/panel/index.tsx Outdated Show resolved Hide resolved
Make code more readable by adding enhancedEvents (which adds metadata to events)
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.

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 302225b and eb88463.

Files selected for processing (3)
  • tools/devtools/src/devtools/contexts/YorkieSource.tsx (4 hunks)
  • tools/devtools/src/devtools/panel/index.tsx (5 hunks)
  • tools/devtools/src/devtools/tabs/History.tsx (7 hunks)
Files skipped from review as they are similar to previous changes (3)
  • tools/devtools/src/devtools/contexts/YorkieSource.tsx
  • tools/devtools/src/devtools/panel/index.tsx
  • tools/devtools/src/devtools/tabs/History.tsx

Copy link
Contributor

@chacha912 chacha912 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks again @gwbaik9717

@hackerwins hackerwins merged commit 7edae23 into yorkie-team:main Jul 25, 2024
2 checks passed
hackerwins pushed a commit that referenced this pull request Jul 25, 2024
This commit adds a Root-Only Filter in the History tab, allowing users
to focus exclusively on changes to the Root of the Document.
Previously, the History tab logs both content changes and Presence events
(such as cursor movements), which can result in a high volume of events
that may not always be relevant for debugging content changes.
hackerwins pushed a commit that referenced this pull request Jul 25, 2024
This commit adds a Root-Only Filter in the History tab, allowing users
to focus exclusively on changes to the Root of the Document.
Previously, the History tab logs both content changes and Presence events
(such as cursor movements), which can result in a high volume of events
that may not always be relevant for debugging content changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Enhance Devtools UI with Root-only Filter Feature In History
3 participants