Skip to content

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Jan 20, 2025

PR

重新指定utils的导出名称, 从log改为logger
确保所有logger只使用 warn ,error的方法
packages/mobile内的没有修改。

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor

    • Updated logging utility across multiple packages from log to logger
    • Simplified logging method calls in various components
  • Dependency Updates

    • Added @opentiny/utils as a workspace dependency in vue-common package
  • Chores

    • Removed old logging module
    • Created new logger implementation

Copy link

coderabbitai bot commented Jan 20, 2025

Walkthrough

This pull request introduces a comprehensive update to the logging mechanism across multiple packages in the project. The primary change involves replacing the log import from @opentiny/utils with a new logger import. This modification affects several files in the renderless, utils, and vue packages, updating how logging methods are called and imported. The changes are consistent across different components, replacing log.logger.xxx calls with logger.xxx, while maintaining the overall functionality of the existing code.

Changes

File Change Summary
packages/renderless/src/*/index.ts Replaced log import with logger from @opentiny/utils
packages/utils/src/log/index.ts Deleted old logging utility
packages/utils/src/logger/index.ts Added new logger utility with similar functionality
packages/vue-common/package.json Added @opentiny/utils dependency
packages/vue/src/grid/src/tools/logger.ts Updated logging method to use new logger import

Possibly related PRs

Suggested Labels

refactoring

Suggested Reviewers

  • zzcr

Poem

🐰 A Logging Leap of Faith

From log to logger, we dance and prance,
Refactoring code with a rabbit's glance,
Imports transformed, methods realigned,
A cleaner path, elegantly designed!

Hop, hop, hurray! 🎉

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.

@github-actions github-actions bot added the refactoring Refactoring (重构) label Jan 20, 2025
Copy link

Walkthrough

此PR重命名了utils模块中的导出名称,从log改为logger,并确保所有logger只使用warn和error方法。注意,packages/mobile目录下的文件没有修改。

Changes

文件路径 概述
packages/renderless/src/common/validate/util.ts, packages/renderless/src/currency/index.ts, packages/renderless/src/file-upload/index.ts, packages/renderless/src/tree/index.ts, packages/renderless/src/user/index.ts 将log替换为logger,确保只使用warn和error方法。
packages/utils/src/index.ts 更新导出名称,从log改为logger。
packages/utils/src/log/index.ts 删除log模块。
packages/utils/src/logger/index.ts 新增logger模块,替代原log模块。
packages/vue-common/src/breakpoint.ts 修改示例代码中的console.log调用。
packages/vue/src/grid/src/tools/logger.ts 将log替换为logger。

@@ -555,7 +555,7 @@ export const handleStart =
state,
vm
}: Pick<IFileUploadRenderlessParams, 'api' | 'constants' | 'props' | 'state' | 'vm'>) =>
(rawFiles: IFileUploadFile[], updateId: string, reUpload: boolean = false) => {
(rawFiles: IFileUploadFile[], updateId: string, reUpload = false) => {

Choose a reason for hiding this comment

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

The default parameter syntax has been simplified from reUpload: boolean = false to reUpload = false. Ensure that this change does not affect the expected behavior of the function.

@@ -900,7 +900,7 @@ export const abort =

export const abortDownload =
({ state }: Pick<IFileUploadRenderlessParams, 'state'>) =>
(file: IFileUploadFile, batch: boolean = false) => {
(file: IFileUploadFile, batch = false) => {

Choose a reason for hiding this comment

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

The default parameter syntax has been simplified from batch: boolean = false to batch = false. Ensure that this change does not affect the expected behavior of the function.

@@ -2263,7 +2263,7 @@ export const getToken =

export const previewFile =
({ api, props }: Pick<IFileUploadRenderlessParams, 'api' | 'props'>) =>
(file: IFileUploadFile, open: boolean = false) => {
(file: IFileUploadFile, open = false) => {

Choose a reason for hiding this comment

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

The default parameter syntax has been simplified from open: boolean = false to open = false. Ensure that this change does not affect the expected behavior of the function.

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Walkthrough

This PR renames the export names in the utils module from log to logger and ensures that all loggers only use the warn and error methods. Note that the files in the packages/mobile directory have not been modified.

Changes

File path Overview
packages/renderless/src/common/validate/util.ts, packages/renderless/src/currency/index.ts, packages/renderless/src/file-upload/index.ts, packages/renderless/src/tree/index .ts, packages/renderless/src/user/index.ts Replace log with logger, making sure to only use the warn and error methods.
packages/utils/src/index.ts Update the export name from log to logger.
packages/utils/src/log/index.ts Delete the log module.
packages/utils/src/logger/index.ts Add a new logger module to replace the original log module.
packages/vue-common/src/breakpoint.ts Modify the console.log call in the sample code.
packages/vue/src/grid/src/tools/logger.ts Replace log with logger.

Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

@shenjunjian shenjunjian changed the title refactor(utils): rename log to logger refactor(utils): [grid,tree] rename log to logger Jan 20, 2025
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: 0

🧹 Nitpick comments (4)
packages/utils/src/logger/index.ts (2)

3-3: Consider stricter typing for window object.

Using any type bypasses TypeScript's type checking. Consider using a more specific type or interface that defines the expected shape of the window object.

-const _win: any = getWindow()
+interface WindowWithConsole {
+  console: Console;
+}
+const _win = getWindow() as WindowWithConsole

4-5: Improve documentation and error handling.

  1. Consider translating the Chinese comment to English for consistency.
  2. Add error handling for environments where window/console might not be available.
-/** 使用 logger.xxx 代替 window.console.xxx, 避免语法警告 */
+/** Use logger.xxx instead of window.console.xxx to avoid syntax warnings in strict mode */
-export const logger = _win.console as Console
+export const logger = (_win?.console || console) as Console
packages/vue/src/grid/src/tools/logger.ts (1)

Line range hint 4-11: Add type safety for logger methods.

The type parameter should be restricted to valid logger methods to prevent runtime errors.

-const outLog = (type) => (message, detail) => {
+type LogLevel = 'warn' | 'error';
+const outLog = (type: LogLevel) => (message: string, detail?: string) => {
packages/renderless/src/currency/index.ts (1)

79-79: Enhance warning message with more context.

The current warning message is generic. Consider including more details about the data error to help with debugging.

-logger.warn('data error. set it to the default value.')
+logger.warn(`Currency data error: Missing ${valueField} and ${textField}. Falling back to default value: ${props.currency}`)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e29aaf and 32b7107.

📒 Files selected for processing (11)
  • packages/renderless/src/common/validate/util.ts (3 hunks)
  • packages/renderless/src/currency/index.ts (2 hunks)
  • packages/renderless/src/file-upload/index.ts (8 hunks)
  • packages/renderless/src/tree/index.ts (2 hunks)
  • packages/renderless/src/user/index.ts (2 hunks)
  • packages/utils/src/index.ts (1 hunks)
  • packages/utils/src/log/index.ts (0 hunks)
  • packages/utils/src/logger/index.ts (1 hunks)
  • packages/vue-common/package.json (1 hunks)
  • packages/vue-common/src/breakpoint.ts (1 hunks)
  • packages/vue/src/grid/src/tools/logger.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/utils/src/log/index.ts
✅ Files skipped from review due to trivial changes (3)
  • packages/utils/src/index.ts
  • packages/vue-common/src/breakpoint.ts
  • packages/renderless/src/tree/index.ts
🔇 Additional comments (4)
packages/renderless/src/common/validate/util.ts (1)

211-211: LGTM! Error handling implementation is robust.

The code correctly distinguishes between validation errors (which have errors and fields properties) and actual errors that should be logged.

Also applies to: 247-247

packages/renderless/src/user/index.ts (1)

17-17: LGTM! Import and usage of logger updated correctly.

The changes correctly implement the new logging pattern:

  1. Import statement updated from log to logger
  2. Usage updated from log.logger.warn to logger.warn

Also applies to: 142-142

packages/renderless/src/file-upload/index.ts (1)

33-33: LGTM! Logger import and usage updated consistently.

All instances of the logger have been correctly updated:

  1. Import statement changed from log to logger
  2. Four instances of log.logger.warn updated to logger.warn
  3. Warning message formats preserved

Also applies to: 1688-1688, 1697-1697, 1935-1935, 1945-1945

packages/vue-common/package.json (1)

34-34: LGTM! Required dependency added correctly.

The @opentiny/utils dependency has been properly added with workspace resolution, which is required for the logger functionality.

@zzcr zzcr merged commit f251353 into opentiny:dev Jan 20, 2025
16 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 26, 2025
13 tasks
@shenjunjian shenjunjian deleted the refactor-log branch March 10, 2025 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants