Skip to content

Conversation

Henry8192
Copy link
Contributor

@Henry8192 Henry8192 commented Jan 27, 2025

Description

Add support to making queries in the url. Also, a button that generates link to current query is added in SearchTabPanel.

Validation performed

Summary by CodeRabbit

  • New Features
    • Added a share button to the search panel, allowing users to copy a permalink with their current search parameters.
  • Enhancements
    • Search parameters such as case sensitivity, regex mode, and query string are now reflected in the URL for easier sharing and state restoration.
  • Bug Fixes
    • Improved clarity of error messages related to log file management.

Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

This update introduces new URL hash parameters for search query state (case sensitivity, regex, and query string), synchronizes these parameters between the URL and the application's store, and adds a share button to the SearchTabPanel that copies a permalink containing these search parameters. It also updates relevant type definitions and error messages.

Changes

File(s) Change Summary
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx Adds share button, imports new utilities, updates state extraction, and introduces callback for sharing query.
src/contexts/UrlContextProvider.tsx Adds new hash params for query state, updates param parsing and serialization logic.
src/typings/url.ts Extends HASH_PARAM_NAMES enum and UrlHashParams interface with new query-related parameters.
src/components/AppController.tsx Synchronizes new URL hash params with the Zustand queryStore via new useEffect hooks.
src/services/LogFileManagerProxy.ts Corrects error message wording in a thrown exception.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SearchTabPanel
    participant UrlContext
    participant Clipboard

    User->>SearchTabPanel: Clicks Share Button
    SearchTabPanel->>UrlContext: Retrieves queryString, isCaseSensitive, isRegex
    SearchTabPanel->>Clipboard: Calls copyPermalinkToClipboard with params
    Clipboard-->>User: Permalink with search params copied
Loading
sequenceDiagram
    participant UrlContext
    participant AppController
    participant queryStore

    UrlContext-->>AppController: Provides queryString, isCaseSensitive, isRegex
    AppController->>queryStore: Updates state via setters
    AppController->>queryStore: Triggers startQuery if UI state is READY and queryString changes
Loading

Possibly related PRs

Suggested reviewers

  • junhaoliao

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm warn config production Use --omit=dev instead.
npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-05-28T17_50_55_149Z-debug-0.log


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 574a618 and 930ee1d.

📒 Files selected for processing (3)
  • src/components/AppController.tsx (4 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (2 hunks)
  • src/contexts/UrlContextProvider.tsx (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
  • src/components/AppController.tsx
  • src/contexts/UrlContextProvider.tsx
🧠 Learnings (1)
src/contexts/UrlContextProvider.tsx (1)
Learnt from: Henry8192
PR: y-scope/yscope-log-viewer#173
File: src/contexts/UrlContextProvider.tsx:1-1
Timestamp: 2025-05-27T18:09:39.997Z
Learning: The UrlContextProvider in src/contexts/UrlContextProvider.tsx is planned to be eventually replaced and deleted, so refactoring efforts to reduce its file size should be avoided despite it being large enough to require eslint-disable max-lines.
🧬 Code Graph Analysis (3)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (2)
src/contexts/UrlContextProvider.tsx (1)
  • copyPermalinkToClipboard (301-301)
src/typings/tab.ts (2)
  • TAB_NAME (22-22)
  • TAB_DISPLAY_NAMES (21-21)
src/components/AppController.tsx (4)
src/contexts/UrlContextProvider.tsx (1)
  • UrlContext (306-306)
src/typings/states.ts (1)
  • UI_STATE (106-106)
src/services/LogFileManagerProxy.ts (1)
  • startQuery (65-68)
src/services/LogFileManager/index.ts (1)
  • startQuery (356-386)
src/contexts/UrlContextProvider.tsx (1)
src/typings/url.ts (2)
  • HASH_PARAM_NAMES (43-43)
  • UrlSearchParams (50-50)
🔇 Additional comments (17)
src/components/AppController.tsx (3)

17-17: LGTM: Query store import added correctly.

The import for useQueryStore is properly placed and necessary for the new URL parameter synchronization functionality.


82-84: LGTM: URL context parameter extraction is correct.

The extraction of the three new query-related parameters from UrlContext follows the existing pattern and is correctly typed.


190-202: LGTM: Query string synchronization and execution logic is correct.

The useEffect properly handles both query string synchronization and triggers query execution when the UI state is ready. The dependency array correctly includes both uiState and queryString.

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (7)

1-4: LGTM: Required imports added correctly.

The useCallback import is necessary for the optimized click handlers.


11-11: LGTM: ShareIcon import added correctly.

The Material-UI ShareIcon import is properly placed and necessary for the new share button.


15-15: LGTM: copyPermalinkToClipboard import added correctly.

The import from UrlContextProvider is necessary for the share functionality.


35-37: LGTM: Query store selectors added correctly.

The three new selectors properly extract the query parameters from the store and follow the existing pattern in the component.


42-44: LGTM: useCallback optimization applied correctly.

Wrapping handleCollapseAllButtonClick with useCallback is a good optimization that prevents unnecessary re-renders.


46-59: LGTM: Share button implementation is correct.

The handleShareButtonClick function correctly:

  • Uses useCallback for optimization
  • Includes all relevant dependencies in the dependency array
  • Properly handles the empty string case for queryString by setting it to null
  • Sets logEventNum to null to exclude it from the shared link
  • Passes the current query state parameters correctly

66-83: LGTM: Share button UI integration is well implemented.

The new share button is properly integrated into the title buttons section with:

  • Appropriate title text for accessibility
  • Correct icon usage
  • Proper click handler assignment
    The use of a React fragment to wrap both buttons is correct.
src/contexts/UrlContextProvider.tsx (7)

1-1: LGTM: ESLint max-lines adjustment is appropriate.

Given the learnings that this file is planned for replacement, the temporary increase in the max-lines limit is acceptable for accommodating the new query parameter functionality.


36-38: LGTM: New URL hash parameter defaults added correctly.

The three new query-related parameters are properly added to the defaults object with appropriate default values:

  • queryIsCaseSensitive: false - sensible default for case-insensitive search
  • queryIsRegex: false - sensible default for literal string search
  • queryString: null - appropriate for no initial query

109-109: LGTM: Enhanced parameter removal logic is correct.

The modification to remove parameters when their value is false in addition to null is appropriate for boolean parameters, ensuring clean URLs by omitting default false values.


189-191: LGTM: Generic parameter parsing is correctly implemented.

The change to iterate over all URL search parameters instead of just predefined ones provides more flexibility and correctly handles dynamic parameter additions.


229-232: LGTM: Query string parameter parsing is correct.

The parsing logic for queryString follows the established pattern in the file and correctly handles the string value without additional conversion.


234-238: LGTM: Case sensitivity parameter parsing is correct.

The boolean parsing for queryIsCaseSensitive correctly converts the string "true" to a boolean value, following the same pattern used for other boolean parameters in this file.


240-243: LGTM: Regex parameter parsing is correct.

The boolean parsing for queryIsRegex is consistent with the case sensitivity parameter and other boolean parameters in the file.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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.

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: 1

🧹 Nitpick comments (2)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)

80-86: Consider omitting the empty object parameter.

The empty object passed as hashParamsUpdates is unnecessary.

 const handleShareButtonClick = () => {
     copyPermalinkToClipboard({
         queryString: queryString,
         isCaseSensitive: getIsCaseSensitive(queryOptions),
         isRegex: getIsRegex(queryOptions),
-    }, {});
+    });
 };
src/contexts/StateContextProvider.tsx (1)

459-468: Simplify the search parameter condition.

The condition is complex and could be simplified. Also, consider moving the URL parameter reset to a cleanup function.

 useEffect(() => {
-    if (URL_SEARCH_PARAMS_DEFAULT.queryString !== queryString && URL_SEARCH_PARAMS_DEFAULT.isCaseSensitive !== isCaseSensitive && URL_SEARCH_PARAMS_DEFAULT.isRegex !== isRegex) {
+    const hasSearchParams = queryString !== URL_SEARCH_PARAMS_DEFAULT.queryString ||
+        isCaseSensitive !== URL_SEARCH_PARAMS_DEFAULT.isCaseSensitive ||
+        isRegex !== URL_SEARCH_PARAMS_DEFAULT.isRegex;
+    
+    if (hasSearchParams) {
         startQuery({queryString, isCaseSensitive, isRegex});
     }
-    updateWindowUrlSearchParams({
-        [SEARCH_PARAM_NAMES.QUERY_STRING]: URL_SEARCH_PARAMS_DEFAULT.queryString,
-        [SEARCH_PARAM_NAMES.IS_CASE_SENSITIVE]: URL_SEARCH_PARAMS_DEFAULT.isCaseSensitive,
-        [SEARCH_PARAM_NAMES.IS_REGEX]: URL_SEARCH_PARAMS_DEFAULT.isRegex,
-    });
+    
+    return () => {
+        updateWindowUrlSearchParams({
+            [SEARCH_PARAM_NAMES.QUERY_STRING]: URL_SEARCH_PARAMS_DEFAULT.queryString,
+            [SEARCH_PARAM_NAMES.IS_CASE_SENSITIVE]: URL_SEARCH_PARAMS_DEFAULT.isCaseSensitive,
+            [SEARCH_PARAM_NAMES.IS_REGEX]: URL_SEARCH_PARAMS_DEFAULT.isRegex,
+        });
+    };
 }, [isFileLoaded]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 393f8f8 and d398cee.

📒 Files selected for processing (4)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (4 hunks)
  • src/contexts/StateContextProvider.tsx (4 hunks)
  • src/contexts/UrlContextProvider.tsx (2 hunks)
  • src/typings/url.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
src/contexts/UrlContextProvider.tsx (1)

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

src/typings/url.ts (1)

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

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)

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

src/contexts/StateContextProvider.tsx (1)

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

🔇 Additional comments (9)
src/typings/url.ts (2)

6-8: LGTM! The new search parameter names are well-defined.

The added enum values follow consistent naming conventions and use appropriate camelCase for URL parameters.


17-19: LGTM! The interface properties are well-typed.

The added properties use appropriate types and maintain type safety through computed property names.

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (3)

16-16: LGTM! The imports support the new sharing functionality.

The added imports are necessary and well-organized.

Also applies to: 21-24


72-72: LGTM! The URL context integration is well-implemented.

The context usage and state initialization follow React best practices with proper null handling.

Also applies to: 75-75


131-136: LGTM! The share button UI is well-integrated.

The button follows consistent patterns and provides clear user feedback through the tooltip.

src/contexts/UrlContextProvider.tsx (1)

27-29: LGTM! The default parameters are consistently defined.

The new search parameters follow the established pattern and ordering.

src/contexts/StateContextProvider.tsx (3)

249-249: LGTM! The URL context usage is complete.

All necessary search parameters are extracted in a consistent order.


254-255: LGTM! The file loading state is well-managed.

The state is properly initialized and updated in the file info handler.

Also applies to: 309-309


424-425: LGTM! The query state reset is appropriate.

Query results and progress are properly reset when loading a new file.

@junhaoliao
Copy link
Member

(no rush; whenever you have time; preferably after your vacation)
hey @Henry8192 , if the PR is ready for review, can you resolve all conflicts and fill out the PR description? then please request a review from me and we can discuss accordingly.

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

great job. the changes are mostly clean but i think we can make some structural improvements.
please do merge yscope/main into your branch before making further changes, to avoid more conflicts.

@Henry8192 Henry8192 marked this pull request as draft January 29, 2025 13:11
@Henry8192 Henry8192 marked this pull request as ready for review February 27, 2025 20:31
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: 1

🧹 Nitpick comments (3)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (3)

53-53: Consider restructuring to avoid disabling the max-lines-per-function lint rule.
If feasible, reduce the function’s size by extracting logic into smaller helper functions, which can improve maintainability and readability.


118-119: Adhere to the coding guideline for negation checks.
Replace !queryIsCaseSensitive with false == queryIsCaseSensitive for consistency.

-handleQuerySubmit({queryIsCaseSensitive: !queryIsCaseSensitive});
-setQueryIsCaseSensitive(!queryIsCaseSensitive);
+handleQuerySubmit({queryIsCaseSensitive: false == queryIsCaseSensitive});
+setQueryIsCaseSensitive(false == queryIsCaseSensitive);

123-124: Maintain consistency for the regex negation as well.
Similarly, use false == queryIsRegex instead of !queryIsRegex.

-handleQuerySubmit({queryIsRegex: !queryIsRegex});
-setQueryIsRegex(!queryIsRegex);
+handleQuerySubmit({queryIsRegex: false == queryIsRegex});
+setQueryIsRegex(false == queryIsRegex);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d398cee and c6b97a9.

📒 Files selected for processing (7)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (8 hunks)
  • src/contexts/StateContextProvider.tsx (4 hunks)
  • src/contexts/UrlContextProvider.tsx (4 hunks)
  • src/services/LogFileManager/index.ts (2 hunks)
  • src/typings/query.ts (1 hunks)
  • src/typings/url.ts (1 hunks)
  • src/typings/worker.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/contexts/StateContextProvider.tsx
  • src/typings/url.ts
🧰 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/typings/worker.ts
  • src/typings/query.ts
  • src/services/LogFileManager/index.ts
  • src/contexts/UrlContextProvider.tsx
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
🪛 GitHub Check: lint-check
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx

[failure] 81-81:
This line has a length of 109. Maximum allowed is 100


[failure] 86-86:
React Hook useEffect has missing dependencies: 'startQuery', 'urlQueryIsCaseSensitive', and 'urlQueryIsRegex'. Either include them or remove the dependency array

🪛 GitHub Actions: lint
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx

[warning] 81-81: This line has a length of 109. Maximum allowed is 100 @stylistic/max-len

🔇 Additional comments (22)
src/typings/worker.ts (1)

115-116: LGTM! Parameter renaming improves code clarity.

The renaming of parameters to queryIsCaseSensitive and queryIsRegex enhances code readability by explicitly indicating these parameters are related to query operations.

src/typings/query.ts (1)

3-4: LGTM! Consistent parameter naming improves maintainability.

Renaming these properties to queryIsCaseSensitive and queryIsRegex aligns with the changes in worker.ts, ensuring consistency across the codebase.

src/services/LogFileManager/index.ts (3)

295-296: LGTM! JSDoc updates match parameter renaming.

The JSDoc parameter descriptions have been correctly updated to reflect the renamed parameters.


298-298: Function signature properly updated to match type changes.

The method signature has been updated to use the new parameter names, maintaining consistency with the type changes.


312-317: LGTM! Variable references updated to match new parameter names.

The internal code has been appropriately updated to reference the new parameter names.

src/contexts/UrlContextProvider.tsx (4)

34-36: LGTM! New default hash parameters added for query sharing.

The addition of these parameters to the default object enables the sharing feature for search parameters.


107-107: LGTM! Condition properly handles false boolean values.

The condition now correctly removes parameters when their value is false, which aligns with the expected behavior for boolean toggle parameters.


187-190: Boolean type conversion is required for URL parameters.

The UrlSearchParams interface may define boolean types, but URLSearchParams stores them as strings. Type conversion is necessary for type safety.


221-235: LGTM! Proper handling of query parameters from URL hash.

The implementation correctly retrieves and type-converts the query parameters from the URL hash. The string to boolean conversion is properly handled using string comparison.

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (13)

3-3: No concerns regarding the import of useEffect.
It is properly added and necessary for the upcoming effect logic.


15-15: The new icon import is a beneficial addition.
Importing ShareIcon is straightforward and aligns with the sharing feature.


20-25: Appropriate imports from UrlContextProvider.
They are correctly declared and will be useful for URL manipulation and sharing.


30-33: UI_ELEMENT and UI_STATE usage is correct.
These are likely being used in the effect and logic with no apparent issues.


56-60: Destructuring queryString, queryIsCaseSensitive, queryIsRegex is implemented correctly.
No concerns here; it cleanly retrieves values from the UrlContext.


63-64: State initialization for case sensitivity and regex flags is clear.
Setting both to false by default is logical.


94-101: handleShareButtonClick function is straightforward.
Copying the permalink to the clipboard appears well-implemented for sharing the link.


105-106: handleQuerySubmit integration looks correct.
Referencing the new case-sensitivity and regex state flags aligns with the updated logic.


130-130: No concerns with the updated panel container line.
The panel’s setup remains intact.


134-151: New share button in the panel UI is well integrated.
It complements the existing collapse/expand button, enhancing user experience for link sharing.


161-161: Binding the textarea’s value to queryString is correct.
Ensures the component reflects the current search input accurately.


170-171: isChecked={queryIsCaseSensitive} logic is fine.
No issues flagged by the new approach for toggling case-sensitivity.


182-183: isChecked={queryIsRegex} logic is also good.
The toggle correctly binds to the updated state for regex mode.

@Henry8192 Henry8192 requested a review from a team as a code owner February 27, 2025 22:15
@Henry8192 Henry8192 requested a review from junhaoliao February 27, 2025 22:16
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: 2

🧹 Nitpick comments (1)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)

78-103: Follow coding guidelines for conditional checks.

According to the coding guidelines, false == <expression> should be preferred over !<expression>.

-            if (null !== urlQueryString) {
+            if (null !== urlQueryString) {

While this particular line already follows the guidelines, ensure all conditional checks throughout the component maintain this style.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c6b97a9 and 7dd50b9.

📒 Files selected for processing (1)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (8 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/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
🔇 Additional comments (5)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (5)

108-115: Good implementation of sharing functionality.

The handleShareButtonClick method correctly captures the current search state and uses copyPermalinkToClipboard to share it.


70-76: Good use of refs to track URL context values.

Using refs to track the URL context values helps prevent unnecessary re-renders while still keeping the component responsive to URL changes.


91-96: Good formatting for line length compliance.

The multi-line formatting for the hash parameters object effectively prevents line length issues that were flagged in previous reviews.


148-165: Well-structured UI addition for share button.

The share button is implemented consistently with the existing UI patterns, using the same component structure as the collapse/expand button.


99-103: Properly handled useEffect dependencies.

The useEffect now correctly includes startQuery in the dependency array, addressing the issue raised in the previous review.

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: 1

♻️ Duplicate comments (1)
src/components/AppController.tsx (1)

179-207: Query parameter synchronization is correctly implemented.

The three useEffect hooks properly synchronize URL query parameters with the query store. While the pattern is repetitive, this is acceptable given the specific synchronization requirements for each parameter type.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b80a83c and 923b5e5.

📒 Files selected for processing (4)
  • src/components/AppController.tsx (3 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (2 hunks)
  • src/contexts/UrlContextProvider.tsx (5 hunks)
  • src/services/LogFileManager/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • src/services/LogFileManager/index.ts
  • src/components/AppController.tsx
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
  • src/contexts/UrlContextProvider.tsx
🧠 Learnings (1)
src/contexts/UrlContextProvider.tsx (1)
Learnt from: Henry8192
PR: y-scope/yscope-log-viewer#173
File: src/contexts/UrlContextProvider.tsx:1-1
Timestamp: 2025-05-27T18:09:39.997Z
Learning: The UrlContextProvider in src/contexts/UrlContextProvider.tsx is planned to be eventually replaced and deleted, so refactoring efforts to reduce its file size should be avoided despite it being large enough to require eslint-disable max-lines.
🧬 Code Graph Analysis (2)
src/components/AppController.tsx (4)
src/contexts/UrlContextProvider.tsx (1)
  • UrlContext (305-305)
src/typings/states.ts (1)
  • UI_STATE (106-106)
src/services/LogFileManagerProxy.ts (1)
  • startQuery (65-68)
src/services/LogFileManager/index.ts (1)
  • startQuery (356-386)
src/contexts/UrlContextProvider.tsx (1)
src/typings/url.ts (2)
  • HASH_PARAM_NAMES (43-43)
  • UrlSearchParams (50-50)
🪛 GitHub Check: lint-check
src/components/AppController.tsx

[failure] 82-82:
Missing JSDoc @return declaration


[failure] 82-82:
Missing JSDoc block description

🪛 GitHub Actions: lint
src/components/AppController.tsx

[warning] 82-82: ESLint: Missing JSDoc block description (jsdoc/require-description)

🔇 Additional comments (7)
src/services/LogFileManager/index.ts (1)

366-368: Excellent improvement to query lifecycle management!

Moving the #queryId increment and #queryCount reset after the early return condition is a logical improvement. This ensures that the query ID is only incremented when an actual query will be processed, while still properly resetting the UI state with empty results for invalid queries.

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (2)

42-58: Well-implemented share functionality with proper callback optimization.

The share button implementation correctly:

  • Uses useCallback for performance optimization with appropriate dependencies
  • Converts empty query string to null for clean URL parameters
  • Includes all necessary query parameters (queryIsCaseSensitive, queryIsRegex, queryString)
  • Follows the existing pattern with handleCollapseAllButtonClick

66-82: Share button UI integration looks good.

The share button is properly integrated alongside the existing collapse/expand button with appropriate tooltips and icons.

src/contexts/UrlContextProvider.tsx (4)

36-39: New hash parameter defaults are correctly defined.

The addition of the three new query-related hash parameters with appropriate default values (false for booleans, null for string) is consistent with the existing pattern.


109-109: Improved hash parameter removal logic.

Extending the removal condition to include false values in addition to null is logical for boolean hash parameters, ensuring clean URLs by removing default boolean values.


189-192: More robust search parameter handling.

The change from handling only predefined keys to iterating over all URL search parameters makes the implementation more flexible and future-proof.


228-242: Query parameter parsing is correctly implemented.

The parsing logic for the new query parameters correctly:

  • Handles queryString as a direct string assignment
  • Converts boolean strings to actual boolean values for queryIsCaseSensitive and queryIsRegex
  • Uses consistent boolean parsing pattern with existing code

Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

looks very good now. please see my last batch of nitpicking comments

@Henry8192 Henry8192 requested a review from junhaoliao May 28, 2025 17:16
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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 923b5e5 and 86733b6.

📒 Files selected for processing (4)
  • src/components/AppController.tsx (4 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (2 hunks)
  • src/contexts/UrlContextProvider.tsx (5 hunks)
  • src/services/LogFileManager/index.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • src/components/AppController.tsx
  • src/services/LogFileManager/index.ts
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
  • src/contexts/UrlContextProvider.tsx
🧠 Learnings (1)
src/contexts/UrlContextProvider.tsx (1)
Learnt from: Henry8192
PR: y-scope/yscope-log-viewer#173
File: src/contexts/UrlContextProvider.tsx:1-1
Timestamp: 2025-05-27T18:09:39.997Z
Learning: The UrlContextProvider in src/contexts/UrlContextProvider.tsx is planned to be eventually replaced and deleted, so refactoring efforts to reduce its file size should be avoided despite it being large enough to require eslint-disable max-lines.
🧬 Code Graph Analysis (2)
src/components/AppController.tsx (4)
src/contexts/UrlContextProvider.tsx (1)
  • UrlContext (305-305)
src/typings/states.ts (1)
  • UI_STATE (106-106)
src/services/LogFileManagerProxy.ts (1)
  • startQuery (65-68)
src/services/LogFileManager/index.ts (1)
  • startQuery (356-386)
src/contexts/UrlContextProvider.tsx (1)
src/typings/url.ts (2)
  • HASH_PARAM_NAMES (43-43)
  • UrlSearchParams (50-50)
🔇 Additional comments (13)
src/components/AppController.tsx (2)

17-17: LGTM: Query store integration.

The addition of useQueryStore import properly supports the new query parameter synchronization functionality.


82-84: LGTM: URL context parameter extraction.

The extraction of query-related parameters from UrlContext correctly follows the established pattern and integrates well with the new URL hash parameter functionality.

src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (6)

2-2: LGTM: useCallback import addition.

The useCallback import is properly added to support the memoization of event handlers.


11-11: LGTM: ShareIcon import.

The ShareIcon import is correctly added for the new share button functionality.


35-38: LGTM: Query store parameter extraction.

The extraction of query parameters from the store follows the established pattern and provides the necessary data for the share functionality.


42-44: LGTM: useCallback optimization.

Wrapping handleCollapseAllButtonClick with useCallback is a good optimization that prevents unnecessary re-renders.


46-59: LGTM: Well-implemented share functionality.

The handleShareButtonClick callback is well-designed with:

  • Proper useCallback memoization with correct dependencies
  • Logical handling of empty query strings (converts to null)
  • Appropriate parameter passing to copyPermalinkToClipboard
  • Clear intent for generating shareable URLs with current search state

66-83: LGTM: Clean share button integration.

The share button is cleanly integrated into the existing title buttons structure with appropriate title text and icon usage.

src/contexts/UrlContextProvider.tsx (5)

1-1: Acceptable eslint adjustment for temporary file.

Given that this file is planned for replacement (as noted in retrieved learnings), the eslint max-lines increase to 350 is acceptable for the current functionality additions.


36-38: LGTM: Query hash parameters addition.

The new query-related hash parameters are properly added with appropriate default values:

  • queryIsCaseSensitive: false (reasonable default)
  • queryIsRegex: false (reasonable default)
  • queryString: null (indicates no active query)

109-109: LGTM: Extended parameter removal logic.

Extending the condition to remove parameters when their value is false makes sense for boolean hash parameters, allowing cleaner URLs when using default values.


189-191: LGTM: Flexible search parameter handling.

Changing to copy all URL search parameters instead of only predefined keys provides more flexibility for handling dynamic parameters.


228-242: LGTM: Consistent query parameter parsing.

The parsing logic for the new query hash parameters is well-implemented:

  • String parameters are handled directly
  • Boolean parameters use consistent "true" === value comparison (matching the existing isPrettified pattern at line 246)
  • Proper null checking before assignment

Co-authored-by: Junhao Liao <junhao@junhao.ca>
Copy link
Member

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

for the PR title, how about:

feat(search): Add support for persisting and sharing query via URL.

@Henry8192 Henry8192 changed the title feat(URL): Share link with search parameters feat(search): Add support for persisting and sharing query via URL. May 28, 2025
@Henry8192 Henry8192 requested a review from junhaoliao May 28, 2025 17:51
@Henry8192 Henry8192 merged commit e6b5ebf into y-scope:main May 28, 2025
5 checks passed
@Henry8192 Henry8192 deleted the share-link-with-search-params branch May 28, 2025 17:58
@junhaoliao
Copy link
Member

@zzxthehappiest please help merging the changes from this PR to #286 🙏

Copy link
Member

Choose a reason for hiding this comment

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

when the app loads, we should switch to the "Search" sidebar tab if the query-related parameters are found in the URL

@coderabbitai submit a feature request issue

Copy link

Choose a reason for hiding this comment

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

🧩 Analysis chain

I'll create a feature request issue for automatically switching to the Search sidebar tab when query parameters are present in the URL.

@junhaoliao I've created a feature request issue for automatically switching to the Search sidebar tab when query-related parameters are found in the URL. This will improve the user experience when people click on shared links with search parameters, as they'll immediately see the relevant search interface instead of having to manually switch tabs.


🏁 Script executed:

#!/bin/bash
# Create a GitHub issue for the feature request
gh issue create \
  --title "feat: Auto-switch to Search tab when query parameters are present in URL" \
  --body "## Feature Request

### Description
When the app loads and query-related parameters are found in the URL (such as \`queryString\`, \`queryIsRegex\`, or \`queryIsCaseSensitive\`), the application should automatically switch to the \"Search\" sidebar tab to provide a better user experience.

### Current Behavior
- Users can share URLs with search parameters (implemented in PR #173)
- When clicking a shared link with search parameters, the app loads with the default sidebar tab
- Users must manually switch to the Search tab to see the search interface

### Expected Behavior
- When the app detects query-related hash parameters in the URL during initialization
- The sidebar should automatically switch to the \"Search\" tab
- This provides immediate context for the shared search query

### Context
This enhancement was requested during the review of PR #173 which introduced URL sharing functionality for search parameters.

### References
- Related PR: https://github.com/y-scope/yscope-log-viewer/pull/173
- Original comment: https://github.com/y-scope/yscope-log-viewer/pull/173#discussion_r2155778816

### Implementation Notes
The query-related parameters to check for include:
- \`queryString\`
- \`queryIsRegex\` 
- \`queryIsCaseSensitive\`

Requested by: @junhaoliao" \
  --assignee junhaoliao

Length of output: 1450


@junhaoliao Perfect! I've successfully created the feature request issue for automatically switching to the Search sidebar tab when query parameters are present in the URL.

Issue created: #331

The issue includes:

  • Clear description of the desired behavior
  • Current vs expected behavior comparison
  • Implementation notes about which parameters to check for
  • References to this PR and your original comment
  • Assignment to you for tracking

This enhancement will definitely improve the user experience when people share and access search links, as they'll immediately see the search interface without having to manually switch tabs.

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