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

fix(query): Restart log queries when case-sensitivity or regex button is toggled. #130

Merged
merged 12 commits into from
Dec 9, 2024

Conversation

Henry8192
Copy link
Collaborator

@Henry8192 Henry8192 commented Nov 25, 2024

Description

Fixes #126.
Also updates package-locks.json for vulnerable packages.

Validation performed

Search "Abc" without enabling any of the query options. Enable "caseSensitive" button, that restarts the search.

Summary by CodeRabbit

  • New Features

    • Enhanced query submission handling with new options for case sensitivity and regular expressions.
    • Introduced a structured interface for query arguments to improve clarity and organization.
    • Added constants to represent minimum and maximum values for query progress.
  • Bug Fixes

    • Updated the query handling logic to ensure submissions reflect the latest query options and string.
  • Documentation

    • Added new types and interfaces to support the updated query handling functionality.

Copy link

coderabbitai bot commented Nov 25, 2024

Warning

Rate limit exceeded

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

⌛ How to resolve this issue?

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

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

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 05a3219 and db5e700.

📒 Files selected for processing (1)
  • src/typings/query.ts (1 hunks)

Walkthrough

The changes in the SearchTabPanel component enhance the handling of query submissions by introducing new utility functions and modifying existing functions to improve modularity and clarity. New functions getIsCaseSensitive, getIsRegex, and handleQuerySubmit are added, while the handleQueryInputChange and handleQueryOptionsChange functions are updated to ensure that the query submission reflects the latest state of the query string and options. Additionally, the startQuery method in the StateContextType interface is updated to accept a single QueryArgs object.

Changes

File Path Change Summary
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx Added functions getIsCaseSensitive, getIsRegex, and handleQuerySubmit. Updated handleQueryInputChange and handleQueryOptionsChange for improved query submission handling. Introduced state variable queryString.
src/contexts/StateContextProvider.tsx Updated startQuery method signature to accept a single QueryArgs parameter instead of multiple parameters.
src/typings/worker.ts Added new interface QueryArgs and updated WorkerReqMap to include START_QUERY with the new structure.
src/services/LogFileManager/index.ts Updated startQuery method signature to accept a single queryArgs parameter. Enhanced error handling in startQuery.
src/services/MainWorker.ts Simplified argument handling in onmessage event for START_QUERY case by removing explicit type checks.
src/typings/query.ts Introduced new constants and interfaces for query handling, including QueryArgs, QueryResults, and progress constants.
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx Updated import statement for QueryResultsType to reflect a change in the source module.

Assessment against linked issues

Objective Addressed Explanation
Log queries are restarted when "isCaseSensitive" / "isRegex" button is toggled. (#126) The changes do not ensure that queries are restarted when toggling the options as required.

Possibly related PRs

Suggested reviewers

  • junhaoliao

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. (Experiment)
  • @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.

@Henry8192 Henry8192 requested a review from junhaoliao November 25, 2024 20:12
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

🧹 Outside diff range and nitpick comments (1)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)

61-65: Consider enhancing the query string validation

While the implementation successfully fixes the option toggling issue, consider these improvements:

  1. Make the empty check more explicit
  2. Add string trimming to handle whitespace-only queries
-        if ("" !== queryStringRef.current) {
+        const trimmedQuery = queryStringRef.current.trim();
+        if (trimmedQuery.length > 0) {
             const isCaseSensitive = newOptions.includes(QUERY_OPTION.IS_CASE_SENSITIVE);
             const isRegex = newOptions.includes(QUERY_OPTION.IS_REGEX);
-            startQuery(queryStringRef.current, isRegex, isCaseSensitive);
+            startQuery(trimmedQuery, isRegex, isCaseSensitive);
         }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d07c1b7 and ed2d79a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (3 hunks)
🔇 Additional comments (3)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (3)

48-48: Good addition of queryStringRef!

The useRef hook is a suitable choice for maintaining the current query string value between renders, which is essential for the fix.


Line range hint 50-55: Effective query input handling implementation!

The function properly updates queryStringRef and maintains the existing search functionality while supporting the fix for option toggling.


Line range hint 48-65: Verify the fix resolves the original issue

The implementation appears to correctly address the core issue where queries weren't restarting when options were toggled. Let's verify this by checking for any similar patterns in the codebase that might need the same fix.

✅ Verification successful

Implementation is correct and unique to the search functionality

The implementation properly addresses the issue of restarting queries when options change. After examining the codebase, I found that:

  • The only other ToggleButtonGroup usage is in ThemeSwitchToggle.tsx, which has a different purpose (theme switching) and doesn't require query persistence
  • The search functionality implementation is unique to the SearchTabPanel component and doesn't have similar patterns elsewhere that would need the same fix
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar toggle button implementations that might need the same fix
ast-grep --pattern 'ToggleButtonGroup {
  $$$
  onChange={$_}
  $$$
}'

Length of output: 72


Script:

#!/bin/bash
# Search for similar patterns using ripgrep to find ToggleButtonGroup usage
rg -l "ToggleButtonGroup" --type tsx

# Then search for onChange handlers in those files
rg "onChange.*=.*=>" --type tsx -A 5

Length of output: 131


Script:

#!/bin/bash
# Search for ToggleButtonGroup usage in all files
rg "ToggleButtonGroup"

# Search for onChange handlers in all files
rg "onChange.*=.*=>" -A 5

Length of output: 1181

package-lock.json Outdated Show resolved Hide resolved
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.

Let's treat this task as a refactoring task as I believe with some interface redesigns, the reported issue could have been avoided.

src/typings/worker.ts -> src/typings/query.ts

  1. Let move all query-related types into a new file src/typings/query.ts.
  2. Let's extract the type of the args of START_QUERY into an interface named QueryArgs and also move that into query.ts.
  3. As we previously discussed, QUERY_PROGRESS_INIT shall be named QUERY_PROGRESS_VALUE_MIN and QUERY_PROGRESS_DONE shall be named QUERY_PROGRESS_VALUE_MAX if you agree.

Change the positional arguments signatures into object parameter signatures

That will include

  1. src/services/LogFileManager/index.ts: startQuery
  2. src/services/MainWorker.ts: LOG_FILE_MANAGER.startQuery(args);.
    1. Also I don't think the arg type checks are necessary?
  3. src/contexts/StateContextProvider.tsx: startQuery

Misc

You might need to fix the type QueryResultsType import in src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx

@junhaoliao junhaoliao assigned junhaoliao and Henry8192 and unassigned junhaoliao Dec 2, 2024
@Henry8192 Henry8192 requested a review from junhaoliao December 3, 2024 19:57
# Conflicts:
#	package-lock.json
#	src/contexts/StateContextProvider.tsx
# Conflicts:
#	src/contexts/StateContextProvider.tsx
src/contexts/StateContextProvider.tsx Outdated Show resolved Hide resolved
@junhaoliao
Copy link
Member

junhaoliao commented Dec 3, 2024

Let's treat this task as a refactoring task as I believe with some interface redesigns, the reported issue could have been avoided.

src/typings/worker.ts -> src/typings/query.ts

  1. Let move all query-related types into a new file src/typings/query.ts.
  2. Let's extract the type of the args of START_QUERY into an interface named QueryArgs and also move that into query.ts.
  3. As we previously discussed, QUERY_PROGRESS_INIT shall be named QUERY_PROGRESS_VALUE_MIN and QUERY_PROGRESS_DONE shall be named QUERY_PROGRESS_VALUE_MAX if you agree.

Change the positional arguments signatures into object parameter signatures

That will include

  1. src/services/LogFileManager/index.ts: startQuery.

  2. src/services/MainWorker.ts: LOG_FILE_MANAGER.startQuery(args);.

    1. Also I don't think the arg type checks are necessary?
  3. src/contexts/StateContextProvider.tsx: startQuery

Misc

You might need to fix the type QueryResultsType import in src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/ResultsGroup.tsx

@Henry8192, could we go over the items on this list that you disagree with?

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

🧹 Outside diff range and nitpick comments (3)
src/typings/query.ts (2)

1-2: Consider more descriptive constant names

The constants could be more specific about their purpose in the query progress context.

-const QUERY_PROGRESS_VALUE_MIN = 0;
-const QUERY_PROGRESS_VALUE_MAX = 1;
+const QUERY_PROGRESS_PERCENTAGE_MIN = 0;
+const QUERY_PROGRESS_PERCENTAGE_MAX = 100;

10-10: Add JSDoc comment for TextRange type

The type would benefit from documentation explaining its purpose and the meaning of each number in the tuple.

+/**
+ * Represents a range of text indices in a log message.
+ * The tuple contains [startIndex, endIndex] where startIndex is inclusive
+ * and endIndex is exclusive.
+ */
type TextRange = [number, number];
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)

70-81: Consider debouncing query submissions

The current implementation triggers a query on every keystroke, which could be resource-intensive for large logs. Consider adding debouncing to improve performance.

+import {debounce} from "lodash";
+
 const handleQuerySubmit = (newArgs: Partial<QueryArgs>) => {
     startQuery({
         isCaseSensitive: getIsCaseSensitive(queryOptions),
         isRegex: getIsRegex(queryOptions),
         queryString: queryString,
         ...newArgs,
     });
 };
 
+const debouncedQuerySubmit = debounce(handleQuerySubmit, 300);
+
 const handleQueryInputChange = (ev: React.ChangeEvent<HTMLTextAreaElement>) => {
     setQueryString(ev.target.value);
-    handleQuerySubmit({queryString: ev.target.value});
+    debouncedQuerySubmit({queryString: ev.target.value});
 };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 31d9609 and c592b58.

📒 Files selected for processing (6)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (4 hunks)
  • src/contexts/StateContextProvider.tsx (5 hunks)
  • src/services/LogFileManager/index.ts (2 hunks)
  • src/services/MainWorker.ts (2 hunks)
  • src/typings/query.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/worker.ts
🔇 Additional comments (4)
src/services/MainWorker.ts (1)

127-127: Consider adding runtime type validation for query arguments

The removal of type checks before calling startQuery could lead to runtime issues if the args object is malformed. While TypeScript provides compile-time type safety, consider adding runtime validation for critical parameters.

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

41-58: Well-implemented utility functions following DRY principles

The implementation follows the suggested refactoring and improves code maintainability.

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

9-12: LGTM: Good separation of query-related types

The relocation of query-related types to a dedicated query.ts file improves code organization and follows the single responsibility principle.


292-297: LGTM: Improved method signature using object parameters

The change to use a single QueryArgs object parameter improves maintainability and makes the method signature more flexible for future additions.

src/services/LogFileManager/index.ts Show resolved Hide resolved
@Henry8192 Henry8192 requested a review from junhaoliao December 8, 2024 01:34
junhaoliao
junhaoliao previously approved these changes Dec 9, 2024
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.

All good except one nit about variable and type ordering.

Regarding the Rabbit's suggestion, we can wrap the RegExp error with a specific message.

src/typings/query.ts Outdated Show resolved Hide resolved
src/typings/query.ts Show resolved Hide resolved
src/typings/query.ts Outdated Show resolved Hide resolved
src/typings/query.ts Show resolved Hide resolved
junhaoliao
junhaoliao previously approved these changes Dec 9, 2024
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

fix(query): Log queries are not restarted when "isCaseSensitive" / "isRegex" button is toggled.

Co-authored-by: Junhao Liao <[email protected]>
@Henry8192 Henry8192 changed the title fix: Log queries are not restarted when "isCaseSensitive" / "isRegex" button is toggled. fix(query): Log queries are not restarted when "isCaseSensitive" / "isRegex" button is toggled. Dec 9, 2024
@Henry8192 Henry8192 changed the title fix(query): Log queries are not restarted when "isCaseSensitive" / "isRegex" button is toggled. fix(query): Restart log queries when case-sensitivity or regex button is toggled. Dec 9, 2024
@Henry8192 Henry8192 requested a review from junhaoliao December 9, 2024 20:00
@Henry8192 Henry8192 merged commit b15d9e0 into y-scope:main Dec 9, 2024
5 checks passed
@Henry8192 Henry8192 deleted the queryOptionButton-fix branch December 9, 2024 20:04
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.

Log queries are not restarted when "isCaseSensitive" / "isRegex" button is toggled.
2 participants