Skip to content

refactor(query): Refactor QueryInputBox into a dedicated component from SearchTabPanel. #196

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

Merged
merged 2 commits into from
Mar 3, 2025

Conversation

junhaoliao
Copy link
Member

@junhaoliao junhaoliao commented Mar 2, 2025

Description

  1. Refactor QueryInputBox into a dedicated component from SearchTabPanel.

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 with demo file as instructed from the contribution guide.
  2. Started a query with keyword rmcontainerimpl and observed results shown in the search panel.
  3. Toggled (Activated) the "Aa" case-sensitivity switch and observed no result shown in the search panel. Toggle the button again (deactivated) and observed results shown.
  4. Entered query rmcontainerimpl(.*)container and observed no results. Toggled (activated) the ".*" use-regex button and observed results shown and the matching parts are highlighted as expected.
  5. Hovered onto the toggle buttons and observed the button tooltips shown as expected ("Match case" & "Use regular expression").

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced query input box in the sidebar with improved layout, integrated progress feedback, and options for customised query parameters.
  • Refactor

    • Streamlined the search panel by replacing the previous input mechanism with the new, unified query input box for a cleaner and more consistent user interface.

@junhaoliao junhaoliao requested a review from a team as a code owner March 2, 2025 05:16
Copy link

coderabbitai bot commented Mar 2, 2025

Walkthrough

This pull request introduces a new modular approach for handling query inputs in the Sidebar’s Search Tab Panel. A dedicated React component, QueryInputBox, now encapsulates query input handling, including text input, case sensitivity and regex toggles, and a linear progress indicator. Styling for these elements has been migrated from the shared stylesheet to a new CSS file, with obsolete query-related styles removed from the original file. Overall, the changes streamline state management by offloading query logic from the parent component to the new QueryInputBox component.

Changes

File(s) Change Summary
src/.../SearchTabPanel/QueryInputBox.css
src/.../SearchTabPanel/index.css
Added new CSS styles for the query input box in QueryInputBox.css; removed the corresponding obsolete classes from index.css.
src/.../SearchTabPanel/QueryInputBox.tsx Introduced a new React functional component that handles query inputs, toggle buttons for options, and displays the linear progress indicator.
src/.../SearchTabPanel/index.tsx Removed inline query state management and UI elements, replacing them with the integrated QueryInputBox component.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant QueryInputBox
    participant StateContext

    User->>QueryInputBox: Enters query text / toggles options
    QueryInputBox->>QueryInputBox: Updates local state (query, options)
    QueryInputBox->>StateContext: Submits query (via handleQuerySubmit)
    StateContext-->>QueryInputBox: Returns query progress update
    QueryInputBox->>User: Updates linear progress indicator
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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: 0

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

50-53: Update condition to follow coding guidelines

According to project coding guidelines, prefer false == <expression> rather than !<expression>.

const handleCaseSensitivityButtonClick = () => {
-    handleQuerySubmit({isCaseSensitive: !isCaseSensitive});
-    setIsCaseSensitive(!isCaseSensitive);
+    handleQuerySubmit({isCaseSensitive: false == isCaseSensitive});
+    setIsCaseSensitive(false == isCaseSensitive);
};

55-58: Update condition to follow coding guidelines

According to project coding guidelines, prefer false == <expression> rather than !<expression>.

const handleRegexButtonClick = () => {
-    handleQuerySubmit({isRegex: !isRegex});
-    setIsRegex(!isRegex);
+    handleQuerySubmit({isRegex: false == isRegex});
+    setIsRegex(false == isRegex);
};

112-114: Condition formatting could be improved

For better readability and to follow project coding guidelines, consider restructuring this ternary condition.

value={queryProgress * 100}
-color={QUERY_PROGRESS_VALUE_MAX === queryProgress ?
-    "success" :
-    "primary"}/>
+color={
+    QUERY_PROGRESS_VALUE_MAX === queryProgress
+        ? "success"
+        : "primary"
+}/>
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19fd738 and e4cc3cb.

📒 Files selected for processing (4)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.css (1 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.tsx (1 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.css (0 hunks)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (3 hunks)
💤 Files with no reviewable changes (1)
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.css
🧰 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/QueryInputBox.tsx
  • src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx
🧠 Learnings (2)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.css (1)
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#107
File: src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.css:14-18
Timestamp: 2024-11-14T04:35:00.986Z
Learning: In `src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.css`, the use of `!important` flags is necessary for overriding styles in the `.query-input-box` class.
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/index.tsx (1)
Learnt from: Henry8192
PR: y-scope/yscope-log-viewer#107
File: src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/Result.tsx:34-58
Timestamp: 2024-11-10T16:46:53.300Z
Learning: When suggesting performance optimizations, ensure they are significant and applicable to the specific context of the code being reviewed.
🔇 Additional comments (7)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.css (4)

1-5: Well-implemented solution for JoyUI rounding issue

The margin adjustment is a clean fix for the JoyUI component's width calculation issue. The comment clearly explains the reason for this adjustment.


7-10: Appropriate use of !important flags

The use of !important flags here is necessary and aligns with previous learnings about overriding styles in JoyUI components.


12-19: Consistent button styling with precise dimensions

The styles ensure the option buttons maintain consistent size and typography, which is important for the UI's visual consistency.


30-33: Good practice with stylelint exception

The stylelint-disable comment properly documents the intentional deviation from the linting rule, which is a good practice when exceptions are necessary.

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

21-21: Clean component refactoring with improved separation of concerns

The refactoring successfully extracts the query input functionality into a dedicated component, resulting in cleaner code with better separation of concerns. The SearchTabPanel now focuses solely on managing the panel structure and results display.

Also applies to: 33-34, 59-59

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

29-61: Well-structured component with clean state management

The component is well-organized with appropriate state management and clear separation of concerns. The handlers are logically structured and maintain a consistent pattern.


62-116: Clean UI implementation with appropriate component composition

The component's UI is well structured with good use of MUI Joy components. The linear progress indicator provides good visual feedback for the query process.

@junhaoliao
Copy link
Member Author

This should fix the linting violations in #173 and #195 .

@junhaoliao junhaoliao requested a review from Henry8192 March 3, 2025 05:35
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 (2)
src/components/CentralContainer/Sidebar/SidebarTabs/SearchTabPanel/QueryInputBox.tsx (2)

45-48: Consider implementing debouncing for query submissions.

The current implementation submits a query on every keystroke, which could potentially lead to performance issues with larger datasets or complex queries.

You could add debouncing to optimize performance:

+import { debounce } from "lodash"; // or implement your own debounce function
 
 const QueryInputBox = () => {
     const {queryProgress, startQuery, uiState} = useContext(StateContext);
 
     const [queryString, setQueryString] = useState<string>("");
     const [isCaseSensitive, setIsCaseSensitive] = useState<boolean>(false);
     const [isRegex, setIsRegex] = useState<boolean>(false);
+
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+    const debouncedQuerySubmit = React.useCallback(
+        debounce((newArgs: Partial<QueryArgs>) => {
+            startQuery({
+                isCaseSensitive: isCaseSensitive,
+                isRegex: isRegex,
+                queryString: queryString,
+                ...newArgs,
+            });
+        }, 300),
+        [isCaseSensitive, isRegex, queryString, startQuery]
+    );
 
     const handleQuerySubmit = (newArgs: Partial<QueryArgs>) => {
-        startQuery({
-            isCaseSensitive: isCaseSensitive,
-            isRegex: isRegex,
-            queryString: queryString,
-            ...newArgs,
-        });
+        debouncedQuerySubmit(newArgs);
     };

23-28: Complete the JSDoc comment with a proper return description.

The JSDoc comment is missing a return description after the @return tag.

 /**
  * Provides a text input and optional toggles for submitting search queries.
  *
- * @return
+ * @return {JSX.Element} A component containing query input field, toggle buttons and progress indicator.
  */
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e4cc3cb and d5efe31.

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

30-31: LGTM! Good use of React context to access global state.

The component correctly uses the context to access query-related functionality and UI state. This approach cleanly separates the query input box logic from the parent component.


32-34: LGTM! Clean state initialization.

The component properly initializes local state variables for query string and toggle options with appropriate types. Using individual state variables instead of a combined state object makes the code more readable and easier to maintain.


36-43: LGTM! Clear and reusable query submission handler.

The handleQuerySubmit function is well-designed to accept partial arguments, which allows for flexible reuse in different scenarios. Spreading the newArgs at the end ensures they can override default values.


60-60: LGTM! Good separation of UI state logic.

Using a dedicated utility function isDisabled to determine the disabled state of UI elements promotes code reuse and consistency across the application.


62-115: LGTM! Well-structured component rendering with appropriate props and layout.

The component rendering is well-organized with clear prop assignments and logical structure. The use of MUI Joy components with appropriate customization helps maintain a consistent UI design.


118-118: Remove this unnecessary blank line.

There's an extra blank line before the export statement. This line was already marked for removal in a previous review.


107-115:

✅ Verification successful

Verify the LinearProgress value calculation.

The progress value is multiplied by 100, assuming that queryProgress is a decimal between 0 and 1. Verify that this calculation is correct based on the expected range of queryProgress.


🏁 Script executed:

#!/bin/bash
# Check for occurrences of QUERY_PROGRESS_VALUE_MAX to verify its value and usage
ast-grep --pattern $'const QUERY_PROGRESS_VALUE_MAX = $_'
# Also look for other usages of queryProgress to understand the expected range
rg -A 2 -B 2 "queryProgress" --type ts --type tsx

Length of output: 196


Progress Calculation Verified: Approved
We confirmed that the maximum query progress value is defined as 1 in src/typings/query.ts (line 18), meaning that queryProgress is expected to be a decimal between 0 and 1. Multiplying by 100 to compute the appropriate percentage for the LinearProgress component is therefore correct. No further changes are required.

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.

@junhaoliao junhaoliao merged commit 1e8455e into y-scope:main Mar 3, 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