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: support file dialog renderCustomMsg #4352

Merged
merged 2 commits into from
Feb 13, 2025
Merged

Conversation

xujingli
Copy link
Contributor

@xujingli xujingli commented Feb 10, 2025

Types

  • 🎉 New Features
  • 🐛 Bug Fixes
  • 📚 Documentation Changes
  • 💄 Code Style Changes
  • 💄 Style Changes
  • 🪚 Refactors
  • 🚀 Performance Improvements
  • 🏗️ Build System
  • ⏱ Tests
  • 🧹 Chores
  • Other Changes

Background or solution

Changelog

Summary by CodeRabbit

  • 新功能
    • 优化文件对话框:现在对话框能自动获取并设置默认文件路径,提升加载体验。
    • 增强警告提示:在必要时会动态显示警告信息,帮助用户更好地理解当前状态。
    • 改进搜索体验:根据配置条件展示文件路径搜索选项,让定位文件更加便捷。

@opensumi opensumi bot added the 🐞 bug Something isn't working label Feb 10, 2025
Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

此次 PR 对 FileDialog 的功能进行了增强。在组件中新增了 getDefaultPath 方法,用于从模型根目录提取默认文件路径,并通过 fileServicegetDefaultFilePath 进行处理。同时引入了 renderCustomMsg 方法,用于检测并显示 fileService 提供的自定义消息。此外,Select 组件的 showSearch 属性现依据 fileServiceshowFilePathSearch 状态进行设置。相应地,FileTreeDialogService 类中也新增了 showFilePathSearch 属性及两个辅助方法:renderCustomMsggetDefaultFilePath

Changes

文件 更改摘要
packages/file-tree-next/.../file-dialog.view.tsx 新增 getDefaultPathrenderCustomMsg 方法,集成默认路径获取与自定义消息显示;在 ensureIsReady 中调用新方法,并根据 fileService.showFilePathSearch 控制 Select 组件的搜索功能。
packages/file-tree-next/.../file-dialog.service.ts 新增布尔属性 showFilePathSearch;添加 renderCustomMsg 方法(返回 null)和 getDefaultFilePath 方法(返回传入的 defaultPath)。

Sequence Diagram(s)

sequenceDiagram
    participant FD as FileDialog
    participant FS as FileDialogService
    FD->>FS: getDefaultFilePath(defaultPath)
    FS-->>FD: 返回处理后的路径
    FD->>FS: renderCustomMsg()
    FS-->>FD: 返回自定义消息或 null
Loading

Possibly related PRs

Suggested reviewers

  • Ricbet
  • hacke2
  • ensorrow

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.

yarn install v1.22.22
[1/4] Resolving packages...
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: 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 > glob@7.2.3: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.


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 (3)
packages/overlay/src/common/index.ts (1)

60-60: 建议为新方法添加文档注释

建议为 renderWarningMsg 方法添加 JSDoc 文档注释,说明该方法的用途、返回值含义以及使用场景。这将有助于其他开发者理解和正确使用该方法。

+  /**
+   * 渲染警告消息
+   * @returns 返回要渲染的警告消息节点,如果没有警告消息则返回 null
+   */
   renderWarningMsg(): React.ReactNode | null;
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (2)

214-218: 实现逻辑正确,但建议优化依赖项

renderWarningMsg 函数的实现逻辑正确,通过安全检查确保方法存在才调用。

建议将 dialogService 添加到 useCallback 的依赖数组中:

  const renderWarningMsg = useCallback(() => {
    if (dialogService.renderWarningMsg) {
      return dialogService.renderWarningMsg();
    }
-  }, []);
+  }, [dialogService]);

297-306: 建议更新 useMemo 依赖项

DialogContent 组件使用了 renderWarningMsg 函数,但未将其添加到 useMemo 的依赖数组中。

  const DialogContent = useMemo(
    () => (
      <>
        <div>{renderWarningMsg()}</div>
        <div className={styles.file_dialog_directory}>{renderDirectorySelection()}</div>
        <div className={styles.file_dialog_content}>{renderDialogTree()}</div>
      </>
    ),
-    [renderDirectorySelection, renderDialogTree],
+    [renderDirectorySelection, renderDialogTree, renderWarningMsg],
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bfefebb and 3852bf3.

📒 Files selected for processing (2)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (2 hunks)
  • packages/overlay/src/common/index.ts (1 hunks)

Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

Walkthrough

此次更改在文件对话框组件中引入了新的 renderWarningMsg 方法,该方法会检查并调用 dialogService 中同名方法以渲染警告消息。同时,在对话框服务接口 IDialogService 中新增了 renderWarningMsg 方法,返回类型为 React.ReactNode | null,以便实现一致的警告消息渲染功能。这些更改为文件对话框添加了条件性警告信息显示能力,并确保警告渲染接口在服务中得到定义。

Changes

文件 更改摘要
packages/.../file-dialog.view.tsx 新增 renderWarningMsg 方法,在 DialogContent 中调用以渲染警告消息。
packages/.../index.ts IDialogService 接口中新增 `renderWarningMsg(): React.ReactNode

Sequence Diagram(s)

sequenceDiagram
    participant FD as FileDialog
    participant DS as DialogService
    FD->>DS: 检查是否实现 renderWarningMsg 方法
    DS-->>FD: 返回警告消息 (React.ReactNode 或 null)
    FD->>FD: 在对话框内容中渲染警告消息
Loading

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.

yarn install v1.22.22
[1/4] Resolving packages...
warning eslint@8.57.1: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/config-array@0.13.0: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/object-schema@2.0.3: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > inflight@1.0.6: 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 > glob@7.2.3: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

✨ 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

🔭 Outside diff range comments (1)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

305-305: 需要更新 useMemo 的依赖数组

DialogContent 的 useMemo 依赖数组中缺少 renderWarningMsg,这可能导致警告消息不能及时更新。

-    [renderDirectorySelection, renderDialogTree],
+    [renderDirectorySelection, renderDialogTree, renderWarningMsg],
🧹 Nitpick comments (2)
packages/overlay/src/common/index.ts (1)

60-60: 接口定义清晰且符合预期

新增的 renderWarningMsg 方法定义合理,返回类型 React.ReactNode | null 能够满足不同场景的渲染需求。

建议考虑添加 JSDoc 注释来说明该方法的用途和使用场景。

+  /** 渲染警告信息,当无需显示警告时返回 null */
   renderWarningMsg(): React.ReactNode | null;
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

300-300: 建议优化警告消息的渲染逻辑

当没有警告消息时,当前实现仍会创建一个空的 div 元素。建议使用条件渲染来优化。

-        <div>{renderWarningMsg()}</div>
+        {renderWarningMsg() && <div>{renderWarningMsg()}</div>}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bfefebb and 3852bf3.

📒 Files selected for processing (2)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (2 hunks)
  • packages/overlay/src/common/index.ts (1 hunks)
🔇 Additional comments (1)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

214-218: 安全地实现了警告消息渲染

实现使用了 useCallback 并正确地进行了空值检查,符合 React 最佳实践。

@Ricbet Ricbet changed the title fix: add renderWarningMsg feat: support file dialog renderWarningMsg Feb 11, 2025
@opensumi opensumi bot added the 🎨 feature feature required label Feb 11, 2025
@Ricbet
Copy link
Member

Ricbet commented Feb 11, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented Feb 11, 2025

🎉 PR Next publish successful!

3.7.1-next-1739252693.0

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 0% with 5 lines in your changes missing coverage. Please review.

Project coverage is 54.17%. Comparing base (92e7bca) to head (d49745f).
Report is 24 commits behind head on main.

Files with missing lines Patch % Lines
...ree-next/src/browser/dialog/file-dialog.service.ts 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4352      +/-   ##
==========================================
- Coverage   54.19%   54.17%   -0.02%     
==========================================
  Files        1635     1639       +4     
  Lines       99973   100306     +333     
  Branches    21703    21761      +58     
==========================================
+ Hits        54177    54341     +164     
- Misses      38049    38196     +147     
- Partials     7747     7769      +22     
Flag Coverage Δ
jsdom 49.65% <0.00%> (-0.08%) ⬇️
node 12.28% <0.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 (2)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

277-277: 建议简化布尔表达式

当前的三元表达式可以简化为更清晰的形式。

建议修改为:

-          showSearch={fileService.showFilePathSearch === false ? false : true}
+          showSearch={fileService.showFilePathSearch !== false}
packages/main-layout/src/browser/accordion/styles.module.less (1)

83-91: 建议优化样式复用

kt_split_warning_message 类与 kt_split_panel_message 类存在大量重复样式,建议重构以提高可维护性。

建议修改为:

  .kt_split_panel_message {
    padding: 4px 12px 4px 18px;
    line-height: 14px;
    user-select: text;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .kt_split_warning_message {
-    padding: 4px 12px 4px 18px;
-    line-height: 14px;
-    user-select: text;
-    overflow: hidden;
-    text-overflow: ellipsis;
+    &:extend(.kt_split_panel_message);
    white-space: normal;
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c18b79d and 4f35105.

📒 Files selected for processing (5)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts (2 hunks)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (5 hunks)
  • packages/main-layout/src/browser/accordion/accordion.service.ts (1 hunks)
  • packages/main-layout/src/browser/accordion/section.view.tsx (1 hunks)
  • packages/main-layout/src/browser/accordion/styles.module.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts
🔇 Additional comments (3)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (2)

98-106: 代码结构清晰,实现合理!

函数实现了良好的关注点分离,将获取默认路径的逻辑独立出来,并正确处理了可选的 fileService.getDefaultFilePath 方法。


226-232: 很好地处理了空值情况!

函数实现符合之前的代码评审建议,通过返回 null 来避免渲染空标签。同时使用了简洁的条件返回结构,代码清晰易读。

packages/main-layout/src/browser/accordion/section.view.tsx (1)

215-217: 代码实现清晰且符合最佳实践!

警告消息的条件渲染实现得当:

  • 正确放置在 ErrorBoundary 内部
  • 与现有消息保持一致的渲染模式
  • 使用统一的样式类

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

🔭 Outside diff range comments (1)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

316-325: 🛠️ Refactor suggestion

添加缺失的 useMemo 依赖

DialogContent 的 useMemo 依赖数组中缺少 renderWarningMsg,这可能导致警告消息无法及时更新。

    ),
-    [renderDirectorySelection, renderDialogTree],
+    [renderDirectorySelection, renderDialogTree, renderWarningMsg],
  );
🧹 Nitpick comments (3)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (3)

98-106: 优化 getDefaultPath 方法的实现

建议进行以下改进:

  1. 使用 useCallback 包装函数以避免不必要的重新渲染
  2. 添加类型注解以提高代码可维护性
  3. 添加空值检查以提高代码健壮性
-  const getDefaultPath = (model) => {
+  const getDefaultPath = useCallback((model: FileTreeDialogModel) => {
+    if (!model?.treeModel?.root) {
+      return '';
+    }
+
     let defaultPath = (model.treeModel.root as Directory).uri.codeUri.fsPath;

     if (fileService.getDefaultFilePath) {
       defaultPath = fileService.getDefaultFilePath(defaultPath);
     }

     return defaultPath;
-  };
+  }, [fileService]);

226-232: 优化 renderWarningMsg 的依赖数组

当前的依赖数组仅包含 fileService.renderWarningMsg,建议将整个 fileService 添加到依赖数组中,以确保当 fileService 发生变化时能够正确触发重新渲染。

  }, [fileService.renderWarningMsg]);
+  }, [fileService]);

267-270: 简化 showFilePathSearch 的实现

当前实现使用双重否定来确保布尔值,可以简化为更直观的形式。

  const showFilePathSearch = useMemo(
-    () => (fileService.showFilePathSearch === false ? false : true),
+    () => fileService.showFilePathSearch !== false,
    [fileService.showFilePathSearch],
  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f35105 and 1048213.

📒 Files selected for processing (1)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (6 hunks)
🔇 Additional comments (1)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

282-282: 代码实现正确

showSearch 属性的设置符合需求,实现清晰明了。

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)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (2)

98-106: 建议使用 useCallback 包装 getDefaultPath 函数

该函数被用作 ensureIsReady 的依赖,应该使用 useCallback 进行记忆化以避免不必要的重渲染。同时建议添加错误处理。

建议按如下方式重构:

-  const getDefaultPath = (model) => {
+  const getDefaultPath = useCallback((model) => {
+    if (!model?.treeModel?.root) {
+      return '';
+    }
+
     let defaultPath = (model.treeModel.root as Directory).uri.codeUri.fsPath;
 
     if (fileService.getDefaultFilePath) {
       defaultPath = fileService.getDefaultFilePath(defaultPath);
     }
 
     return defaultPath;
-  };
+  }, [fileService]);

267-270: 建议简化 showFilePathSearch 的逻辑

当前实现可以更简洁地表达默认值逻辑。

建议按如下方式重构:

-  const showFilePathSearch = useMemo(
-    () => (fileService.showFilePathSearch === false ? false : true),
-    [fileService.showFilePathSearch],
-  );
+  const showFilePathSearch = useMemo(
+    () => fileService.showFilePathSearch !== false,
+    [fileService.showFilePathSearch],
+  );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1048213 and 38c2498.

📒 Files selected for processing (2)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts (2 hunks)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts
🔇 Additional comments (1)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

226-232: 实现合理,符合之前的代码评审建议

该实现正确处理了空值检查,并使用了 useCallback 进行优化。

Ricbet
Ricbet previously approved these changes Feb 13, 2025
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)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (1)

98-106: 建议使用 useCallback 包装 getDefaultPath 函数

为了保持一致性和优化性能,建议将 getDefaultPath 函数使用 useCallback 包装。

-  const getDefaultPath = (model) => {
+  const getDefaultPath = useCallback((model) => {
     let defaultPath = (model.treeModel.root as Directory).uri.codeUri.fsPath;
 
     if (fileService.getDefaultFilePath) {
       defaultPath = fileService.getDefaultFilePath(defaultPath);
     }
 
     return defaultPath;
-  };
+  }, [fileService.getDefaultFilePath]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 38c2498 and d49745f.

📒 Files selected for processing (2)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts (3 hunks)
  • packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/file-tree-next/src/browser/dialog/file-dialog.service.ts
🔇 Additional comments (4)
packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx (4)

226-232: renderCustomMsg 函数实现正确

函数实现了正确的空值检查,并且使用了 useCallback 进行了适当的性能优化。


267-270: showFilePathSearch 的默认值处理合理

使用 useMemo 缓存计算结果,并且对 undefined 情况做了合理的默认值处理。


282-282: Select 组件的 showSearch 属性集成正确

showSearch 属性与 showFilePathSearch 状态正确关联。


319-319: 建议添加空值检查

为了避免渲染空标签,建议添加空值检查。

-        {renderCustomMsg()}
+        {renderCustomMsg() && renderCustomMsg()}

@Ricbet Ricbet changed the title feat: support file dialog renderWarningMsg feat: support file dialog renderCustomMsg Feb 13, 2025
@Ricbet Ricbet merged commit a795630 into opensumi:main Feb 13, 2025
13 checks passed
@Ricbet
Copy link
Member

Ricbet commented Feb 13, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented Feb 13, 2025

🎉 PR Next publish successful!

3.7.1-next-1739439717.0

@coderabbitai coderabbitai bot mentioned this pull request Feb 14, 2025
11 tasks
@coderabbitai coderabbitai bot mentioned this pull request Feb 14, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🎨 feature feature required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants