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(settings): Reload file instead of the whole app when applying settings. #185

Merged
merged 6 commits into from
Feb 20, 2025

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Feb 17, 2025

Description

  1. Reload file instead of the whole app when applying settings. This is particularly useful for retaining any drag-n-drop'ed files when applying the settings.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  1. Launched debug server and opened the log viewer in a browser.
  2. Drag-n-drop'ed demo file https://yscope.s3.us-east-2.amazonaws.com/sample-logs/yarn-ubuntu-resourcemanager-ip-172-31-17-135.log.1.clp.zst into the editor view. Observed the file was loaded successfully.
  3. Set the cursor at a specific log event (e.g. logEventNum=816).
  4. Opened the settings tab, changed "View: Page size" from 10000 to 1, clicked "Apply" and observed the file was reloaded with only 1 log event in the view, which is Log Event 816.

Summary by CodeRabbit

  • New Features

    • The settings experience now applies changes via a smoother, programmatic refresh—eliminating disruptive full page reloads—and the submit button has been updated to simply read “Apply.”
    • Enhanced navigation now leverages improved content caching for a quicker, more responsive reload experience.
    • A new action for reloading has been introduced, expanding the set of available actions for better state management within the application.
  • Bug Fixes

    • Improved error handling for unexpected values during file reload actions, ensuring a more robust user experience.

Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

This update modifies the page refresh behavior in the settings modal workflow. The SettingsDialog component now accesses the new context from StateContext to replace a full page reload with a programmatic call to loadPageByAction using the RELOAD action. The modal now closes after form submission. In parallel, the state context provider has been enhanced by caching the file source using a new reference and updating the reload logic, while the actions module now defines a new RELOAD action.

Changes

File(s) Summary of Changes
src/components/.../SettingsDialog.tsx Introduced StateContext usage; updated form submission to call loadPageByAction(ACTION_NAME.RELOAD), adjusted dependency array, changed button text to "Apply", and set modal state to closed.
src/contexts/.../StateContextProvider.tsx Added a new fileSrcRef for caching the file source; modified loadPageByAction to validate context references and call loadFile with appropriate parameters when RELOAD is triggered.
src/utils/actions.ts Added the RELOAD value to the ACTION_NAME enum and updated the NavigationActionsMap to include it.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant SD as SettingsDialog
    participant SC as StateContext
    participant LF as loadFile

    U->>SD: Submit settings form
    SD->>SC: Call loadPageByAction(RELOAD)
    alt Valid refs present
        SC->>LF: Invoke loadFile(fileSrc, cursor)
    else
        SC-->>SC: Throw error (missing fileSrcRef or logEventNumRef)
    end
    SD->>SD: Close settings modal
Loading

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d65d338 and b0052ff.

📒 Files selected for processing (2)
  • src/components/Editor/index.tsx (1 hunks)
  • src/components/modals/SettingsModal/SettingsDialog.tsx (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/components/modals/SettingsModal/SettingsDialog.tsx
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/components/Editor/index.tsx
🔇 Additional comments (2)
src/components/Editor/index.tsx (2)

103-118: Well-implemented memory management solution!

The resetCachedPageSize implementation effectively addresses potential out-of-memory issues by temporarily reducing the page size during text updates, with proper error handling and clear documentation.


181-195:

❓ Verification inconclusive

Verify impact on settings display synchronization.

The caching and restoration of page size might be related to the reported issue where the settings dialog doesn't reflect the new page size. Please verify that this implementation doesn't interfere with settings display synchronization.

Run this script to check how the page size value flows through the application:


🏁 Script executed:

#!/bin/bash
# Description: Track page size value flow through the codebase

# Search for page size related state updates and display logic
rg -A 5 "PAGE_SIZE" --type ts --type tsx

# Search for settings form display logic
ast-grep --pattern 'const SettingsDialog = () => {
  $$$
}'

Length of output: 130


Settings Display Synchronization Impact Verification Needed

The integration of resetCachedPageSize (as beforeTextUpdate) and restoreCachedPageSize (as onTextUpdate) in the MonacoInstance appears to follow the intended pattern. However, the reported issue—where the settings dialog continues to display a page size of 10,000 even after it is changed to 1—suggests that the current caching logic might be interfering with the synchronization of the settings display.

At this stage, the internal flow of the "PAGE_SIZE" value and related settings update logic could not be confirmed due to the shell script producing low-quality output (e.g. issues with file type recognition for tsx and no output from the AST-based search).

Please perform a manual verification to ensure that:

  • The updated page size is correctly propagated throughout the application.
  • The settings dialog accurately reflects the new page size after MonacoInstance updates occur.

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@junhaoliao junhaoliao requested a review from Henry8192 February 17, 2025 15:54
Henry8192
Henry8192 previously approved these changes Feb 18, 2025
Copy link
Collaborator

@Henry8192 Henry8192 left a comment

Choose a reason for hiding this comment

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

LGTM. An issue (or a feature request) is found during the test, which I believe we should bring that to another pr:

When the page size is set from 10000 to 1 & saved, the page size in settings is still 10000, even though the actual page size is set to 1. Should we sync up the numbers here to avoid confusion?

@junhaoliao
Copy link
Member Author

LGTM. An issue (or a feature request) is found during the test, which I believe we should bring that to another pr:

When the page size is set from 10000 to 1 & saved, the page size in settings is still 10000, even though the actual page size is set to 1. Should we sync up the numbers here to avoid confusion?

good catch. i was able to reproduce the issue on my end. let me see if i can quickly fix it in this PR.

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

🧹 Nitpick comments (1)
src/contexts/StateContextProvider.tsx (1)

440-451: Consider adding error recovery for reload action.

The current implementation throws an error if fileSrcRef or logEventNumRef is null. Consider handling this gracefully by falling back to default values or showing an error message to the user.

 if (navAction.code === ACTION_NAME.RELOAD) {
-    if (null === fileSrcRef.current || null === logEventNumRef.current) {
-        throw new Error(`Unexpected fileSrc=${JSON.stringify(fileSrcRef.current)
-        }, logEventNum=${logEventNumRef.current} when reloading.`);
-    }
-    loadFile(fileSrcRef.current, {
-        code: CURSOR_CODE.EVENT_NUM,
-        args: {eventNum: logEventNumRef.current},
-    });
+    if (null === fileSrcRef.current) {
+        postPopUp({
+            level: LOG_LEVEL.ERROR,
+            message: "Unable to reload: No file is currently loaded.",
+            timeoutMillis: DEFAULT_AUTO_DISMISS_TIMEOUT_MILLIS,
+            title: "Reload failed",
+        });
+        return;
+    }
+    loadFile(fileSrcRef.current, {
+        code: CURSOR_CODE.EVENT_NUM,
+        args: {eventNum: logEventNumRef.current ?? 1},
+    });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 773629c and d65d338.

📒 Files selected for processing (3)
  • src/components/modals/SettingsModal/SettingsDialog.tsx (4 hunks)
  • src/contexts/StateContextProvider.tsx (4 hunks)
  • src/utils/actions.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • src/contexts/StateContextProvider.tsx
  • src/utils/actions.ts
  • src/components/modals/SettingsModal/SettingsDialog.tsx
🔇 Additional comments (3)
src/utils/actions.ts (1)

14-14: LGTM!

The new RELOAD action follows the existing pattern and naming conventions.

Also applies to: 73-73

src/components/modals/SettingsModal/SettingsDialog.tsx (1)

21-21: LGTM!

The changes improve the user experience by:

  • Preserving dragged files during settings updates
  • Automatically closing the modal after applying settings
  • Using more accurate button text

Also applies to: 101-101, 131-132, 179-179

src/contexts/StateContextProvider.tsx (1)

271-271: LGTM!

The file source caching implementation is clean and follows React best practices by using useRef.

Also applies to: 410-412

@junhaoliao
Copy link
Member Author

LGTM. An issue (or a feature request) is found during the test, which I believe we should bring that to another pr:
When the page size is set from 10000 to 1 & saved, the page size in settings is still 10000, even though the actual page size is set to 1. Should we sync up the numbers here to avoid confusion?

good catch. i was able to reproduce the issue on my end. let me see if i can quickly fix it in this PR.

the issue should have now been fixed. could you check again?

Copy link
Collaborator

@Henry8192 Henry8192 left a comment

Choose a reason for hiding this comment

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

Yup. That issue is fixed. You got a green light.

@junhaoliao junhaoliao merged commit ec35a06 into y-scope:main Feb 20, 2025
4 checks passed
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.

2 participants