Skip to content

refactor: replace custom isNil utility with lodash-es isNil#9479

Open
zzjiaxiang wants to merge 7 commits intoant-design:masterfrom
zzjiaxiang:utils
Open

refactor: replace custom isNil utility with lodash-es isNil#9479
zzjiaxiang wants to merge 7 commits intoant-design:masterfrom
zzjiaxiang:utils

Conversation

@zzjiaxiang
Copy link
Contributor

@zzjiaxiang zzjiaxiang commented Feb 13, 2026

Summary by CodeRabbit

发布说明

  • Chores

    • 移除并统一替换部分本地工具实现,依赖来源集中以便维护与一致性。
  • Refactor

    • 统一空值与字符串检测逻辑,提升输入校验一致性与稳定性。
    • 优化 Logo/标题的渲染判断,保持展示行为一致并对 URL 字符串友好。
    • 改进 URL 校验的输入处理,对非字符串输入更稳健并减少异常情况。

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 13, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @zzjiaxiang, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on refactoring the codebase by replacing custom utility functions with their lodash-es counterparts. The primary goal is to leverage well-tested and maintained external libraries for common operations like checking for null/undefined values and string types. This change reduces the amount of custom utility code, improves consistency, and enhances the reliability of these fundamental checks, leading to a more robust and maintainable application.

Highlights

  • Utility Function Standardization: Replaced the custom isNil utility function with the lodash-es/isNil equivalent across multiple files to standardize null/undefined checks.
  • Improved Type Checking: Introduced lodash-es/isString to replace manual typeof variable === 'string' checks, particularly in SimpleContent.tsx and isUrl/index.ts.
  • Codebase Cleanup: Removed the custom src/utils/isNil/index.ts file and its exports from src/utils/index.tsx as it is no longer needed.
  • Refined URL Validation: Updated the isUrl utility to use lodash-es/isString and simplified its internal logic for checking valid URLs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/field/components/Digit/index.tsx
    • Replaced custom isNil import with lodash-es/isNil.
  • src/layout/components/AppsLogoComponents/SimpleContent.tsx
    • Imported lodash-es/isString.
    • Replaced typeof logo === 'string' checks with isString(logo).
    • Replaced typeof title === 'string' check with isString(title).
  • src/table/utils/columnRender.tsx
    • Imported lodash-es/isNil.
    • Removed the import of the custom isNil utility.
  • src/utils/conversionMomentValue/index.ts
    • Replaced custom isNil import with lodash-es/isNil.
  • src/utils/index.tsx
    • Removed the import and export of the custom isNil utility.
  • src/utils/isNil/index.ts
    • Removed the file containing the custom isNil utility.
  • src/utils/isUrl/index.ts
    • Imported lodash-es/isString.
    • Updated the isUrl function to use isString for type checking the path.
    • Simplified the URL validation logic by directly returning true on successful URL construction and false on error.
  • src/utils/parseValueToMoment/index.ts
    • Replaced custom isNil import with lodash-es/isNil.
  • src/utils/transformKeySubmitValue/index.ts
    • Replaced custom isNil import with lodash-es/isNil.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

将多个文件中对本地 isNil 的引用改为 lodash-es/isNil 并移除本地 isNil 实现/导出;isUrl 的参数类型由 string | undefined 改为 string,运行时用 isString 校验并简化验证逻辑;SimpleContent 中统一使用 isString 判断字符串;Digit 组件略微简化了精度处理的空值检查逻辑。

Changes

Cohort / File(s) Summary
isNil 导入迁移至 lodash-es
src/field/components/Digit/index.tsx, src/table/utils/columnRender.tsx, src/utils/conversionMomentValue/index.ts, src/utils/parseValueToMoment/index.ts, src/utils/transformKeySubmitValue/index.ts
isNil 的导入源从本地工具模块更改为 lodash-es/isNil,使用位置不变;Digit 中同时微调了基于精度的 toFixed 调用的空值检查逻辑。
本地 isNil 工具移除
src/utils/index.tsx, src/utils/isNil/index.ts
从工具聚合导出和单文件中删除本地 isNil 实现与导出,不再通过本地工具提供该符号。
isUrl 签名与实现调整
src/utils/isUrl/index.ts
将参数类型由 `string
isString 用于字符串校验
src/layout/components/AppsLogoComponents/SimpleContent.tsx
新增 lodash-es/isString 导入并用 isString 替换原有字符串类型判断,调整 logo/title 渲染分支并保留最终返回行为。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 代码轻跳换新装,
小函远行入大厂。
isNil 扬帆去他处,isString 守旧墙,
精度微调步轻盈,
兔足拍地笑嘻嘻。

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed PR标题准确地总结了主要变更,即用lodash-es的isNil替换自定义isNil工具函数,标题简洁清晰且与所有文件更改高度相关。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dosubot dosubot bot added the 🧱 antd label Feb 13, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the codebase to use isNil from lodash-es instead of a custom utility, which is a good move for consistency and leveraging a standard library. The changes also include replacing typeof x === 'string' checks with isString from lodash-es. While this is a good refactoring, I've found a subtle bug introduced in SimpleContent.tsx where the new isString check doesn't account for empty strings, leading to a change in rendering behavior. Please see my comments for details and suggestions for a fix. The rest of the changes look good.

Copy link

@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

🤖 Fix all issues with AI agents
In `@src/layout/components/AppsLogoComponents/SimpleContent.tsx`:
- Around line 29-31: The current check in SimpleContent (where it renders <div
id="avatarLogo">{symbol}</div>) uses !logo && isString(title) which allows an
empty string title and renders an empty avatar; restore the original truthy
title guard so empty string is skipped by changing the condition to require a
non-empty string (e.g., !logo && isString(title) && title) before computing
symbol = title.substring(0, 1) and rendering avatarLogo.

@chenshuai2144
Copy link
Contributor

冲突了,再来一下

Copy link

@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.

🧹 Nitpick comments (1)
src/field/components/Digit/index.tsx (1)

59-65: !isNil(val) 条件冗余,可以移除

在进入该 if 块时,typeof val === 'number' 已经保证 val 不为 nullundefined,因此两处 !isNil(val) 检查是多余的,可一并删除以提升可读性。

♻️ 建议的精简
-      if (
-        typeof val === 'number' &&
-        !isNil(val) &&
-        !isNil(fieldProps.precision)
-      ) {
+      if (
+        typeof val === 'number' &&
+        !isNil(fieldProps.precision)
+      ) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/field/components/Digit/index.tsx` around lines 59 - 65, The if condition
that formats the numeric value is checking !isNil(val) redundantly because
typeof val === 'number' already excludes null/undefined; update the conditional
in the Digit component so it only verifies typeof val === 'number' and that
fieldProps.precision is not nil (remove both !isNil(val) checks), leaving the
Number(val.toFixed(fieldProps.precision)) logic unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/field/components/Digit/index.tsx`:
- Around line 59-65: The if condition that formats the numeric value is checking
!isNil(val) redundantly because typeof val === 'number' already excludes
null/undefined; update the conditional in the Digit component so it only
verifies typeof val === 'number' and that fieldProps.precision is not nil
(remove both !isNil(val) checks), leaving the
Number(val.toFixed(fieldProps.precision)) logic unchanged.

- Removed unnecessary nil checks for val in precision formatting.
- Streamlined the condition to only check for number type and precision presence.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🧱 antd size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants