Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add completely delete file option #4326

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xujingli
Copy link

@xujingli xujingli commented Jan 20, 2025

Types

  • 🎉 New Features

Background or solution

Since we can't recover files from nas drives, we added the option to delete files completely.

Changelog

Summary by CodeRabbit

  • 新功能

    • 为文件资源管理器添加了完全删除文件的确认选项
    • 支持在删除文件时选择是否完全删除
  • 本地化

    • 新增中英文文件完全删除确认提示语
    • 添加了完全删除和取消操作的本地化文案
  • 改进

    • 优化了文件删除流程,增加了更精细的删除控制
    • 提供了更明确的文件删除操作选项

@CLAassistant
Copy link

CLAassistant commented Jan 20, 2025

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@opensumi opensumi bot added the 🎨 feature feature required label Jan 20, 2025
Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"

概述

演练

这个拉取请求主要修改了文件删除的确认机制。移除了 explorer.confirmCompletelyDelete 首选项,并在文件树服务中添加了一个新的完全删除选项。更改涉及多个包,包括核心浏览器、文件树、国际化和工作空间编辑服务。新的实现允许更精细地控制文件删除行为,增加了一个可选的完全删除参数。

变更

文件路径 变更摘要
packages/core-browser/src/core-preferences.ts 移除了 explorer.confirmCompletelyDelete 首选项定义
packages/file-tree-next/src/browser/services/file-tree-api.service.ts 更新 delete 方法签名,添加 completelyDelete 可选参数
packages/file-tree-next/src/browser/services/file-tree-model.service.ts 修改删除文件方法,增加完全删除确认逻辑
packages/i18n/src/common/en-US.lang.ts 添加完全删除相关的本地化字符串
packages/i18n/src/common/zh-CN.lang.ts 添加完全删除相关的本地化字符串
packages/workspace-edit/src/browser/workspace-edit.service.ts ResourceFileEdit 中添加 completelyDelete 属性

可能相关的 PR

建议标签

🎨 feature

建议审阅者

  • Ricbet
  • bytemain
  • hacke2
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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.

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 (5)
packages/workspace-edit/src/browser/workspace-edit.service.ts (1)

301-304: 建议优化条件逻辑的可读性!

当前的条件逻辑较为复杂,建议重构以提高可读性。

建议修改为:

-          useTrash:
-            options.completelyDelete !== undefined
-              ? !options.completelyDelete // 如果 completelyDelete 被定义,使用其相反值
-              : !(isWindows && this.oldResource.path.name === 'node_modules'), // 否则使用原有逻辑,
+          useTrash: (() => {
+            // 如果指定了完全删除选项,则不使用回收站
+            if (options.completelyDelete !== undefined) {
+              return !options.completelyDelete;
+            }
+            // Windows 上的 node_modules 文件夹不使用回收站
+            if (isWindows && this.oldResource.path.name === 'node_modules') {
+              return false;
+            }
+            // 默认使用回收站
+            return true;
+          })(),
packages/i18n/src/common/zh-CN.lang.ts (1)

58-60: 确认新增的本地化文案符合预期!

新增的完全删除相关的本地化文案清晰明确,并且与现有的移入回收站删除提示保持一致的风格。建议可以考虑在"彻底删除"的文案中添加警示性的提示,比如"此操作无法撤销"。

packages/file-tree-next/src/browser/services/file-tree-model.service.ts (3)

980-997: 完全删除文件的确认对话框实现

确认对话框的实现逻辑清晰,但建议进行以下改进:

  1. 建议将确认对话框的消息文本抽取为常量,以便于维护和复用。
  2. 建议添加文件数量的显示,当文件数量超过5个时,显示总数。
+const MAX_DISPLAY_FILES = 5;
+const getDeleteFilesMessage = (uris: URI[], isCompletelyDelete: boolean) => {
+  const fileCount = uris.length;
+  const displayFiles = uris.slice(0, MAX_DISPLAY_FILES)
+    .map((uri) => uri.displayName)
+    .join(',');
+  const suffix = fileCount > MAX_DISPLAY_FILES ? 
+    ` ... (共${fileCount}个文件)` : '';
+  return `[ ${displayFiles}${suffix} ]`;
+};

-    const deleteFilesMessage = `[ ${uris
-      .slice(0, 5)
-      .map((uri) => uri.displayName)
-      .join(',')}${uris.length > 5 ? ' ...' : ''} ]`;
+    const deleteFilesMessage = getDeleteFilesMessage(uris, true);

1045-1045: 确保完全删除参数正确传递

删除操作的参数传递正确,但建议添加类型注释以提高代码可读性。

-        this.deleteFile(root.node, root.path, !!this.corePreferences['explorer.confirmCompletelyDelete']).then((v) => {
+        this.deleteFile(
+          root.node,
+          root.path,
+          !!this.corePreferences['explorer.confirmCompletelyDelete'] as boolean
+        ).then((v) => {

1059-1062: 完全删除功能的方法实现

方法实现逻辑正确,但建议添加错误处理和日志记录。

   async deleteFile(node: File | Directory, path: URI | string, completelyDelete?: boolean): Promise<boolean> {
     const uri = typeof path === 'string' ? new URI(path) : (path as URI);
+    try {
       const error = await this.fileTreeAPI.delete(uri, completelyDelete);
       if (error) {
         this.messageService.error(error);
         return false;
       }
+    } catch (e) {
+      this.messageService.error(`删除文件失败: ${e.message}`);
+      return false;
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92e7bca and d87edef.

📒 Files selected for processing (8)
  • packages/core-browser/src/core-preferences.ts (2 hunks)
  • packages/file-tree-next/src/browser/services/file-tree-api.service.ts (1 hunks)
  • packages/file-tree-next/src/browser/services/file-tree-model.service.ts (3 hunks)
  • packages/file-tree-next/src/common/index.ts (1 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
  • packages/workspace-edit/src/browser/workspace-edit.service.ts (2 hunks)
  • packages/workspace-edit/src/common/index.ts (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/core-browser/src/core-preferences.ts
🧰 Additional context used
🪛 Biome (1.9.4)
packages/file-tree-next/src/common/index.ts

[error] 25-25: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (5)
packages/file-tree-next/src/common/index.ts (1)

25-25: 接口更改符合预期!

delete 方法签名的更改恰当地添加了可选的 completelyDelete 参数,保持了向后兼容性。

🧰 Tools
🪛 Biome (1.9.4)

[error] 25-25: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

packages/workspace-edit/src/common/index.ts (1)

30-30: 选项定义清晰明确!

IResourceFileEdit 接口中添加 completelyDelete 选项,类型定义准确,保持了与其他选项的一致性。

packages/file-tree-next/src/browser/services/file-tree-api.service.ts (1)

204-212: 实现简洁有效!

delete 方法的实现正确地处理了 completelyDelete 参数,并保持了良好的错误处理机制。

packages/workspace-edit/src/browser/workspace-edit.service.ts (1)

200-200: 类型定义符合接口规范!

ResourceFileEdit 类中添加 completelyDelete 选项,与接口定义保持一致。

packages/i18n/src/common/en-US.lang.ts (1)

57-59: 英文本地化文案翻译准确!

英文版本的完全删除相关文案与中文版本含义对应,用词专业规范。

@Ricbet
Copy link
Member

Ricbet commented Jan 20, 2025

看起来你期望的“彻底删除”这个功能是默认实现了的,只是在文案上看起来有歧义。
似乎只需要改个文案就好了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants