Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@davemarco
Copy link
Contributor

@davemarco davemarco commented Jun 5, 2025

Description

Old webui had logic to unquote query string, so i ported code to new webui. Logic is identical. Code is slightly different for some linter config changes.

Added logic to display message to user if syntax is off.

Personally not as familiar with clp-s, or why we are doing this (i assume there is a reason, but im not familiar), so reviewer please test that works as expected.

Note u need to change setting.json storage engine to clp-s to test this, and run clp-s package

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

Tested error shows up if query is misconfigured.

Summary by CodeRabbit

  • New Features

    • Added enhanced query preprocessing for specific storage engine settings, including automatic unquoting of query strings and improved error handling.
    • Introduced a new utility to safely remove and unescape surrounding quotes from query inputs.
  • Bug Fixes

    • Improved validation and error messages for invalid or empty query submissions.
  • Chores

    • Updated configuration handling for storage engine and stream type settings to improve maintainability and consistency across the application.

@davemarco davemarco requested a review from a team as a code owner June 5, 2025 16:53
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 5, 2025

Walkthrough

A new configuration module was introduced to centralize storage engine and stream type settings. Conditional query preprocessing was added for a specific storage engine, with a new string unquoting utility. Related imports and logic were updated to use the new configuration, and redundant constants were removed or replaced.

Changes

File(s) Change Summary
.../client/src/config/index.ts Added configuration module: imports settings, defines storage engine enum, selects engine, derives and exports stream type constant.
.../client/src/pages/SearchPage/SearchControls/search-requests.ts Added conditional preprocessing for queries using the new engine setting; validates and unquotes query strings before submission.
.../client/src/pages/SearchPage/SearchControls/utils.ts Added and exported unquoteString utility for removing quotes and unescaping characters in strings.
.../client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/LogViewerLink.tsx Updated import path for STREAM_TYPE to use the new centralized configuration module.
.../client/src/pages/SearchPage/SearchResults/SearchResultsTable/utils.ts Refactored to use new config module; removed local constants and updated logic to use imported enums/constants.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant ConfigModule
    participant Utils
    participant ErrorHandler

    User->>UI: Submit query
    UI->>ConfigModule: Get SETTINGS_STORAGE_ENGINE
    alt If engine is CLP_S
        UI->>Utils: unquoteString(queryString)
        alt Success
            UI->>UI: Continue with submission
        else Error (empty or exception)
            UI->>ErrorHandler: Show error message
            ErrorHandler-->>User: Display error
        end
    else
        UI->>UI: Continue with submission
    end
Loading

Possibly related PRs

Suggested reviewers

  • junhaoliao
✨ 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.

@davemarco davemarco requested a review from junhaoliao June 5, 2025 16:53
Copy link
Contributor

@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 e950185 and 3349a8f.

📒 Files selected for processing (5)
  • components/log-viewer-webui/client/src/config/index.ts (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts (2 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.ts (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/LogViewerLink.tsx (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/utils.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>.

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/LogViewerLink.tsx
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts
  • components/log-viewer-webui/client/src/config/index.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/utils.ts
🧬 Code Graph Analysis (1)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/utils.ts (2)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/typings.tsx (1)
  • SearchResult (64-64)
components/log-viewer-webui/client/src/config/index.ts (2)
  • CLP_STORAGE_ENGINES (22-22)
  • SETTINGS_STORAGE_ENGINE (23-23)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: conventional-commits
🔇 Additional comments (14)
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/LogViewerLink.tsx (1)

9-9: LGTM! Clean refactoring to centralize constants.

The import path change correctly references the new centralized configuration module where STREAM_TYPE is now defined.

components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/utils.ts (3)

1-4: LGTM! Good refactoring to centralize configuration.

The import changes correctly use the new centralized configuration module instead of direct JSON imports.


15-15: LGTM! Improved use of enum instead of hardcoded string.

Using CLP_STORAGE_ENGINES.CLP instead of a hardcoded string improves maintainability and reduces the risk of typos.


21-21: LGTM! Correct simplification of exports.

Removing STREAM_TYPE from exports is appropriate since it's now centralized in the config module.

components/log-viewer-webui/client/src/config/index.ts (3)

7-10: LGTM! Well-defined enum for storage engines.

The enum clearly defines the two CLP storage engine variants with appropriate string values.


21-25: LGTM! Clean exports of configuration constants.

The exports provide a clear interface for the centralized configuration.


17-19: 🧹 Nitpick (assertive)

Consider coding guidelines compliance for boolean expressions.

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

-const STREAM_TYPE = CLP_STORAGE_ENGINES.CLP === SETTINGS_STORAGE_ENGINE ?
+const STREAM_TYPE = false == (CLP_STORAGE_ENGINES.CLP === SETTINGS_STORAGE_ENGINE) ?
+    "json" :
-    "ir" :
-    "json";
+    "ir";

Wait, that would invert the logic. The current ternary doesn't use negation, so it actually complies with the guidelines as written.

components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.ts (3)

1-1: LGTM! Appropriate imports for the new feature.

The imports correctly add the necessary dependencies for message display, configuration access, and string unquoting functionality.

Also applies to: 10-13, 16-16


72-72:

✅ Verification successful

Verify the unquoteString utility function exists.

The code imports and uses unquoteString but this utility function isn't visible in the provided files.


🏁 Script executed:

#!/bin/bash
# Description: Verify the unquoteString utility function exists and examine its implementation

# Search for unquoteString function definition
ast-grep --pattern 'function unquoteString($$$) { $$$ }'
ast-grep --pattern 'const unquoteString = $$$'
ast-grep --pattern 'export $$$unquoteString$$$'

# Also search with ripgrep for broader coverage
rg -A 10 "unquoteString.*=" 
rg -A 10 "function unquoteString"

Length of output: 13654


unquoteString utility function is present and correctly imported

The unquoteString function is defined in:

  • components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.ts (lines 15–73)
  • and also in the shared components/webui/imports/utils/misc.js.

No further changes required.


70-85: 🧹 Nitpick (assertive)

LGTM! Well-implemented conditional query preprocessing.

The feature correctly implements the PR objectives by:

  • Using enum comparison to check for CLP_S storage engine
  • Preprocessing query strings with unquoteString utility
  • Providing appropriate error handling and user feedback
  • Using early returns to prevent invalid query submission

However, consider following the coding guidelines for boolean expressions.

-            if ("" === payload.queryString) {
+            if (false == (payload.queryString.length > 0)) {

Actually, let me suggest a simpler approach that's more readable:

-            if ("" === payload.queryString) {
+            if (false == Boolean(payload.queryString)) {

Likely an incorrect or invalid review comment.

components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.ts (4)

1-13: Documentation is comprehensive and clear.

The JSDoc documentation effectively explains the function's purpose, parameters, return value, and exception conditions. The note about not unescaping non-quote characters is particularly helpful for understanding the intended behaviour.


24-41: Character processing logic is well-implemented.

The algorithm correctly handles:

  • Tracking escaped characters with a boolean flag
  • Identifying positions of quotes and escape characters to remove
  • Only removing escape characters that escape quotes (not other characters)

The logic properly maintains the escaped state across iterations and handles the escaping rules as documented.


47-64: Quote validation logic is robust.

The validation ensures that unescaped quotes only appear at the beginning and end of the string, with appropriate error messages for malformed input. The symmetric check for begin/end quotes prevents incomplete quoting scenarios.


66-73: String reconstruction follows coding guidelines correctly.

The code properly uses false === positionOfCharsToRemove.includes(i) which aligns with the coding guideline preference for false == <expression> rather than !<expression>. The filter and join approach efficiently reconstructs the processed string.

CLP_S = "clp-s",
}

const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
Copy link
Contributor

@coderabbitai coderabbitai bot Jun 5, 2025

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify type safety of the assertion.

The type assertion assumes settings.ClpStorageEngine matches the enum values, but there's no runtime validation.


🏁 Script executed:

#!/bin/bash
# Description: Check the settings.json file to verify ClpStorageEngine values match the enum

# Find and examine settings.json files
fd -t f "settings.json" --exec cat {} \;

Length of output: 1552


🏁 Script executed:

#!/bin/bash
# Search for the CLP_STORAGE_ENGINES enum definition in the repository
rg "export enum CLP_STORAGE_ENGINES" -A5 -B5

Length of output: 46


🏁 Script executed:

#!/bin/bash
# Search for the CLP_STORAGE_ENGINES enum or type alias
rg "CLP_STORAGE_ENGINES" -n .

# Search for any import or definition of ClpStorageEngine type
rg "ClpStorageEngine" -n .

Length of output: 2667


🏁 Script executed:

#!/bin/bash
# Display the enum definition and related context in index.ts
rg -n "enum CLP_STORAGE_ENGINES" -A10 -B5 components/log-viewer-webui/client/src/config/index.ts

Length of output: 442


Add runtime validation for settings.ClpStorageEngine

TypeScript’s as CLP_STORAGE_ENGINES cast only enforces types at compile-time. To guard against invalid or unexpected values in settings.json, validate the runtime value before casting:

• File: components/log-viewer-webui/client/src/config/index.ts, line 12

// before casting, ensure the setting is one of the enum values
if (!Object.values(CLP_STORAGE_ENGINES).includes(settings.ClpStorageEngine)) {
  throw new Error(
    `Invalid ClpStorageEngine: ${settings.ClpStorageEngine}. ` +
    `Expected one of ${Object.values(CLP_STORAGE_ENGINES).join(", ")}.`
  );
}

const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;

This check will surface mis-configured values (e.g. a typo or new value not yet in the enum) at startup rather than causing subtle downstream failures.

🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/config/index.ts at line 12, the code
casts settings.ClpStorageEngine to the enum CLP_STORAGE_ENGINES without runtime
validation, risking invalid values. Fix this by adding a runtime check before
the cast: verify that settings.ClpStorageEngine is included in
Object.values(CLP_STORAGE_ENGINES), and if not, throw an error with a clear
message listing valid enum values. This ensures only valid enum values are
accepted at runtime.

Copy link
Member

Choose a reason for hiding this comment

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

i agree with the rabbit on this

Copy link
Contributor

Choose a reason for hiding this comment

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

@junhaoliao Thanks for confirming! You're right that the runtime validation would be a good safety measure to catch invalid configuration values early.

Would you like me to implement the runtime validation that CodeRabbit suggested? I can add the check to ensure settings.ClpStorageEngine is a valid enum value before the type assertion, which would prevent potential runtime issues if the settings file contains an unexpected value.

Copy link
Member

Choose a reason for hiding this comment

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

unless we're planning on adding a check in the setting fetching utility that hasn't been added?

Copy link
Contributor

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for existing settings utilities or validation patterns
echo "=== Searching for settings utilities ==="
rg -n "settings.*util" --type ts --type js

echo "=== Searching for settings validation patterns ==="
rg -n "validate.*settings|settings.*validate" --type ts --type js

echo "=== Searching for other settings imports ==="
rg -n "import.*settings" --type ts --type js

echo "=== Searching for settings configuration or setup files ==="
rg -n "settings.*config|config.*settings" --type ts --type js

echo "=== Looking for centralized settings handling ==="
fd -e ts -e js | xargs rg -l "settings" | head -10

Length of output: 2652


🏁 Script executed:

#!/bin/bash
# Look at how settings are used in other files to see validation patterns
echo "=== Examining how settings are used in server files ==="
cat components/log-viewer-webui/server/src/app.ts | head -20

echo "=== Checking settings usage in query routes ==="
cat components/log-viewer-webui/server/src/routes/query.ts | head -20

echo "=== Looking at the actual settings.json file structure ==="
find . -name "settings.json" -exec cat {} \; | head -30

echo "=== Checking if there are any type definitions for settings ==="
rg -n "interface.*Settings|type.*Settings" --type ts --type d.ts

echo "=== Looking for any validation or schema checking patterns ==="
rg -n "validate|schema|check" --type ts | grep -i settings | head -5

Length of output: 2895


@junhaoliao Based on my analysis of the codebase, there doesn't appear to be any existing or planned centralized settings fetching utility. Here's what I found:

Current State:

  • Settings are imported directly from JSON files in 9+ locations across the codebase
  • No validation patterns exist anywhere for settings
  • No centralized settings utility or type definitions
  • The pattern is consistently: import settings from "path/to/settings.json" followed by direct usage

Architectural Consideration:
You raise a good point about centralization. If you're planning to create a centralized settings utility that would handle validation, that would be a cleaner architectural approach than adding validation piecemeal across multiple import sites.

Recommendation:
Since there's no evidence of a planned centralized utility, I'd suggest adding the runtime validation here for now. It's a small safety net that prevents potential runtime issues. If you later decide to create a centralized settings utility, this validation can easily be moved there and removed from individual import sites.

Would you prefer to:

  1. Add the validation here as suggested by CodeRabbit
  2. Defer this and plan for a centralized settings utility first
  3. Skip validation entirely given the current codebase pattern

What are your thoughts on the architectural approach?

Copy link
Contributor Author

@davemarco davemarco Jun 9, 2025

Choose a reason for hiding this comment

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

my view on this was that that the value comes from clp package, where it is validated, therefore, it must be correct(i.e. clp or clp-s), and dosent need to be validated twice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Member

Choose a reason for hiding this comment

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

my view on this was that that the value comes from clp package, where it is validated, therefore, it must be correct(i.e. clp or clp-s)

you're right. from the user's perspective, the clp start scripts should have validated the input. developers could make typos when they directly modify the settings file, but we don't have to handle that for now

Comment on lines +14 to +22
// eslint-disable-next-line max-statements
const unquoteString = (
str: string,
quoteChar: string,
escapeChar:string,
) => {
if (0 === str.length) {
return str;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Fix spacing in function parameter.

There's a missing space after the colon in the escapeChar parameter type annotation.

-    escapeChar:string,
+    escapeChar: string,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// eslint-disable-next-line max-statements
const unquoteString = (
str: string,
quoteChar: string,
escapeChar:string,
) => {
if (0 === str.length) {
return str;
}
// eslint-disable-next-line max-statements
const unquoteString = (
str: string,
quoteChar: string,
escapeChar: string,
) => {
if (0 === str.length) {
return str;
}
🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.ts
around lines 14 to 22, fix the spacing in the function parameter list by adding
a space after the colon in the type annotation for the escapeChar parameter,
changing "escapeChar:string" to "escapeChar: string".

CLP_S = "clp-s",
}

const SETTINGS_STORAGE_ENGINE = settings.ClpStorageEngine as CLP_STORAGE_ENGINES;
Copy link
Member

Choose a reason for hiding this comment

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

i agree with the rabbit on this

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 address https://github.com/y-scope/clp/pull/967/files#r2129335327 then this is good to go

@davemarco
Copy link
Contributor Author

see reply

@davemarco davemarco merged commit 67c218c into y-scope:main Jun 10, 2025
7 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