Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Mar 17, 2025

Summary by CodeRabbit

  • New Features

    • Improved deployment commands now allow specifying a target server, streamlining the deployment process.
    • Enhanced settings synchronization provides clear feedback on when a system restart is required after updates.
    • Automatic service restart is now triggered after applying connection settings changes.
    • User interface enhancements include added contextual descriptions for toggle controls.
    • New functionality to refetch connection settings after updates, providing users with the latest information.
  • Bug Fixes

    • Improved user feedback regarding API restart status after settings updates.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2025

Walkthrough

This pull request makes several changes to improve deployment commands and settings management. In the API justfile, the deployment command now accepts a remote parameter, and clearer aliases replace the shorthand. The ConnectSettingsService, ConnectResolver, and ConnectService in the unraid API have updated function signatures, refined logic for sandbox mode, and added API restart functionality after settings updates. Additionally, a computed property for descriptions is added in the Switch component, and the ConnectSettings component now includes a refetch mechanism with restart notifications.

Changes

File(s) Change Summary
api/justfile Updated deployment command to @deploy remote: with a parameter; removed bd shorthand and introduced distinct aliases: alias b := build and alias d := deploy.
api/src/unraid-api/graph/connect/*.ts In connect-settings.service.ts: Updated syncSettings method to return a boolean; updated setSandboxMode and sandboxSlice signatures and logic.
In connect.resolver.ts: Added ConnectService dependency to trigger API restart after settings update.
In connect.service.ts: Added a new restartApi method using execa with logging.
unraid-ui/src/forms/Switch.vue Introduced a new computed property description to conditionally render additional context text from schema options.
web/components/ConnectSettings/ConnectSettings.ce.vue Updated useQuery hook to include a refetch method; added a computed property restartRequired and updated submission logic to notify users if the API will restart after applying settings.

Possibly related PRs

  • fix(api): logrotate modification & permissions #1145: The changes in the main PR focus on updating deployment commands and aliases in the api/justfile, while the retrieved PR modifies the setup, @build, and bd recipes in the same file, indicating a direct relationship in terms of modifications to the same commands and aliases.

Suggested reviewers

  • mdatelle
  • elibosley

Poem

Code blossoms in a fresh new light,
Commands refined, making deployment bright.
Services whisper changes with a gentle restart,
Switches and queries now play their part.
A joyful dance in our code, a true work of art!
🚀✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between bb73e1f and 114bd11.

📒 Files selected for processing (1)
  • api/src/unraid-api/graph/connect/connect.resolver.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/src/unraid-api/graph/connect/connect.resolver.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Test API
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Cloudflare Pages

🪧 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

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

CodeRabbit Configuration File (.coderabbit.yaml)

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

Documentation and Community

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (2)
api/src/unraid-api/graph/connect/connect.resolver.ts (1)

70-77: Well-implemented restart logic.

The implementation correctly checks if a restart is required after syncing settings and schedules the restart with a delay to allow the current request to complete.

One suggestion: consider extracting the timeout value to a constant for better maintainability.

+    private readonly API_RESTART_DELAY_MS = 3_000;
     
     public async updateApiSettings(@Args('input') settings: ApiSettingsInput) {
         this.logger.verbose(`Attempting to update API settings: ${JSON.stringify(settings, null, 2)}`);
         const restartRequired = await this.connectSettingsService.syncSettings(settings);
         const currentSettings = await this.connectSettingsService.getCurrentSettings();
         if (restartRequired) {
             setTimeout(async () => {
                 await this.connectService.restartApi();
-            }, 3_000);
+            }, this.API_RESTART_DELAY_MS);
         }
         return currentSettings;
     }
api/src/unraid-api/graph/connect/connect-settings.service.ts (1)

274-274: Indentation issue in description string.

The static analysis tool indicates an indentation issue with this line.

-        const description = 'The developer sandbox is available at <code><a class="underline" href="/graphql" target="_blank">/graphql</a></code>.';
+        const description = 'The developer sandbox is available at <code><a class="underline" href="/graphql" target="_blank">/graphql</a></code>.';

Split the string across multiple lines with proper indentation for better readability:

-        const description = 'The developer sandbox is available at <code><a class="underline" href="/graphql" target="_blank">/graphql</a></code>.';
+        const description = 
+            'The developer sandbox is available at <code><a class="underline" href="/graphql" target="_blank">/graphql</a></code>.';
🧰 Tools
🪛 GitHub Check: Build API

[failure] 274-274:
Insert ⏎···········

🪛 GitHub Check: Test API

[failure] 274-274:
Insert ⏎···········

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 6f9fa10 and e3e878d.

📒 Files selected for processing (6)
  • api/justfile (1 hunks)
  • api/src/unraid-api/graph/connect/connect-settings.service.ts (5 hunks)
  • api/src/unraid-api/graph/connect/connect.resolver.ts (2 hunks)
  • api/src/unraid-api/graph/connect/connect.service.ts (1 hunks)
  • unraid-ui/src/forms/Switch.vue (2 hunks)
  • web/components/ConnectSettings/ConnectSettings.ce.vue (6 hunks)
🧰 Additional context used
🪛 GitHub Check: Build API
api/src/unraid-api/graph/connect/connect.resolver.ts

[failure] 20-20:
import statements should have an absolute path

api/src/unraid-api/graph/connect/connect-settings.service.ts

[failure] 274-274:
Insert ⏎···········

🪛 GitHub Check: Test API
api/src/unraid-api/graph/connect/connect.resolver.ts

[failure] 20-20:
import statements should have an absolute path

api/src/unraid-api/graph/connect/connect-settings.service.ts

[failure] 274-274:
Insert ⏎···········

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (20)
unraid-ui/src/forms/Switch.vue (2)

2-3: Good implementation of the description computed property.

The computed property correctly extracts the description from the uischema options, providing a clean way to access this data.

Also applies to: 17-17


22-22: Consider the security implications of using v-html.

While v-html works well for rendering HTML content in the description, be aware that it bypasses Vue's built-in XSS protections. If the description content comes from user input or an untrusted source, this could pose a security risk.

Consider using a safer alternative if the HTML rendering isn't strictly necessary:

-    <p v-if="description" v-html="description" class="mb-2"></p>
+    <p v-if="description" class="mb-2">{{ description }}</p>

Or if HTML is required, ensure the content is sanitized before display.

api/src/unraid-api/graph/connect/connect.service.ts (1)

1-3: Good implementation of the API restart functionality.

The implementation correctly handles error logging and uses execa to execute the shell command. The Logger is properly instantiated with the class name for context.

Also applies to: 7-14

api/justfile (2)

12-13: Good enhancement to the deploy command.

Adding a remote parameter to the deploy command improves flexibility by allowing deployment to different targets.


15-16: Clear and intuitive aliases.

The aliases 'b' and 'd' are intuitive shorthand for build and deploy, making the commands easier to use.

api/src/unraid-api/graph/connect/connect.resolver.ts (1)

25-28: Good dependency injection of ConnectService.

The constructor properly injects the ConnectService, following dependency injection best practices.

web/components/ConnectSettings/ConnectSettings.ce.vue (7)

8-8: Import reorganization looks good.

The imports have been reorganized in a cleaner way, using destructuring to import multiple components from the @unraid/ui package in a single line.


20-20: Good update to destructure the refetch function.

Now destructuring both result and refetch from the useQuery hook. This is necessary to support the new functionality that refreshes settings after updates.


30-32: Effective implementation of restart detection.

The restartRequired computed property correctly checks if the sandbox setting has changed, which will determine if an API restart is needed after applying settings.


60-62: Enhanced user feedback with conditional restart notification.

The success toast now includes additional context about the API restarting when relevant, which improves the user experience by providing clear feedback about what's happening.


74-74: Simplified renderer declaration.

The renderers array declaration is now more concise using the spread operator.


80-80: Important addition of refetch after mutation.

Adding a refetch after updating settings ensures the UI displays the latest data from the backend after changes are applied.


119-119: Clear user notification about restart.

This informative message clearly communicates to users that the API will restart after settings are applied when necessary, setting appropriate expectations.

api/src/unraid-api/graph/connect/connect-settings.service.ts (7)

64-66: Return type for syncSettings improved with documentation.

The method now explicitly returns a boolean to indicate whether a restart is required, and this is properly documented. This enhances the API contract clarity.

Also applies to: 98-99


67-67: Good use of flag variable.

The restartRequired flag is effectively used to track restart requirements throughout the method.


94-94: Elegant use of compound assignment operator.

Using the ||= operator to accumulate restart status is a concise approach that ensures any restart requirement from any setting change is captured.


107-118: Well-documented and improved sandbox mode setter.

The method has been enhanced to:

  1. Clearly document its purpose and return value
  2. Check if the sandbox mode actually changed before applying updates
  3. Return a boolean indicating whether a change occurred

This prevents unnecessary restarts when the value hasn't changed.


152-152: Correctly updated to await the result.

Updated to properly await the now-async sandboxSlice method.


272-274: Made sandboxSlice method async for better state access.

Converting the method to async allows it to fetch the current sandbox state, which is used to determine whether to show the description.

🧰 Tools
🪛 GitHub Check: Build API

[failure] 274-274:
Insert ⏎···········

🪛 GitHub Check: Test API

[failure] 274-274:
Insert ⏎···········


290-290: Good conditional description display.

Only showing the description when sandbox is enabled improves user experience by providing relevant information exactly when needed.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
api/src/unraid-api/graph/connect/connect.resolver.ts (1)

69-77: Added API restart logic when settings require it

The updateApiSettings method now checks if a restart is required after syncing settings, and if so, schedules an API restart after a 3-second delay. This allows the response to be sent to the client before restarting.

Consider extracting the 3000ms delay to a named constant for better readability and maintainability:

-            }, 3_000);
+            }, API_RESTART_DELAY_MS);

Where API_RESTART_DELAY_MS would be defined as a class property or module constant.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between ac103e2 and bb73e1f.

📒 Files selected for processing (1)
  • api/src/unraid-api/graph/connect/connect.resolver.ts (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
api/src/unraid-api/graph/connect/connect.resolver.ts (1)
api/src/graphql/generated/api/types.ts (2) (2)
  • Resolver (1862:1862)
  • ConnectResolvers (2297:2302)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build Web App
  • GitHub Check: Build API
  • GitHub Check: Test API
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
api/src/unraid-api/graph/connect/connect.resolver.ts (2)

19-19: Import added for ConnectService using absolute path

This correctly follows the project's convention of using absolute paths for imports, addressing a previously flagged issue.


24-27: Properly injected ConnectService dependency

The constructor has been updated to include the ConnectService as a dependency, following good dependency injection practices.

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1232/dynamix.unraid.net.plg

Copy link
Member

@elibosley elibosley left a comment

Choose a reason for hiding this comment

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

This looks great! Only note is that we should probably throw the translate tag into the alerts at some point soon!

@pujitm pujitm merged commit 2224a2f into main Mar 18, 2025
8 checks passed
@pujitm pujitm deleted the fix/sandbox-apply branch March 18, 2025 14:33
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.

3 participants