-
Notifications
You must be signed in to change notification settings - Fork 83
feat(new-webui): Unquote query string for clp-s queries. #967
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
Conversation
WalkthroughA 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
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
Possibly related PRs
Suggested reviewers
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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}: - Preferfalse == <expression>rather than!<expression>.
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/Message/LogViewerLink.tsxcomponents/log-viewer-webui/client/src/pages/SearchPage/SearchControls/utils.tscomponents/log-viewer-webui/client/src/pages/SearchPage/SearchControls/search-requests.tscomponents/log-viewer-webui/client/src/config/index.tscomponents/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_TYPEis 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.CLPinstead of a hardcoded string improves maintainability and reduces the risk of typos.
21-21: LGTM! Correct simplification of exports.Removing
STREAM_TYPEfrom 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
unquoteStringbut 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
unquoteStringfunction 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 forfalse == <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; |
There was a problem hiding this comment.
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 -B5Length 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.tsLength 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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Add the validation here as suggested by CodeRabbit
- Defer this and plan for a centralized settings utility first
- Skip validation entirely given the current codebase pattern
What are your thoughts on the architectural approach?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
| // eslint-disable-next-line max-statements | ||
| const unquoteString = ( | ||
| str: string, | ||
| quoteChar: string, | ||
| escapeChar:string, | ||
| ) => { | ||
| if (0 === str.length) { | ||
| return str; | ||
| } |
There was a problem hiding this comment.
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.
| // 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; |
There was a problem hiding this comment.
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
There was a problem hiding this 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
|
see reply |
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
breaking change.
Validation performed
Tested error shows up if query is misconfigured.
Summary by CodeRabbit
New Features
Bug Fixes
Chores