Skip to content

Reveal Parent Directories in External Applications#1791

Merged
oneirocosm merged 13 commits intomainfrom
sylvie/open-parent-ext
Jan 23, 2025
Merged

Reveal Parent Directories in External Applications#1791
oneirocosm merged 13 commits intomainfrom
sylvie/open-parent-ext

Conversation

@oneirocosm
Copy link
Contributor

Adds context menu options to the directory preview to open the parent directory in the native file viewer. Additionally, it adds context menu options in the block header to open either a parent directory or a different type of file in an external default application.

This only adds the options to the individual rows and the frame. It
still needs to be added to the header.
Importing PLATFORM in util.ts broke the app. I am now passing it as an
argument to avoid this.
Importing PLATFORM in util.ts broke the app. I am now passing it as an
argument to avoid this.
This allows revealing directories and other files with external
applications.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Warning

Rate limit exceeded

@oneirocosm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between dd0d952 and 363b46e.

📒 Files selected for processing (2)
  • frontend/app/view/preview/directorypreview.tsx (6 hunks)
  • frontend/app/view/preview/preview.tsx (4 hunks)

Walkthrough

The pull request introduces enhancements to the file and directory preview functionality across multiple frontend files. Key modifications include the addition of a new utility function makeNativeLabel in the util.ts file, which generates context-aware labels for file operations based on the platform.

Changes are made in three primary files: directorypreview.tsx, preview.tsx, and util.ts. In directorypreview.tsx, the context menu functionality is improved by making the handleFileContextMenu function asynchronous and incorporating dynamic label generation for menu items. The preview.tsx file sees the addition of new menu items that utilize the makeNativeLabel function for opening native paths. The util.ts file introduces the makeNativeLabel function, which constructs labels based on the platform and file type.

These updates enhance the application's capability to manage native path operations effectively across different operating systems.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • 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. (Beta)
  • @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.

While parent is trivial to compute for non-directories, it is slightly
more involved for children that are also directories. This resolves that
case using the RemoteFileJoinCommand
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 (2)
frontend/util/util.ts (1)

305-326: Add input validation and use platform constants.

The implementation looks good but could be improved with:

  1. Input validation for the platform parameter
  2. Constants for platform strings to avoid magic strings
+const PLATFORM_DARWIN = 'darwin';
+const PLATFORM_WIN32 = 'win32';
+
 function makeNativeLabel(platform: string, isDirectory: boolean, isParent: boolean) {
+    if (!platform) {
+        platform = 'unknown';
+    }
     let managerName: string;
     if (!isDirectory && !isParent) {
         managerName = "Default Application";
-    } else if (platform == "darwin") {
+    } else if (platform === PLATFORM_DARWIN) {
         managerName = "Finder";
-    } else if (platform == "win32") {
+    } else if (platform === PLATFORM_WIN32) {
         managerName = "Explorer";
     } else {
         managerName = "File Manager";
     }
frontend/app/view/preview/directorypreview.tsx (1)

514-521: Add error type and improve error handling.

The error handling for parent file info retrieval could be more robust:

  1. The error type should be specified
  2. The error message could be more descriptive
  3. Consider logging the actual error
 try {
     parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [normPath, ".."], {
         route: makeConnRoute(conn),
     });
-} catch (e) {
-    console.log("could not get parent file info. using child file info as fallback");
+} catch (error: unknown) {
+    console.error("Failed to get parent file info, using child file info as fallback:", error);
     parentFileInfo = finfo;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5346b62 and 39562f5.

📒 Files selected for processing (2)
  • frontend/app/view/preview/directorypreview.tsx (4 hunks)
  • frontend/util/util.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (3)
frontend/app/view/preview/directorypreview.tsx (3)

575-585: LGTM: Context menu items for native path operations.

The implementation correctly uses the makeNativeLabel utility to generate platform-specific labels for both the current item and its parent directory.


865-869: LGTM: Directory context menu implementation.

The implementation correctly uses the makeNativeLabel utility for the directory context menu.


13-13: Verify all imports of makeNativeLabel.

Let's verify that makeNativeLabel is imported and used consistently across the codebase.

✅ Verification successful

makeNativeLabel imports and usage verified successfully

The function is properly imported and consistently used across the preview components for generating platform-specific labels.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all imports of makeNativeLabel
echo "Checking imports of makeNativeLabel:"
rg "import.*makeNativeLabel.*from.*util"

# Search for all usages of makeNativeLabel
echo -e "\nChecking usages of makeNativeLabel:"
rg "makeNativeLabel\("

Length of output: 1043

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)
frontend/app/view/preview/directorypreview.tsx (1)

520-526: Consider enhancing error handling with specific error types.

The error handling for parent directory info retrieval is good but could be more specific. Consider catching specific error types to handle different failure scenarios appropriately.

-            } catch (e) {
+            } catch (error) {
+                if (error instanceof TypeError) {
+                    console.error("Network or API error:", error);
+                } else {
+                    console.error("Unexpected error:", error);
+                }
                 console.log("could not get parent file info. using child file info as fallback");
                 parentFileInfo = finfo;
             }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e70836 and f42be50.

📒 Files selected for processing (2)
  • frontend/app/view/preview/directorypreview.tsx (4 hunks)
  • frontend/app/view/preview/preview.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/app/view/preview/preview.tsx
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (3)
frontend/app/view/preview/directorypreview.tsx (3)

12-12: LGTM!

The import statement for makeNativeLabel is correctly added and follows the project's import style.


889-893: LGTM!

The context menu implementation for opening directories in native file manager is consistent with the earlier changes and uses the makeNativeLabel function appropriately.


580-590: Address the TODO comment about local files.

The TODO comment indicates that these options should only be shown for local files. This should be implemented to prevent showing these options for remote files.

Let's verify the current behavior:

Would you like me to help implement the connection type check for these menu items?

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f42be50 and dd0d952.

📒 Files selected for processing (2)
  • frontend/app/view/preview/directorypreview.tsx (7 hunks)
  • frontend/app/view/preview/preview.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (4)
frontend/app/view/preview/directorypreview.tsx (2)

12-12: LGTM!

The import statement correctly adds the makeNativeLabel utility function while maintaining alphabetical order.


580-590: Consider performance optimization and WSL support.

  1. The click handlers could be memoized using useCallback to prevent unnecessary re-renders.
  2. The TODO comment about WSL support should be addressed.

Let's verify if WSL support is implemented elsewhere:

frontend/app/view/preview/preview.tsx (2)

690-709: Ensure consistent connection handling.

The connection handling in the terminal block creation is consistent with the rest of the codebase.


711-717: LGTM!

The implementation of native file opening is clean and follows the established patterns.

Comment on lines +511 to +526
async (e: any, finfo: FileInfo) => {
e.preventDefault();
e.stopPropagation();
if (finfo == null) {
return;
}
const normPath = getNormFilePath(finfo);
const fileName = finfo.path.split("/").pop();
let openNativeLabel = "Open File";
if (finfo.isdir) {
openNativeLabel = "Open Directory in File Manager";
if (PLATFORM == "darwin") {
openNativeLabel = "Open Directory in Finder";
} else if (PLATFORM == "win32") {
openNativeLabel = "Open Directory in Explorer";
}
} else {
openNativeLabel = "Open File in Default Application";
let parentFileInfo: FileInfo;
try {
parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [normPath, ".."], {
route: makeConnRoute(conn),
});
} catch (e) {
console.log("could not get parent file info. using child file info as fallback");
parentFileInfo = finfo;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling and parent directory fallback logic.

The error handling for parent directory info could be improved:

  1. The error log message is too generic and doesn't include the actual error.
  2. Using the child file info as a fallback might lead to incorrect behavior.

Consider this improved implementation:

 try {
     parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [normPath, ".."], {
         route: makeConnRoute(conn),
     });
 } catch (e) {
-    console.log("could not get parent file info. using child file info as fallback");
-    parentFileInfo = finfo;
+    console.error(`Failed to get parent info for ${normPath}:`, e);
+    throw new Error(`Unable to access parent directory: ${e.message}`);
 }
📝 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
async (e: any, finfo: FileInfo) => {
e.preventDefault();
e.stopPropagation();
if (finfo == null) {
return;
}
const normPath = getNormFilePath(finfo);
const fileName = finfo.path.split("/").pop();
let openNativeLabel = "Open File";
if (finfo.isdir) {
openNativeLabel = "Open Directory in File Manager";
if (PLATFORM == "darwin") {
openNativeLabel = "Open Directory in Finder";
} else if (PLATFORM == "win32") {
openNativeLabel = "Open Directory in Explorer";
}
} else {
openNativeLabel = "Open File in Default Application";
let parentFileInfo: FileInfo;
try {
parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [normPath, ".."], {
route: makeConnRoute(conn),
});
} catch (e) {
console.log("could not get parent file info. using child file info as fallback");
parentFileInfo = finfo;
async (e: any, finfo: FileInfo) => {
e.preventDefault();
e.stopPropagation();
if (finfo == null) {
return;
}
const normPath = getNormFilePath(finfo);
const fileName = finfo.path.split("/").pop();
let parentFileInfo: FileInfo;
try {
parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [normPath, ".."], {
route: makeConnRoute(conn),
});
} catch (e) {
console.error(`Failed to get parent info for ${normPath}:`, e);
throw new Error(`Unable to access parent directory: ${e.message}`);
}

@oneirocosm oneirocosm merged commit 6d32ae8 into main Jan 23, 2025
5 checks passed
@oneirocosm oneirocosm deleted the sylvie/open-parent-ext branch January 23, 2025 03:09
xxyy2024 pushed a commit to xxyy2024/waveterm_aipy that referenced this pull request Jun 24, 2025
Adds context menu options to the directory preview to open the parent
directory in the native file viewer. Additionally, it adds context menu
options in the block header to open either a parent directory or a
different type of file in an external default application. These context
menu items are only available for local directory previews.
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.

1 participant