Skip to content

feat(new-webui): Support loading injected client-side settings.json at app startup.#995

Merged
hoophalab merged 5 commits into
y-scope:mainfrom
hoophalab:client-settings
Jun 10, 2025
Merged

feat(new-webui): Support loading injected client-side settings.json at app startup.#995
hoophalab merged 5 commits into
y-scope:mainfrom
hoophalab:client-settings

Conversation

@hoophalab

@hoophalab hoophalab commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

Description

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

Summary by CodeRabbit

  • Chores
    • Updated configuration loading to use a TypeScript module for application settings instead of direct JSON imports.
    • Improved error handling when loading settings from the server.
    • Removed obsolete comments related to configuration management.

@hoophalab hoophalab requested a review from a team as a code owner June 10, 2025 01:31
@coderabbitai

coderabbitai Bot commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes refactor how configuration settings are loaded in the client application. Imports previously referencing a static JSON file are updated to import settings from a new TypeScript module, which asynchronously loads and parses the configuration at runtime. Some comments related to configuration were also removed.

Changes

File(s) Change Summary
.../client/src/pages/IngestPage/sqlConfig.ts Removed two comment lines related to TODO and ESLint directives before the SQL_CONFIG enum.
.../client/src/pages/SearchPage/SearchState/useResultsMetadata.ts Changed settings import from direct JSON to named import from new settings module.
.../client/src/config/index.ts Updated settings import to use the new settings module instead of direct JSON.
.../client/src/settings.ts Added new module: defines Settings type, loads settings.json asynchronously, exports settings.

Sequence Diagram(s)

sequenceDiagram
    participant ClientApp
    participant SettingsModule
    participant Server

    ClientApp->>SettingsModule: import { settings }
    SettingsModule->>Server: GET /settings.json
    Server-->>SettingsModule: settings.json (JSON)
    SettingsModule-->>SettingsModule: Parse and validate JSON
    SettingsModule-->>ClientApp: Export parsed settings object
Loading

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f5d154 and b2c9a9f.

📒 Files selected for processing (2)
  • components/log-viewer-webui/client/src/config/index.ts (1 hunks)
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • components/log-viewer-webui/client/src/config/index.ts
  • components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts
🔇 Additional comments (2)
components/log-viewer-webui/client/src/config/index.ts (1)

1-1:

Details

✅ Verification successful

Verify synchronous availability of imported settings
Ensure that the settings object from ../settings is fully populated when this module executes. If settings.ts loads data asynchronously (e.g., via HTTP), settings.ClpStorageEngine could be undefined at import time, causing downstream errors.

Use the following script to inspect settings.ts and verify whether loading is synchronous or asynchronous:


🏁 Script executed:

#!/bin/bash
# Check for async HTTP calls in settings.ts
rg -n "axios.get" -n components/log-viewer-webui/client/src/settings.ts

Length of output: 143


🏁 Script executed:

#!/bin/bash
# Inspect how settings is used within the config module
sed -n '1,200p' components/log-viewer-webui/client/src/config/index.ts

Length of output: 519


🏁 Script executed:

#!/bin/bash
# Print the contents of settings.ts to inspect export and population logic
sed -n '1,200p' components/log-viewer-webui/client/src/settings.ts

Length of output: 850


Confirmed synchronous availability of settings.ClpStorageEngine
The settings.ts module uses a top-level await loadSettings(), so the export isn’t resolved until the HTTP fetch completes. When you import settings in config/index.ts, settings.ClpStorageEngine is guaranteed to be defined—provided your build targets ES modules with top-level‐await support.

components/log-viewer-webui/client/src/pages/SearchPage/SearchState/useResultsMetadata.ts (1)

5-5:

Details

✅ Verification successful

Verify synchronous availability of the injected settings object

The hook dereferences settings immediately after import, but the new settings.ts module (introduced in this PR) reportedly fetches and populates the object asynchronously at app start-up. If that population hasn’t completed by the time this hook runs, settings.MongoDbSearchResultsMetadataCollectionName will be undefined, leading to a runtime error downstream in MongoCollectionSocket.

Please confirm that settings is guaranteed to be fully initialised before any React component renders, or add a defensive guard / loading gate.


🏁 Script executed:

#!/bin/bash
# Search for an explicit initialisation routine that ensures settings are ready
# before React mounts.  We expect to find something like `await loadSettings()`
# in the app bootstrap.
rg -n --type ts -e 'loadSettings|initSettings|settingsReady'

Length of output: 273


🏁 Script executed:

#!/bin/bash
# Display the top of the settings.ts to inspect if it uses top-level await
sed -n '1,50p' components/log-viewer-webui/client/src/settings.ts

Length of output: 849


🏁 Script executed:

#!/bin/bash
# Locate tsconfig.json and show compilerOptions for module/target support
if [[ -f tsconfig.json ]]; then
  echo "=== tsconfig.json ==="
  sed -n '1,200p' tsconfig.json
else
  echo "tsconfig.json not found at root, searching..."
  find . -maxdepth 3 -type f -name 'tsconfig.json'
fi

echo
# Inspect package.json to determine bundler and script setup
if [[ -f package.json ]]; then
  echo "=== package.json (first 200 lines) ==="
  sed -n '1,200p' package.json
fi

echo
# Find common bundler configuration files
echo "=== Bundler config files ==="
find . -maxdepth 3 -type f \( -name 'webpack.config.js' -o -name 'vite.config.js' -o -name 'rollup.config.js' \)

Length of output: 392


🏁 Script executed:

#!/bin/bash
# Search for tsconfig.json, package.json, and bundler configs anywhere in the repo
echo "=== tsconfig.json files ==="
find . -type f -name 'tsconfig.json'

echo
echo "=== package.json files ==="
find . -type f -name 'package.json'

echo
echo "=== Bundler configuration files ==="
find . -type f \( -name 'webpack.config.js' -o -name 'vite.config.js' -o -name 'rollup.config.js' \)

Length of output: 762


🏁 Script executed:

#!/bin/bash
# Inspect the client-side TypeScript configuration for module/target settings
echo "=== components/log-viewer-webui/client/tsconfig.json ==="
sed -n '1,200p' components/log-viewer-webui/client/tsconfig.json

echo
# Inspect the client-side package.json for build tool or scripts
echo "=== components/log-viewer-webui/client/package.json ==="
sed -n '1,200p' components/log-viewer-webui/client/package.json

Length of output: 1945


🏁 Script executed:

#!/bin/bash
# Inspect the client-side application TypeScript config for module and target settings
sed -n '1,200p' components/log-viewer-webui/client/tsconfig/tsconfig.app.json

Length of output: 750


Settings import is safe—no guard needed
The settings.ts module employs a top-level await (const settings: Settings = await loadSettings();) and your client TS config (target: "ES2022", module: "ESNext") together with Vite’s bundler preserves this behaviour. Any module importing settings will not execute until the JSON fetch completes. It’s therefore safe to dereference settings.MongoDbSearchResultsMetadataCollectionName immediately in the hook.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot]

This comment was marked as outdated.

@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

♻️ Duplicate comments (2)
components/log-viewer-webui/client/src/settings.ts (2)

27-27: Consider lazy loading instead of top-level await.


18-25: 🛠️ Refactor suggestion

Add runtime validation for the response data.

While axios handles HTTP errors automatically, there's no validation that the returned data matches the expected Settings structure. The generic type parameter provides compile-time typing but doesn't guarantee runtime safety.

 const loadSettings = async (): Promise<Settings> => {
     try {
         const response = await axios.get<Settings>("settings.json");
-        return response.data;
+        const data = response.data;
+        // Basic validation - ensure required properties exist
+        if ("object" !== typeof data || null === data || 
+            "string" !== typeof data.MongoDbSearchResultsMetadataCollectionName ||
+            "string" !== typeof data.ClpStorageEngine) {
+            throw new Error("Invalid settings format: missing required properties");
+        }
+        return data;
     } catch (e: unknown) {
         throw new Error("Failed to fetch settings.", {cause: e});
     }
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd1b433 and 5f5d154.

📒 Files selected for processing (1)
  • components/log-viewer-webui/client/src/settings.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ` rather than `!`.

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

  • components/log-viewer-webui/client/src/settings.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: lint-check (macos-latest)

Comment on lines +15 to +16
* @return
* @throws {Error} If the fetch or JSON parsing fails, an error is thrown with the original cause.

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.

🧹 Nitpick (assertive)

Complete the incomplete @return documentation.

The @return tag is missing its description, which reduces the documentation's usefulness.

- * @return
+ * @return A Promise that resolves to the parsed Settings object.
📝 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
* @return
* @throws {Error} If the fetch or JSON parsing fails, an error is thrown with the original cause.
* @return A Promise that resolves to the parsed Settings object.
* @throws {Error} If the fetch or JSON parsing fails, an error is thrown with the original cause.
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/settings.ts around lines 15 to 16, the
JSDoc comment has an incomplete @return tag. Complete the @return tag by adding
a clear description of what the function returns, specifying the type and
meaning of the returned value to improve documentation clarity.

@hoophalab hoophalab requested a review from junhaoliao June 10, 2025 01:47
junhaoliao
junhaoliao previously approved these changes Jun 10, 2025

@junhaoliao junhaoliao left a comment

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.

for the PR title, is this better?

feat(new-webui): Support loading injected client-side settings.json at app startup.

@hoophalab hoophalab changed the title feat(new-webui): Use modifiable settings.json in client. feat(new-webui): Support loading injected client-side settings.json at app startup. Jun 10, 2025
@hoophalab hoophalab merged commit d994430 into y-scope:main Jun 10, 2025
7 checks passed
@hoophalab hoophalab deleted the client-settings branch July 8, 2025 19:42
junhaoliao pushed a commit to junhaoliao/clp that referenced this pull request May 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants