Skip to content

Conversation

@elibosley
Copy link
Member

@elibosley elibosley commented Mar 18, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new Log Viewer configuration component to enhance the management and application of log settings.
  • Chores

    • Removed the legacy log viewer interface to streamline log management and improve the overall user experience.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2025

Walkthrough

The update introduces a new LogViewerModification class that handles the configuration of a log viewer for UNRAID by generating patches, applying new configurations, and handling rollbacks. Additionally, the PHP file responsible for rendering the log viewer interface has been removed, discontinuing that user-facing functionality.

Changes

File Path Change Summary
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts Added new LogViewerModification class that extends the file modification functionality: it checks for an existing configuration, generates a patch, applies new settings, and supports rollback.
plugin/source/dynamix.unraid.net/.../LogViewer.page Deleted file that previously rendered a PHP-based log viewer interface, including metadata and internationalization tags for the UNRAID log viewer display.
api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts Imported LogViewerModification class into the UnraidFileModificationService and included it in the loadModifications method to expand functionality for handling file modifications.

Sequence Diagram(s)

sequenceDiagram
    participant LV as LogViewerModification
    participant FS as File System
    participant Logger as Logger
    LV->>FS: Check if config exists (generatePatch)
    FS-->>LV: Return existing content or not found
    alt Configuration exists
        LV->>Logger: Log config already present (shouldApply false)
    else Configuration missing
        LV->>LV: Initiate rollback to remove previous settings
        LV->>FS: Write new log viewer configuration (apply)
    end
Loading

Suggested reviewers

  • mdatelle

Poem

In a realm where logs come to play,
A new class brings order to the fray.
Patches and rollbacks in a neat little dance,
As old codes retire with a graceful glance.
Cheers to fresh beginnings in code’s bright display!


📜 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 c7e58f7 and 9fefd81.

📒 Files selected for processing (1)
  • api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
api/src/unraid-api/unraid-file-modifier/unraid-file-modifier.service.ts (2)

7-7: Import for LogViewerModification added correctly.

The import statement for the new LogViewerModification class follows the established pattern and is correctly positioned among similar imports.


46-46: LogViewerModification properly integrated into the modification system.

The LogViewerModification class has been added to the modificationClasses array, allowing it to be loaded and applied during service initialization. This change properly implements the feature described in the PR objectives to make the log viewer component dynamic.


🪧 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: 1

🧹 Nitpick comments (5)
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts (5)

10-13: Class declaration looks good, but consider adding documentation.

The LogViewerModification class is well-defined with clear properties, but adding a class-level JSDoc comment would help other developers understand its purpose and usage.

+/**
+ * Handles the configuration of a log viewer for UNRAID by generating patches,
+ * applying new configurations, and handling rollbacks.
+ */
 export class LogViewerModification extends FileModification {
     id: string = 'log-viewer';
     public readonly filePath: string = '/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page' as const;
🧰 Tools
🪛 GitHub Check: Test API

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

🪛 GitHub Check: Build API

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


26-28: Remove unnecessary constructor.

This constructor only calls the parent constructor with the logger parameter, which is what would happen by default if the constructor were omitted.

-    constructor(logger: Logger) {
-        super(logger);
-    }
🧰 Tools
🪛 Biome (1.9.4)

[error] 26-28: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)


30-40: Consider adding error handling for file operations.

The generatePatch method has good logic for checking if the file exists, but it could benefit from additional error handling for file operations.

 protected async generatePatch(overridePath?: string): Promise<string> {
-        const currentContent = (await fileExists(this.filePath))
-            ? await readFile(this.filePath, 'utf8')
-            : '';
+        let currentContent = '';
+        try {
+            if (await fileExists(this.filePath)) {
+                currentContent = await readFile(this.filePath, 'utf8');
+            }
+        } catch (error) {
+            this.logger.warn(`Failed to read file ${this.filePath}: ${error.message}`);
+        }

50-54: Consider adding error handling to the apply method.

The apply method should include try-catch blocks to handle potential errors during file operations.

 async apply(): Promise<string> {
-        await this.rollback();
-        await writeFile(this.filePath, this.logViewerConfig, { mode: 0o644 });
-        return this.logViewerConfig;
+        try {
+            await this.rollback();
+            await writeFile(this.filePath, this.logViewerConfig, { mode: 0o644 });
+            this.logger.log(`Successfully applied log viewer configuration to ${this.filePath}`);
+            return this.logViewerConfig;
+        } catch (error) {
+            this.logger.error(`Failed to apply log viewer configuration: ${error.message}`);
+            throw error;
+        }

56-59: Consider logging rollback actions.

Adding logging statements would help with debugging and auditing when rollbacks occur.

 async rollback(): Promise<void> {
+        this.logger.log('Rolling back log viewer configuration...');
         await rm(this.getPathToAppliedPatch(), { force: true });
         await rm(this.filePath, { force: true });
+        this.logger.log('Log viewer configuration rollback completed');
📜 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 ffceb6e and e9584b5.

📒 Files selected for processing (2)
  • api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts (1 hunks)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page (0 hunks)
💤 Files with no reviewable changes (1)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/LogViewer.page
🧰 Additional context used
🪛 Biome (1.9.4)
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts

[error] 26-28: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

🪛 GitHub Check: Test API
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts

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

🪛 GitHub Check: Build API
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts

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

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (2)
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts (2)

42-48: The shouldApply logic is clear and well-structured.

The method correctly checks if the configuration already exists and returns appropriate response objects.


14-24:

❓ Verification inconclusive

Ensure i18n is fully supported for the log viewer.

The log viewer template includes an <unraid-i18n-host> wrapper, which is good for internationalization. Make sure that all displayed text in the log viewer component is properly localized.


🏁 Script executed:

#!/bin/bash
# Check if log viewer component has i18n support
fd "log-viewer" -e ts -e js -e html --exec cat {} \; | grep -E "i18n|translate"

Length of output: 122


i18n Integration in Log Viewer
The <unraid-i18n-host> wrapper is present, indicating basic internationalization support. However, please verify that all user-facing strings – such as the hardcoded Title="Log Viewer (new)" and any similar text attributes – are fully localized within the unraid-log-viewer component (i.e., linked to your i18n system and translation keys).

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/unraid-file-modifier/modifications/log-viewer.modification.ts (1)

27-29: Remove unnecessary constructor.

This constructor doesn't add any functionality beyond calling the parent constructor and can be safely removed.

-    constructor(logger: Logger) {
-        super(logger);
-    }
🧰 Tools
🪛 Biome (1.9.4)

[error] 27-29: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

📜 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 e9584b5 and c7e58f7.

📒 Files selected for processing (1)
  • api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts

[error] 27-29: This constructor is unnecessary.

Unsafe fix: Remove the unnecessary constructor.

(lint/complexity/noUselessConstructor)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (6)
api/src/unraid-api/unraid-file-modifier/modifications/log-viewer.modification.ts (6)

10-13: Good implementation of the LogViewerModification class.

The class extends FileModification correctly and provides proper identification through the id property. The filePath constant is well-defined and accurately points to the target file location.


15-25: Configuration template looks good.

The log viewer configuration includes appropriate menu categorization, title, icon, and tag settings. The HTML template uses unraid-specific custom elements which aligns with the modern component approach. The use of trimStart() is a good practice to remove unwanted leading whitespace.


31-41: Well-implemented patch generation logic.

The method correctly checks for file existence before reading content and creates an appropriate patch by comparing current and desired configurations. The error handling is robust with good fallback to empty string when file doesn't exist.


43-49: Good implementation of shouldApply method.

The method properly determines if the modification should be applied based on whether the configuration file already exists, with clear and descriptive reason messages.


51-55: Robust apply method implementation.

The method follows a good practice by calling rollback first to ensure a clean state before writing the new configuration. The file permissions (0o644) are explicitly set, which is a security best practice.


57-60: Thorough rollback implementation.

The method ensures proper cleanup by removing both the applied patch and the configuration file, with the force: true option to handle cases where files might not exist.

@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/PR1242/dynamix.unraid.net.plg

@elibosley elibosley merged commit e6ec110 into main Mar 19, 2025
8 checks passed
@elibosley elibosley deleted the feat/log-viewer-dynamic branch March 19, 2025 14:33
mdatelle pushed a commit that referenced this pull request Mar 19, 2025
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced a new Log Viewer configuration component to enhance the
management and application of log settings.

- **Chores**
- Removed the legacy log viewer interface to streamline log management
and improve the overall user experience.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
elibosley pushed a commit that referenced this pull request Mar 25, 2025
🤖 I have created a release *beep* *boop*
---


## [4.4.0](v4.3.1...v4.4.0)
(2025-03-25)


### Features

* add ReplaceKey functionality to plugin
([#1264](#1264))
([4aadcef](4aadcef))
* downgrade page replace key check
([#1263](#1263))
([8d56d12](8d56d12))
* make log viewer component dynamic
([#1242](#1242))
([e6ec110](e6ec110))
* ReplaceKey functionality in Registration and Update pages
([#1246](#1246))
([04307c9](04307c9))
* UnraidCheckExec for Check OS Updates via UPC dropdown
([#1265](#1265))
([5935a3b](5935a3b))


### Bug Fixes

* **deps:** update all non-major dependencies
([#1236](#1236))
([7194f85](7194f85))
* **deps:** update all non-major dependencies
([#1247](#1247))
([20b0aeb](20b0aeb))
* **deps:** update all non-major dependencies
([#1251](#1251))
([33a1a1d](33a1a1d))
* **deps:** update all non-major dependencies
([#1253](#1253))
([53fec0e](53fec0e))
* **deps:** update dependency @nestjs/passport to v11
([#1244](#1244))
([edc93a9](edc93a9))
* **deps:** update dependency graphql-subscriptions to v3
([#1209](#1209))
([c14c85f](c14c85f))
* **deps:** update dependency ini to v5
([#1217](#1217))
([f27660f](f27660f))
* **deps:** update dependency jose to v6
([#1248](#1248))
([42e3d59](42e3d59))
* **deps:** update dependency marked to v15
([#1249](#1249))
([2b6693f](2b6693f))
* **deps:** update dependency pino-pretty to v13
([#1250](#1250))
([85fb910](85fb910))
* **deps:** update dependency pm2 to v6
([#1258](#1258))
([04ad2bc](04ad2bc))
* **deps:** update dependency shadcn-vue to v1
([#1259](#1259))
([1a4fe8f](1a4fe8f))
* **deps:** update dependency vue-i18n to v11
([#1261](#1261))
([0063286](0063286))
* **deps:** update vueuse monorepo to v13 (major)
([#1262](#1262))
([94caae3](94caae3))
* make scripts executable when building the plugin
([#1255](#1255))
([e237f38](e237f38))
* node installation not persisting across reboots
([#1256](#1256))
([0415cf1](0415cf1))
* update configValid state to ineligible in var.ini and adjust rel…
([#1268](#1268))
([ef8c954](ef8c954))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@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.

3 participants