Skip to content

build(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript.#645

Merged
junhaoliao merged 50 commits into
y-scope:mainfrom
junhaoliao:log-viewer-webui-client-ts
Mar 24, 2025
Merged

build(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript.#645
junhaoliao merged 50 commits into
y-scope:mainfrom
junhaoliao:log-viewer-webui-client-ts

Conversation

@junhaoliao

@junhaoliao junhaoliao commented Dec 26, 2024

Copy link
Copy Markdown
Member

⚠️ This PR depends on y-scope/eslint-config-yscope#3 . Do not merge this PR till that PR is merged. The PR has been merged and a release of eslint-config-yscope was made, which has been integrated into this PR.

Description

  1. Switch from Webpack to Vite for bundling. Note: changes in this PR are based on the official template at https://github.com/vitejs/vite/tree/8639538e6498d1109da583ad942c1472098b5919/packages/create-vite/template-react-ts
  2. Convert the codebase to TypeScript.
  3. Update dependencies.

Validation performed

  1. Built the package: https://docs.yscope.com/clp/main/dev-guide/building-package
  2. Started the package: https://docs.yscope.com/clp/main/user-guide/quick-start-cluster-setup/single-node.html
  3. Compressed sample files: clp-package/sbin/compress.sh ~/samples/hive-24hr.
  4. Loaded the webui http://localhost:4000 in a Microsoft Edge browser.
  5. Performed a search with query string "1".
  6. On the first result, clicked the "View log event in context" button which brought up the log-viewer-webui-client page in a new tab. Later, the log viewer loaded up the log viewer which displayed the log in the context. Comparing the query result from the CLP webui and the one at the log viewer cursor and confirmed they match which should suggest the logEventNum parameter is also correctly passed.

Debug mode

  1. clp-package/sbin/stop-clp.sh log_viewer_webui.
  2. cd clp/component/log-viewer-webui; npm i; npm start
  3. Repeat step 7, in the "log-viewer-webui-client page in the new tab", change the port in the address bar to 8080 and observed successful extraction job completion. The redirection to yscope-log-viewer would not work because the viewer app is not served at the same address.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced an enhanced query interface with improved progress indicators and error feedback for a smoother log retrieval experience.
    • Added a new QueryStatus component for better management of query submissions and states.
  • Refactor

    • Transitioned to a statically typed codebase using TypeScript and updated the build process to Vite for improved performance and maintainability.
    • Simplified import paths and enhanced type safety across components.
  • Chores

    • Upgraded dependencies, revised project metadata, and refreshed configuration to align with modern standards.
    • Introduced new TypeScript configuration files to support the updated build process.

@coderabbitai

coderabbitai Bot commented Dec 26, 2024

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request transitions the log viewer web UI from JavaScript to TypeScript and updates the build process from Webpack to Vite. Key changes include a modified package.json with updated dependencies and scripts, the removal of outdated Webpack configuration, and the introduction of new TypeScript configuration files. API functions have been migrated from JavaScript to TypeScript with added type definitions, and several UI components have been updated for improved type safety and import consistency. Additionally, the ESLint setup and task commands have been adjusted to better reflect the new toolchain.

Changes

Files Change Summary
components/log-viewer-webui/client/package.json Updated main entry from src/index.jsx to src/main.tsx; build scripts now run TypeScript compilation and Vite build; dependency revisions include new packages (e.g., @emotion/react, axios, react, etc.) and removal of Webpack-related packages.
components/log-viewer-webui/client/src/App.tsx Updated import statements: simplified MUI import, changed local storage key import, and removed file extensions from component imports; modified JSDoc comment syntax.
components/log-viewer-webui/client/src/api/query.js
components/log-viewer-webui/client/src/api/query.ts
Removed legacy query.js; added new query.ts featuring the submitExtractStreamJob function with TypeScript types and the ExtractStreamResp interface.
components/log-viewer-webui/client/src/typings/common.ts
components/log-viewer-webui/client/src/typings/config.ts
components/log-viewer-webui/client/src/typings/query.ts
Added a new Nullable<T> type alias; introduced new enums (QUERY_LOADING_STATE, QUERY_JOB_TYPE), constants, and interfaces for query management; added a new enum LOCAL_STORAGE_KEY for configuration.
components/log-viewer-webui/client/src/ui/Loading.tsx Introduced TypeScript interfaces for component props (LoadingStepProps and LoadingProps); updated component signatures and logic to utilize new loading state constants.
components/log-viewer-webui/client/src/ui/QueryStatus.tsx Added a new component to manage query submission, URL parameter parsing, error handling, and state updates leading to redirection.
components/log-viewer-webui/client/tsconfig.json Added a new TypeScript configuration file referencing both app and node-specific configurations.
components/log-viewer-webui/client/webpack.config.js Removed the legacy Webpack configuration file.
Taskfile.yml Updated task definitions to include new source files (HTML, TSConfig files) and modified file patterns to use TypeScript (.ts, .tsx) instead of JavaScript (.jsx); explicit build commands for different components.
components/log-viewer-webui/client/index.html Modified the HTML title and meta tags; added a module script tag to load the new src/main.tsx file.
components/log-viewer-webui/client/src/main.tsx Introduced a new entry point for the React app using TypeScript, initializing the application with StrictMode.
components/log-viewer-webui/client/src/vite-env.d.ts Added a reference to Vite client types to enable proper TypeScript autocompletion and type checking.
components/log-viewer-webui/client/vite.config.ts Added a new Vite configuration file with the React plugin, server settings (port 8080), and a proxy for /query requests.
components/log-viewer-webui/client/eslint.config.mjs Introduced a new ESLint configuration file that aggregates common, React, stylistic, and TypeScript-specific rules with overrides for project-specific files.
components/log-viewer-webui/client/tsconfig/tsconfig.app.json
components/log-viewer-webui/client/tsconfig/tsconfig.base.json
components/log-viewer-webui/client/tsconfig/tsconfig.node.json
Introduced additional TypeScript configuration files to manage app, base, and node-specific settings, ensuring strict type-checking and updated module handling.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant QS as QueryStatus Component
    participant API as API Layer (submitExtractStreamJob)
    participant AX as Axios
    participant LV as Log Viewer

    U->>QS: Load page and render component
    QS->>QS: Parse & validate URL parameters
    QS->>API: Call submitExtractStreamJob with parameters
    API->>AX: POST request to /query/extract-stream
    AX-->>API: Response with stream data
    API-->>QS: Return response data
    QS->>QS: Update query state (LOADING/Error)
    alt On Success
      QS->>LV: Redirect to log viewer with query parameters
    else On Error
      QS->>QS: Display error via Loading component
    end
Loading

Suggested reviewers

  • kirkrodrigues
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

Comment thread components/log-viewer-webui/client/tsconfig.json Outdated
Comment thread components/log-viewer-webui/client/package.json Outdated
@junhaoliao junhaoliao marked this pull request as ready for review December 26, 2024 10:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (4)
components/log-viewer-webui/client/src/index.tsx (1)

9-10: Consider gracefully handling potential null references.

While the non-null assertion operator (!) informs TypeScript that the element will never be null, it could still lead to runtime errors if the element does not actually exist. It might be safer to throw an error or provide a fallback to handle this scenario more robustly.

Below is a sample approach:

-const root = createRoot(document.getElementById("root")!);
+const rootElement = document.getElementById("root");
+if (false == rootElement) {
+    throw new Error("Root element not found in DOM");
+}
+const root = createRoot(rootElement);
components/log-viewer-webui/client/src/App.tsx (1)

10-10: Confirm JSDoc return annotation.

Removing the explicit return type is often fine in TypeScript since return types can be inferred. However, please ensure that your documentation accurately reflects the function’s intended return structure.

components/log-viewer-webui/client/src/api/query.ts (1)

29-44: Enhance error handling and request cancellation.

While submitExtractStreamJob is straightforward, consider adding optional request cancellation (via Axios.cancelToken) or error handling to avoid unhandled promise rejections if the server or network fails.

components/log-viewer-webui/client/src/ui/QueryStatus.tsx (1)

29-29: Document return values more explicitly.
Please clarify the returned type or structure to help future readers understand the component’s outcome.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 329edf6 and 3444981.

⛔ Files ignored due to path filters (1)
  • components/log-viewer-webui/client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (12)
  • components/log-viewer-webui/client/package.json (2 hunks)
  • components/log-viewer-webui/client/src/App.tsx (1 hunks)
  • components/log-viewer-webui/client/src/api/query.js (0 hunks)
  • components/log-viewer-webui/client/src/api/query.ts (1 hunks)
  • components/log-viewer-webui/client/src/index.tsx (1 hunks)
  • components/log-viewer-webui/client/src/typings/common.ts (1 hunks)
  • components/log-viewer-webui/client/src/typings/query.js (0 hunks)
  • components/log-viewer-webui/client/src/typings/query.ts (1 hunks)
  • components/log-viewer-webui/client/src/ui/Loading.tsx (3 hunks)
  • components/log-viewer-webui/client/src/ui/QueryStatus.tsx (3 hunks)
  • components/log-viewer-webui/client/tsconfig.json (1 hunks)
  • components/log-viewer-webui/client/webpack.config.js (4 hunks)
💤 Files with no reviewable changes (2)
  • components/log-viewer-webui/client/src/api/query.js
  • components/log-viewer-webui/client/src/typings/query.js
✅ Files skipped from review due to trivial changes (1)
  • components/log-viewer-webui/client/src/typings/common.ts
🧰 Additional context used
📓 Path-based instructions (7)
components/log-viewer-webui/client/src/index.tsx (1)

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

components/log-viewer-webui/client/webpack.config.js (1)

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

components/log-viewer-webui/client/src/App.tsx (1)

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

components/log-viewer-webui/client/src/api/query.ts (1)

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

components/log-viewer-webui/client/src/ui/Loading.tsx (1)

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

components/log-viewer-webui/client/src/typings/query.ts (1)

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

components/log-viewer-webui/client/src/ui/QueryStatus.tsx (1)

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

🔇 Additional comments (48)
components/log-viewer-webui/client/src/App.tsx (2)

1-1: Confirm updated import path for CssVarsProvider.

The new import path @mui/joy is correct for the current version of MUI Joy. Please confirm that this is aligned with your package.json dependencies.


3-4: Ensure consistent usage of TypeScript imports.

Dropping the file extensions is appropriate given your tsconfig settings. Double-check that all references to these imports have been updated accordingly in the rest of the project.

components/log-viewer-webui/client/src/api/query.ts (4)

1-4: Validate Axios import for TypeScript usage.

Your imports from Axios are compatible with TypeScript. Ensure that your tsconfig includes the necessary type definitions for Axios to avoid runtime or type definition issues.


6-16: Enum usage for QUERY_JOB_TYPE.

Leveraging QUERY_JOB_TYPE in TypeScript helps prevent invalid job-type values. Confirm that calling code passes valid enum members.


9-16: Check interface fields align with backend schema.

The fields in ExtractStreamResp appear to match typical streaming extraction responses. Confirm with backend docs that the field names (begin_msg_ix, is_last_chunk, etc.) remain stable or forward-compatible.


46-46: Export structure is consistent with TypeScript norms.

Exporting submitExtractStreamJob from this file provides a clean API surface for your data-fetching logic. Good work keeping it readable and modular.

components/log-viewer-webui/client/src/typings/query.ts (6)

1-5: Numeric enum usage is valid.

Using numeric enums for QUERY_LOADING_STATE is fine. If you ever need more explicit debugging or logging, consider string enums or an equivalent mapping for greater clarity.


7-12: Filtering enum values to numeric types.

The approach of filtering out string enum keys from the Object.values(QUERY_LOADING_STATE) array is efficient. This logic is correct for numeric enums.


14-18: QUERY_JOB_TYPE validity.

Ensure these job types don’t overlap with existing or potential future ones. Numeric enums can inadvertently overlap if not carefully tracked, so consider a stable numbering scheme.


20-23: Interface definitions match usage.

QueryLoadingStateDescription is clearly structured. Nicely done on using a separate interface for clarity.


28-43: Providing descriptive labels is helpful.

QUERY_LOADING_STATE_DESCRIPTIONS nicely documents each enum’s purpose. This improves maintainability. Great usage of Object.freeze for immutability.


45-50: Exports are well-organized.

All relevant symbols are exported for external usage. This aligns with a neat and modular TypeScript codebase.

components/log-viewer-webui/client/webpack.config.js (7)

36-36: Entry point switched to TypeScript index.

Switching from index.jsx to index.tsx is consistent with the migration to TypeScript. Verify that your scripts and references in package.json also reflect this change.


37-39: Mode configuration is correct.

Using environment-based modes is standard practice. Ensure that your build process sets NODE_ENV correctly.


43-43: Refined test pattern for TS/TSX.

Updating the regex ensures proper handling of .ts/.tsx files. Confirm that .js or .jsx is no longer needed if you’ve fully migrated.


56-56: Added TypeScript Babel preset.

Including @babel/preset-typescript is crucial for transpiling TypeScript. Looks good.


73-87: SplitChunks for better performance.

Your splitChunks configuration ensures proper vendor chunking to boost caching and reduce bundle sizes. Good practice.


103-104: Extended resolve with TS/TSX.

Adding .ts/.tsx to resolve.extensions is correct for a TypeScript codebase. Confirm that any .jsx references are not needed.


109-109: Exporting config object.

Exporting the Webpack config object is a clean approach that simplifies usage. Nice move.

components/log-viewer-webui/client/src/ui/QueryStatus.tsx (8)

7-7: Implementation of isAxiosError is beneficial.
This import helps refine error handling for Axios requests, ensuring more accurate detection of Axios-related issues.


9-15: Imports for new type definitions appear streamlined.
Bringing in submitExtractStreamJob, Nullable, and the QUERY_LOADING_STATE constants from separate files fosters modularity and clarity.


32-35: Adoption of strong state typing looks solid.
Using generic types for useState clarifies the permissible values, reducing unintended usage.


57-57: Confirm logical intention of false === streamType in EXTRACT_JOB_TYPE.
While this meets the style preference for false == expression, the operator precedence may be confusing. Consider adding parentheses or using an explicit check (e.g. false == (streamType in EXTRACT_JOB_TYPE)) to convey your intent more clearly.


64-65: Sanitizing user input is prudent.
Using Number() ensures logEventIdx is converted to a numeric type. This helps avoid injection issues and fosters type consistency.


70-72: Updating state on job submission is accurate.
Transitioning to the WAITING state upon submission clarifies the user that a process is in progress.


76-79: Smooth transition to LOADING with correct offset usage.
Calculating innerLogEventNum ensures the log event index aligns with the server’s base offset. Redirection is correct, and usage of window.location.href is consistent with the new approach.


82-84: Comprehensive error handling.
Distinguishing Axios errors from general exceptions helps provide more accurate feedback to the user. Good approach.

components/log-viewer-webui/client/src/ui/Loading.tsx (9)

1-1: Neat import of React.
Explicitly importing React ensures consistent usage of JSX transformations under the TypeScript environment.


12-12: DefaultColorPalette usage is consistent.
Allows for a typed palette configuration, reducing the risk of undefined colour usage.


14-14: Nullable type fosters clarity for optional fields.
This approach clearly conveys which properties can be null, enhancing reliability.


16-19: Use of enumerated states simplifies logic.
Referencing QUERY_LOADING_STATE and related constants reduces magic strings.


24-31: LoadingStepProps interface definitions are straightforward.
These type annotations provide clarity for each required prop, reducing guesswork for future contributors.


49-50: Conditional colour assignment is intuitive.
The code clearly differentiates active and error states, enhancing readability.


84-87: LoadingProps interface is well-defined.
Specifying these types ensures consistent usage of currentState and errorMsg throughout the component.


97-100: Structured destructuring of props.
Explicitly typed parameters help TypeScript detect possible misuses at compile time.


101-103: Building steps array based on states improves maintainability.
Looping through known state values in QUERY_LOADING_STATE_VALUES helps ensure all defined states are handled.

components/log-viewer-webui/client/package.json (4)

5-5: Switching main entry to src/index.tsx is appropriate.
Reflects the recent TypeScript migration, ensuring the build references the correct entry point.


7-7: Upgrading the build script.
Using --config-node-env production aligns with the updated webpack CLI usage, which resolves deprecation in older versions.


16-35: Dependency updates facilitate TypeScript support.
Including @babel/preset-typescript plus updated Babel/webpack dependencies is crucial for the TypeScript build pipeline.


36-86: Dependencies reorganized for clarity and usage.
Promoting relevant libraries (e.g. react, axios) into dependencies ensures they are accessible in production. ESlint configuration is robust, with coverage for TypeScript files.

components/log-viewer-webui/client/tsconfig.json (8)

1-7: Inclusion/exclusion paths are clearly defined.
This separation ensures extraneous files such as node_modules do not affect compilation time or produce unnecessary errors.


8-35: Targeting ES2022 with DOM library is appropriate.
Allows usage of next-gen JavaScript features while supporting browser-based functionalities.


39-44: ESNext module system with bundler resolution is modern.
Harmonizes well with contemporary bundlers and ensures top-level await or other ESNext features can be leveraged.


50-58: Permitting JSON imports is beneficial.
This functionality can consolidate certain config or data definitions directly into the TypeScript code.


63-67: allowJs and checkJs help unify JS and TS.
This configuration is valuable during transitional phases, ensuring JS still gets type-checked where possible.


74-83: sourceMap and noEmit are well-chosen.
Emitting source maps aids debugging, while noEmit clarifies that compiled output is handled by the bundler.


100-106: Enabling isolated modules and ES module interop is standard.
Helps ensure each file is self-sufficient during transpilation, plus broadens import compatibility for third-party modules.


108-143: Strict type checking is thoroughly configured.
Enabling strict mode and measures such as noImplicitAny, strictNullChecks, and noUnusedLocals fosters maintainable, predictable code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This comment no longer applies.

The linting rules are indeed ported to tsconfig.node.ts and tsconfig.app.ts though.

@@ -0,0 +1,152 @@
{
"include": [
"src",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

compared to the one in yscope-log-viewer, removed

    "jest.config.ts",
    "test",

/* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": [
"ES2022",
"DOM",

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

compared to the one in yscope-log-viewer, removed

      "DOM.Iterable",
      "WebWorker",

},
};

export default () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@kirkrodrigues I don't recall if we discussed this for #468 - Did we have to export a function and change the config.mode dynamically? Can we simply define the mode in the above config object and return the object directly?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, that's my understanding based on this: https://webpack.js.org/configuration/configuration-types/#exporting-a-function

I think the old code was wrong since it should've been using the env argument to determine whether it was prod/dev rather than isProduction. Based on a glance at this, I guess we shouldn't be using process.env.NODE_ENV in a webpack config.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Gotcha. Let me defer this after investigating the viability of turning the app into a Vite-React app.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The attempt to migrate to Vite was effortless and they provide all what we need with very simple configuration interfaces. I think we can stick with Vite in this project.

"eval-source-map",
entry: path.resolve(dirname, "src", "index.jsx"),
entry: path.resolve(dirname, "src", "index.tsx"),
mode: isProduction ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Note this was moved from the default-exported function.

@junhaoliao

Copy link
Copy Markdown
Member Author

Alternatively, shall we look into turning this into a Vite-React app? That way we don't have to manage the build configs on our own with webpack.

@kirkrodrigues

Copy link
Copy Markdown
Member

Alternatively, shall we look into turning this into a Vite-React app? That way we don't have to manage the build configs on our own with webpack.

We could, I guess.

@junhaoliao junhaoliao changed the title chore(log-viewer-webui-client): Convert the codebase to TypeScript; Update dependencies. chore(log-viewer-webui-client): Convert the codebase to TypeScript; Switch from Webpack to Vite for bundling. Dec 29, 2024
@junhaoliao junhaoliao changed the title chore(log-viewer-webui-client): Convert the codebase to TypeScript; Switch from Webpack to Vite for bundling. chore(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript. Dec 29, 2024

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (7)
components/log-viewer-webui/client/tsconfig.node.json (2)

3-7: Consider relocating tsBuildInfo and reviewing skipLibCheck setting

Two suggestions for improvement:

  1. Consider moving tsBuildInfoFile outside of node_modules to avoid CI/CD caching issues. A better location would be .ts-cache or similar.
  2. The skipLibCheck: true setting might hide type issues in dependencies. Consider setting it to false if build time permits.
-    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
+    "tsBuildInfoFile": "./.ts-cache/tsconfig.node.tsbuildinfo",

16-21: Consider enabling additional strict checks

The current strict checks are good, but consider enabling these additional TypeScript checks for better type safety:

  • noImplicitReturns: Ensure all code paths return a value
  • exactOptionalPropertyTypes: More precise optional property types
  • noPropertyAccessFromIndexSignature: Prevent typos in property access
     "strict": true,
     "noUnusedLocals": true,
     "noUnusedParameters": true,
     "noFallthroughCasesInSwitch": true,
-    "noUncheckedSideEffectImports": true
+    "noUncheckedSideEffectImports": true,
+    "noImplicitReturns": true,
+    "exactOptionalPropertyTypes": true,
+    "noPropertyAccessFromIndexSignature": true
🧰 Tools
🪛 Biome (1.9.4)

[error] 16-16: JSON standard does not allow comments.

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

components/log-viewer-webui/client/tsconfig.app.json (2)

18-23: Consider additional type-checking options

The current linting configuration is good, but could be enhanced with these additional checks:

 {
   "compilerOptions": {
     /* Linting */
     "strict": true,
     "noUnusedLocals": true,
     "noUnusedParameters": true,
     "noFallthroughCasesInSwitch": true,
-    "noUncheckedSideEffectImports": true
+    "noUncheckedSideEffectImports": true,
+    "noImplicitReturns": true,
+    "exactOptionalPropertyTypes": true,
+    "noPropertyAccessFromIndexSignature": true
   }
 }
🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: JSON standard does not allow comments.

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


25-25: Consider more specific include/exclude paths

The current configuration includes all files under src. Consider adding an exclude array to filter out test files and other non-app code:

 {
   "compilerOptions": {
     // ... existing options ...
   },
-  "include": ["src"]
+  "include": ["src"],
+  "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx", "src/**/*.spec.ts", "src/**/*.spec.tsx"]
 }
🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-26: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

components/log-viewer-webui/client/vite.config.ts (1)

1-18: Consider environment variables for development and production differences.

Currently, the server proxy is hard-coded to http://localhost:3000/query. You may want to employ environment variables (e.g., process.env.NODE_ENV for dev or production) or a .env file to manage different URLs. This would enhance deploy-time flexibility.

components/log-viewer-webui/client/package.json (2)

5-5: Use a more descriptive entry name if desired.

While "main": "src/main.tsx" is valid, you could consider using a more descriptive name to indicate the application’s entry point. This is purely a stylistic choice that might help distinguish from other modules.


15-22: Document newly introduced dependencies.

The new dependencies (@emotion/*, axios, etc.) should be noted in the project’s documentation to inform future maintainers of their usage. This is especially important when adopting UI libraries like MUI Joy.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3444981 and 8b03576.

⛔ Files ignored due to path filters (1)
  • components/log-viewer-webui/client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • Taskfile.yml (2 hunks)
  • components/log-viewer-webui/client/index.html (1 hunks)
  • components/log-viewer-webui/client/package.json (1 hunks)
  • components/log-viewer-webui/client/src/main.tsx (1 hunks)
  • components/log-viewer-webui/client/src/vite-env.d.ts (1 hunks)
  • components/log-viewer-webui/client/tsconfig.app.json (1 hunks)
  • components/log-viewer-webui/client/tsconfig.json (1 hunks)
  • components/log-viewer-webui/client/tsconfig.node.json (1 hunks)
  • components/log-viewer-webui/client/vite.config.ts (1 hunks)
  • components/log-viewer-webui/client/webpack.config.js (0 hunks)
💤 Files with no reviewable changes (1)
  • components/log-viewer-webui/client/webpack.config.js
✅ Files skipped from review due to trivial changes (1)
  • components/log-viewer-webui/client/src/vite-env.d.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/log-viewer-webui/client/tsconfig.json
🧰 Additional context used
📓 Path-based instructions (2)
components/log-viewer-webui/client/vite.config.ts (1)

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

components/log-viewer-webui/client/src/main.tsx (1)

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

🪛 Biome (1.9.4)
components/log-viewer-webui/client/tsconfig.node.json

[error] 9-9: JSON standard does not allow comments.

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: JSON standard does not allow comments.

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 17-17: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-24: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

components/log-viewer-webui/client/tsconfig.app.json

[error] 10-10: JSON standard does not allow comments.

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-18: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 18-18: JSON standard does not allow comments.

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 19-19: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 20-20: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 21-21: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 22-22: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 24-24: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-25: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 25-26: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

🔇 Additional comments (9)
components/log-viewer-webui/client/tsconfig.node.json (2)

9-14: Bundler configuration is well-suited for Vite

The bundler settings are appropriately configured for a Vite-based TypeScript project. The combination of moduleResolution: "bundler" with allowImportingTsExtensions and isolatedModules ensures compatibility with Vite's development and build processes.

🧰 Tools
🪛 Biome (1.9.4)

[error] 9-9: JSON standard does not allow comments.

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 10-10: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


23-23: Include pattern is appropriate

The include pattern correctly targets only the Vite configuration file, which is appropriate for a Node-specific TypeScript configuration.

🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-23: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 23-24: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)

components/log-viewer-webui/client/tsconfig.app.json (2)

10-16: LGTM! Bundler configuration is well-suited for Vite

The bundler mode settings are appropriately configured for a Vite-React application, with proper module resolution and JSX handling.

🧰 Tools
🪛 Biome (1.9.4)

[error] 10-10: JSON standard does not allow comments.

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 11-11: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 12-12: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 13-13: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 14-14: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 15-15: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


[error] 16-16: End of file expected

Use an array for a sequence of values: [1, 2]

(parse)


3-8: Consider the implications of skipLibCheck

The skipLibCheck option is enabled, which skips type-checking of declaration files. While this speeds up compilation, it might hide type errors from dependencies.

Run this script to check if any declaration files have known issues:

✅ Verification successful

skipLibCheck is appropriate for this configuration

Based on the analysis of the project structure and dependencies:

  • The project has minimal TypeScript declaration files (only vite-env.d.ts)
  • Uses modern dependencies with well-maintained type definitions
  • Is a Vite-based React application with TypeScript configuration
  • Has proper ESLint configuration for type checking

The skipLibCheck setting is justified here as:

  1. It speeds up the build process
  2. The project relies on well-tested npm packages
  3. Type checking is still performed on the project's source code
  4. The development setup includes ESLint for additional type safety
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential type issues in declaration files
# Look for .d.ts files with @ts-ignore or @ts-nocheck
rg -t ts "(@ts-ignore|@ts-nocheck)" --glob "*.d.ts"

Length of output: 53


Script:

#!/bin/bash
# Let's check for declaration files first to understand the scope
fd "\.d\.ts$"

# Also check package.json to understand dependencies that might need type checking
fd "package.json$" --exec cat {}

Length of output: 5294

components/log-viewer-webui/client/src/main.tsx (1)

9-10: Acknowledge use of non-null assertion.

The non-null assertion operator here, although acceptable, may hide potential null reference errors. An alternative approach could include a conditional check for the element’s existence, or an optional chaining with a fallback. Evaluate whether you want to rely on a strict assertion or implement a more defensive pattern.

components/log-viewer-webui/client/index.html (1)

1-18: Good choice of updated metadata and script handling.

The newly introduced script tag for TypeScript is properly defined, and the updated meta tags consistently reflect best practices for responsive design. This is a clear step towards a well-structured client application.

components/log-viewer-webui/client/package.json (2)

7-10: Confirm linting best practices.

With "lint:check": "eslint" and "lint:fix": "eslint --fix", ensure that the correct lint configurations (including TypeScript rules) are loaded. Otherwise, some TypeScript-specific issues may be overlooked.


24-29: Ensure TypeScript configuration is consistent.

You are referencing "typescript": "~5.6.2". Confirm that your tsconfig files align with the intended TS version. Also, maintain consistent TS practices across your devDependencies and build scripts.

Taskfile.yml (1)

227-232: Source files properly updated for TypeScript migration!

The changes correctly reflect the transition to TypeScript by:

  • Adding TypeScript configuration files
  • Including .ts and .tsx source files
  • Adding index.html for the client entry point

Comment thread Taskfile.yml Outdated
Comment on lines +250 to +257
- |-
cd "client"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--outDir "{{.OUTPUT_DIR}}/client"
- |-
cd "yscope-log-viewer"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix indentation in build commands

The build commands have inconsistent indentation which could cause YAML parsing issues.

Apply this diff to fix the indentation:

      - |-
        cd "client"
        PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
-        --outDir "{{.OUTPUT_DIR}}/client"
+          --outDir "{{.OUTPUT_DIR}}/client"
      - |-
        cd "yscope-log-viewer"
        PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
-        --output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"
+          --output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"
📝 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
- |-
cd "client"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--outDir "{{.OUTPUT_DIR}}/client"
- |-
cd "yscope-log-viewer"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"
- |-
cd "client"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--outDir "{{.OUTPUT_DIR}}/client"
- |-
cd "yscope-log-viewer"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
--output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (8)
Taskfile.yml (1)

250-257: Add comments to clarify the build tools in use.

While the build commands are well-structured, it would be helpful to add comments indicating that these are Vite and webpack builds respectively.

Apply this diff to improve clarity:

      - |-
        cd "client"
+       # Build the client using Vite
        PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
          --outDir "{{.OUTPUT_DIR}}/client"
      - |-
        cd "yscope-log-viewer"
+       # Build the log viewer using webpack
        PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run build -- \
          --output-path "{{.OUTPUT_DIR}}/yscope-log-viewer"
components/log-viewer-webui/client/src/api/query.ts (2)

9-16: Consider adding JSDoc comments to interface fields.

While the interface is well-structured, adding documentation for each field would improve code maintainability and make the purpose of each field clearer to other developers.

 interface ExtractStreamResp {
+    /** Unique identifier for the extraction job */
     _id: string;
+    /** Starting message index in the stream */
     begin_msg_ix: number;
+    /** Ending message index in the stream */
     end_msg_ix: number;
+    /** Indicates if this is the final chunk of the stream */
     is_last_chunk: boolean;
+    /** File path to the extracted stream */
     path: string;
+    /** Identifier of the stream being extracted */
     stream_id: string;
 }

19-44: Consider enhancing error handling and configuration.

Two suggestions for improvement:

  1. Add explicit error handling with typed error responses
  2. Consider making the API endpoint URL configurable

Example implementation:

interface ExtractStreamError {
    code: string;
    message: string;
}

const API_ENDPOINTS = {
    extractStream: '/query/extract-stream'
} as const;

const submitExtractStreamJob = async (
    extractJobType: QUERY_JOB_TYPE,
    streamId: string,
    logEventIdx: number,
    onUploadProgress: (progressEvent: AxiosProgressEvent) => void,
): Promise<AxiosResponse<ExtractStreamResp>> => {
    try {
        return await axios.post(
            API_ENDPOINTS.extractStream,
            {
                extractJobType,
                streamId,
                logEventIdx,
            },
            {onUploadProgress}
        );
    } catch (error) {
        if (axios.isAxiosError<ExtractStreamError>(error)) {
            // Handle specific API errors
            throw new Error(`Extract stream failed: ${error.response?.data.message}`);
        }
        throw error;
    }
};
components/log-viewer-webui/client/src/ui/Loading.tsx (5)

24-30: LGTM! Well-structured TypeScript interfaces.

The type definitions are clear and comprehensive. The use of the Nullable type for errorMsg shows good type reuse practices.

Consider making the props interfaces readonly to prevent accidental mutations:

-interface LoadingStepProps {
+interface LoadingStepProps {
+    readonly description: string;
+    readonly isActive: boolean;
+    readonly isError: boolean;
+    readonly label: string;
+    readonly stepIndicatorText: number | string;
 }

-interface LoadingProps {
+interface LoadingProps {
+    readonly currentState: QUERY_LOADING_STATE;
+    readonly errorMsg: Nullable<string>;
 }

Also applies to: 84-87


33-41: Enhance JSDoc documentation.

The JSDoc comments could be more descriptive and include return type information.

Consider updating the documentation:

 /**
- * Renders a step with a label and description.
+ * Renders a loading step with a label, description, and customizable indicator.
  *
  * @param props
  * @param props.description - Description text for the loading step
  * @param props.isActive - Whether this step is currently active
  * @param props.isError - Whether this step is in an error state
  * @param props.label - Label text for the loading step
  * @param props.stepIndicatorText - Text or number to display in the step indicator
- * @return
+ * @returns {JSX.Element} A styled step component
  */

Line range hint 50-57: Simplify color logic using ternary operator.

The color logic can be more concise while maintaining readability.

Consider this refactor:

-    let color: DefaultColorPalette = isActive ?
-        "primary" :
-        "neutral";
-
-    if (isError) {
-        color = "danger";
-    }
+    const color: DefaultColorPalette = isError ? "danger" : (isActive ? "primary" : "neutral");

131-134: Use TypeScript nullish checks.

Replace explicit null comparisons with TypeScript's nullish checking operator for better idiomatic TypeScript code.

Consider this refactor:

-                    determinate={null !== errorMsg}
-                    color={null === errorMsg ?
+                    determinate={!!errorMsg}
+                    color={errorMsg === null ?

101-102: Optimize steps array generation with useMemo.

The steps array is recreated on every render. Consider memoizing it to improve performance.

Consider this refactor:

-    const steps: React.ReactNode[] = [];
-    QUERY_LOADING_STATE_VALUES.forEach((state) => {
+    const steps = React.useMemo(() => {
+        const stepsArray: React.ReactNode[] = [];
+        QUERY_LOADING_STATE_VALUES.forEach((state) => {

Then wrap the entire steps generation logic in the useMemo hook with appropriate dependencies:

    }, [currentState, errorMsg]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8b03576 and 7ac39ee.

⛔ Files ignored due to path filters (1)
  • components/log-viewer-webui/client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • Taskfile.yml (2 hunks)
  • components/log-viewer-webui/client/eslint.config.mjs (1 hunks)
  • components/log-viewer-webui/client/src/api/query.ts (1 hunks)
  • components/log-viewer-webui/client/src/typings/LOCAL_STORAGE_KEY.ts (1 hunks)
  • components/log-viewer-webui/client/src/typings/query.ts (1 hunks)
  • components/log-viewer-webui/client/src/ui/Loading.tsx (4 hunks)
  • components/log-viewer-webui/client/vite.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/log-viewer-webui/client/src/typings/LOCAL_STORAGE_KEY.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • components/log-viewer-webui/client/vite.config.ts
  • components/log-viewer-webui/client/src/typings/query.ts
🧰 Additional context used
📓 Path-based instructions (2)
components/log-viewer-webui/client/src/api/query.ts (1)

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

components/log-viewer-webui/client/src/ui/Loading.tsx (1)

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

🔇 Additional comments (9)
Taskfile.yml (1)

227-232: LGTM! Source file patterns updated for TypeScript.

The changes correctly reflect the migration from JSX to TypeScript by:

  • Adding TypeScript configuration files
  • Including the Vite entry point (index.html)
  • Updating source patterns from .jsx to .ts and .tsx
components/log-viewer-webui/client/src/api/query.ts (2)

1-7: LGTM! Well-structured imports.

The imports are properly organized with specific type imports from axios and a clear separation between external and local imports.


46-46: LGTM! Clear and explicit export.

The named export is appropriate and follows TypeScript best practices.

components/log-viewer-webui/client/eslint.config.mjs (6)

1-4: Configuration imports look consistent and aligned with best practices.

Importing the CommonConfig, ReactConfigArray, StylisticConfigArray, and TsConfigArray modules in this manner is idiomatic and helps ensure that these configurations remain modular and comprehendible.


7-13: Folder ignore patterns are appropriate.

Excluding the dist/ and node_modules/ folders from linting is a standard practice, preventing unnecessary checks on distribution builds and third-party packages.


14-23: Effective integration of TsConfigArray.

Aggregating multiple TypeScript configurations using a map function keeps your ESLint rules DRY while extending coverage to both .ts and .tsx files. This approach aligns well with TypeScript-based React projects.


24-34: Targeted overrides for different TypeScript configurations.

Using createTsConfigOverride to specify distinct tsconfig.app.json versus tsconfig.node.json is beneficial for large repositories with diverse environments, as it offers clarity and maintainability. These overrides help ensure TypeScript is correctly configured for client (app) and build-tool (node) code.


35-37: Stylistic and React rules are seamlessly merged.

Adding StylisticConfigArray and ReactConfigArray ensures consistent style enforcement and React-specific linting, promoting maintainable and uniform code across the project.


40-40: Export statement follows modern ECMAScript standards.

Exporting EslintConfig as the default helps with discoverability and import clarity in other parts of the build setup. No issues identified.

<title>Log Viewer Web UI</title>
<meta charset="utf-8"/>
<meta name="description" content="YScope Log Viewer Web UI">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is copied from the Vite react-ts tempalte.

</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is copied from the Vite react-ts tempalte.

<!doctype html>
<html lang="en">
<head>
<title>Log Viewer Web UI</title>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added " Web UI"

<head>
<title>Log Viewer Web UI</title>
<meta charset="utf-8"/>
<meta name="description" content="YScope Log Viewer Web UI">

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added " Web UI"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This needs to be updated once y-scope/eslint-config-yscope#3 is merged and a new version is published.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This comment no longer applies.

The linting rules are indeed ported to tsconfig.node.ts and tsconfig.app.ts though.

},
};

export default () => {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The attempt to migrate to Vite was effortless and they provide all what we need with very simple configuration interfaces. I think we can stick with Vite in this project.

@junhaoliao junhaoliao changed the title chore(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript. build(log-viewer-webui-client): Switch from Webpack to Vite for bundling; Convert the codebase to TypeScript. Dec 29, 2024
@junhaoliao junhaoliao requested review from davemarco and haiqi96 and removed request for kirkrodrigues January 3, 2025 17:22
@junhaoliao

Copy link
Copy Markdown
Member Author

hey
@haiqi96 : can you help take a look at the Taskfile.yml and see if the changes make sense?
@davemarco : can you review the rest?

@davemarco

davemarco commented Jan 6, 2025

Copy link
Copy Markdown
Contributor

@davemarco : can you review the rest?

Sure I will review everything except task file.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (2)
components/log-viewer-webui/client/src/typings/query.ts (2)

2-3: Consider reducing extra empty lines.

There are two consecutive empty lines after the import statement. For consistency, consider keeping just one empty line.

import {Type} from "@sinclair/typebox";

-

74-77: Fix capitalization in label text.

There's a minor capitalization inconsistency in the label text.

-            label: "Submitting query Job",
+            label: "Submitting query job",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c7bc2c0 and a95e269.

📒 Files selected for processing (2)
  • components/log-viewer-webui/client/eslint.config.mjs (1 hunks)
  • components/log-viewer-webui/client/src/typings/query.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/log-viewer-webui/client/eslint.config.mjs
🧰 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>.

  • components/log-viewer-webui/client/src/typings/query.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: build-macos (macos-15, false)
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: build-macos (macos-14, true)
🔇 Additional comments (5)
components/log-viewer-webui/client/src/typings/query.ts (5)

4-7: Add more detailed description for the enum values.

The enum is well documented with a general description, but adding individual descriptions for each state value would improve clarity and maintainability.


18-23: Well implemented constant with proper immutability.

Good use of Object.freeze to ensure immutability, and the filter expression follows the coding guideline by using "number" === typeof value instead of typeof value === "number" or !isNaN(value).


35-41: Well defined mapping with proper immutability.

Good use of Object.freeze to ensure the mapping is immutable. The mapping between extract job type enums and stream type is clear and well-documented.


43-52: Well structured type definition for extract job parameters.

The ExtractJobSearchParams type definition clearly specifies the required URL search parameters for extract jobs. The use of Type.Union with mapped literals ensures type safety for the job type parameter.


88-97: Exports are well-organized.

Good separation between type exports and value exports. The export pattern is consistent and makes it clear what's available from this module.

@junhaoliao junhaoliao requested a review from davemarco March 17, 2025 03:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 (1)
Taskfile.yml (1)

270-278: Refactor build commands using a loop for clarity and consistency.
The updated for: loop that iterates over the client and yscope-log-viewer builds introduces explicit build flags ("--emptyOutDir --outDir" for the client and "--output-path" for yscope-log-viewer). Please confirm that these flags are precisely what is required for the respective build processes with Vite and that the YAML indentation meets the required syntax. This approach improves clarity in the build process.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a95e269 and 823fde8.

📒 Files selected for processing (1)
  • Taskfile.yml (2 hunks)
🔇 Additional comments (2)
Taskfile.yml (2)

246-248: Addition of TypeScript-specific source entries.
The inclusion of "client/index.html", "client/tsconfig/**/*", and "client/tsconfig.json" supports the transition to TypeScript. Please verify that these paths and glob patterns correctly reflect the intended file structure and that all essential configuration files are captured.


251-252: Inclusion of TypeScript source file patterns.
The new source patterns "client/src/**/*.ts" and "client/src/**/*.tsx" appropriately replace the previous JSX patterns, aligning with the PR objectives for converting the codebase to TypeScript. Ensure that there are no remnants of the old file types that might lead to confusion.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (1)

79-80: ⚠️ Potential issue

Sanitize URL parameters to prevent XSS.

The URL construction should sanitize the parameters to prevent potential XSS attacks.

-                window.location.href = `/log-viewer/index.html?filePath=${data.path}` +
-                    `#logEventNum=${innerLogEventNum}`;
+                const sanitizeParam = (param: string): string => {
+                    return encodeURIComponent(param.replace(/[<>'"]/g, ''));
+                };
+                window.location.href = `/log-viewer/index.html?filePath=${sanitizeParam(data.path)}` +
+                    `#logEventNum=${sanitizeParam(String(innerLogEventNum))}`;
🧹 Nitpick comments (2)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (2)

83-93: Simplify error message extraction from Axios errors.

The nested conditionals for extracting error messages can be simplified for better readability.

-                let msg = "Unknown error.";
-                if (isAxiosError<{message: string}>(e)) {
-                    msg = e.message;
-                    if ("undefined" !== typeof e.response) {
-                        if ("undefined" !== typeof e.response.data.message) {
-                            msg = e.response.data.message;
-                        } else {
-                            msg = e.response.statusText;
-                        }
-                    }
-                }
+                let msg = "Unknown error.";
+                if (isAxiosError<{message: string}>(e)) {
+                    if (e.response?.data?.message) {
+                        msg = e.response.data.message;
+                    } else if (e.response?.statusText) {
+                        msg = e.response.statusText;
+                    } else {
+                        msg = e.message;
+                    }
+                }

86-87: Use consistent null checks.

Following the coding guidelines, prefer using Yoda conditions for consistency.

-                    if ("undefined" !== typeof e.response) {
-                        if ("undefined" !== typeof e.response.data.message) {
+                    if ("undefined" !== typeof e.response) {
+                        if ("undefined" !== typeof e.response.data.message) {

Note: This is already using the guideline syntax. The alternative approach would be to use optional chaining as shown in the refactoring suggestion above, which would be even cleaner.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7218b38 and 993a3fa.

📒 Files selected for processing (1)
  • components/log-viewer-webui/client/src/ui/QueryStatus.tsx (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/ui/QueryStatus.tsx
🧬 Code Definitions (1)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (3)
components/log-viewer-webui/client/src/typings/query.ts (3) (3)
  • QUERY_LOADING_STATE (94-94)
  • ExtractJobSearchParams (92-92)
  • EXTRACT_JOB_TYPE (91-91)
components/log-viewer-webui/client/src/typings/common.ts (1) (1)
  • Nullable (3-3)
components/log-viewer-webui/client/src/api/query.ts (1) (1)
  • submitExtractStreamJob (39-39)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-lint
  • GitHub Check: build-macos (macos-15, true)
  • GitHub Check: build (macos-latest)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)
🔇 Additional comments (5)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (5)

23-23: Good approach moving the flag outside the component to prevent double execution.

The approach to move isFirstRun outside the component function follows React's recommendations for initializing applications. This ensures the flag is properly shared across re-renders while preventing duplicate query executions triggered by React's StrictMode.


37-45: The TODO comment provides clear context for the workaround.

The TODO comment clearly explains the reason for using this approach and provides direction for future improvements. The workaround effectively prevents duplicate execution of the effect in React's StrictMode, which is important given the server concurrency issues mentioned.


47-62: Good implementation of URL parameter validation with TypeBox.

The parameter validation approach using TypeBox's Value.Parse with a predefined schema is robust and type-safe. The error handling properly catches and formats validation errors, providing clear feedback to users when parameters are invalid.


67-68: The type assertion is necessary but properly documented.

The use of as keyof typeof EXTRACT_JOB_TYPE is necessary for TypeScript to understand that the string from parseResult will be a valid key. The comment explains this well, making the code maintainable.


16-18: Consider defining EXTRACT_JOB_TYPE in a dedicated file.

As mentioned in previous review comments, EXTRACT_JOB_TYPE should probably be declared in typings/query.ts to keep related types together.

@davemarco davemarco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Okay I am good with it. There are some minor nits. Please test it again that it actually works. I will approve after minor nits. Also this is still not resolved - #645 (comment)

Comment thread components/log-viewer-webui/client/src/main.tsx Outdated
Comment thread components/log-viewer-webui/client/src/ui/QueryStatus.tsx Outdated
junhaoliao and others added 2 commits March 21, 2025 17:34
…ode review

Co-authored-by: davemarco <83603688+davemarco@users.noreply.github.com>
…review

Co-authored-by: davemarco <83603688+davemarco@users.noreply.github.com>
@junhaoliao junhaoliao requested a review from davemarco March 21, 2025 21:55

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (1)

81-83: ⚠️ Potential issue

Sanitize URL parameters to prevent potential XSS.

The URL construction does not sanitize the parameters, which could potentially lead to XSS vulnerabilities.

Consider sanitizing the parameters before constructing the URL:

- const innerLogEventNum = parseResult.logEventIdx - data.begin_msg_ix + 1;
- window.location.href = `/log-viewer/index.html?filePath=${data.path}` +
-     `#logEventNum=${innerLogEventNum}`;
+ const innerLogEventNum = parseResult.logEventIdx - data.begin_msg_ix + 1;
+ // Sanitize parameters to prevent XSS
+ const sanitizedPath = encodeURIComponent(data.path);
+ const sanitizedLogEventNum = encodeURIComponent(String(innerLogEventNum));
+ window.location.href = `/log-viewer/index.html?filePath=${sanitizedPath}` +
+     `#logEventNum=${sanitizedLogEventNum}`;
🧹 Nitpick comments (1)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (1)

67-77: Type assertion could be improved for better type safety.

The type assertion on line 71 is necessary but could potentially be handled in a more type-safe manner.

Consider using a type guard or validation step to ensure type safety without using the as keyword:

- EXTRACT_JOB_TYPE[parseResult.type as keyof typeof EXTRACT_JOB_TYPE],
+ // Verify that parseResult.type is a valid key in EXTRACT_JOB_TYPE
+ ((type: string): number => {
+   if (!(type in EXTRACT_JOB_TYPE)) {
+     throw new Error(`Invalid extract job type: ${type}`);
+   }
+   return EXTRACT_JOB_TYPE[type as keyof typeof EXTRACT_JOB_TYPE];
+ })(parseResult.type),

Alternatively, if you're confident the validation from TypeBox ensures parseResult.type will always be valid:

- // `parseResult.type` must be valid key since parsed using with typebox type
- // `ExtractJobSearchParams`.
- EXTRACT_JOB_TYPE[parseResult.type as keyof typeof EXTRACT_JOB_TYPE],
+ // TypeBox validation ensures parseResult.type is valid
+ EXTRACT_JOB_TYPE[parseResult.type as keyof typeof EXTRACT_JOB_TYPE],
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9faef13 and 1ff4986.

📒 Files selected for processing (1)
  • components/log-viewer-webui/client/src/ui/QueryStatus.tsx (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/ui/QueryStatus.tsx
🧬 Code Definitions (1)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (3)
components/log-viewer-webui/client/src/typings/query.ts (3) (3)
  • QUERY_LOADING_STATE (94-94)
  • ExtractJobSearchParams (92-92)
  • EXTRACT_JOB_TYPE (91-91)
components/log-viewer-webui/client/src/typings/common.ts (1) (1)
  • Nullable (3-3)
components/log-viewer-webui/client/src/api/query.ts (1) (1)
  • submitExtractStreamJob (39-39)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: ubuntu-jammy-lint
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build-macos (macos-13, true)
  • GitHub Check: build-macos (macos-13, false)
🔇 Additional comments (6)
components/log-viewer-webui/client/src/ui/QueryStatus.tsx (6)

1-20: LGTM: Imports are well-organized and appropriate.

The imports are logically grouped and include all necessary dependencies. The component correctly imports validation utilities from TypeBox, HTTP request utilities from Axios, and internal application modules.


23-26: Global flag is a temporary workaround.

This global flag implementation is documented as a workaround for preventing duplicate execution of the useEffect hook. It's properly documented with a comment that explains its purpose.

Note that while this approach works, it's a temporary solution as indicated by the TODO comment on lines 40-42. Consider prioritizing the resolution of server-side concurrency issues to implement a cleaner solution with AbortController.


33-38: LGTM: Component state is properly initialized.

The component correctly initializes the query state to SUBMITTING and error message to null using useState hooks with appropriate TypeScript typing.


50-65: Robust URL parameter validation implementation.

The parameter validation implementation is thorough and handles errors appropriately:

  1. Parameters are extracted from the URL
  2. They're validated against a schema
  3. Validation errors are caught and provide detailed feedback

This approach prevents invalid parameters from being processed further.


85-95: LGTM: Comprehensive error handling with detailed messages.

The error handling is robust and provides detailed error messages for both generic and Axios-specific errors. The component correctly differentiates between different error types and extracts the most relevant error message.


98-103: LGTM: Component rendering is clean and passes appropriate props.

The component correctly renders the Loading component with the current state and error message as props.

@davemarco davemarco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved - conditional on your testing that it still works.

@junhaoliao junhaoliao merged commit fc1fe7c into y-scope:main Mar 24, 2025
@coderabbitai coderabbitai Bot mentioned this pull request May 5, 2025
3 tasks
@junhaoliao junhaoliao deleted the log-viewer-webui-client-ts branch May 7, 2026 19:46
junhaoliao added a commit to junhaoliao/clp that referenced this pull request May 17, 2026
…ing; Convert the codebase to TypeScript. (y-scope#645)

Co-authored-by: davemarco <83603688+davemarco@users.noreply.github.com>
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.

4 participants