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: sync log #93

Merged
merged 2 commits into from
Oct 18, 2024
Merged

feat: sync log #93

merged 2 commits into from
Oct 18, 2024

Conversation

elrrrrrrr
Copy link
Member

@elrrrrrrr elrrrrrrr commented Oct 18, 2024

  • 🎨 取消重复的查看日志信息弹框 cc @yoyo837

Summary by CodeRabbit

  • New Features

    • Introduced a new status display for log operations with improved messaging.
    • Enhanced button functionality to reflect log status and loading states.
  • Bug Fixes

    • Improved error handling for log polling with a defined maximum retry limit.
  • Refactor

    • Updated state management for better clarity and maintainability.

@elrrrrrrr elrrrrrrr added the enhancement New feature or request label Oct 18, 2024
Copy link

vercel bot commented Oct 18, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
cnpmweb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2024 6:26am

Copy link

coderabbitai bot commented Oct 18, 2024

Walkthrough

The pull request introduces several modifications to the Sync component located in src/components/Sync.tsx. Key changes include the addition of a constant MAX_RETRY, the replacement of the LogStatus object with an enum that includes an INIT state, and the creation of a mapping object, LogStatusTextMap, for status messages. The state management for logState is updated, the showLog function is removed, and the button's behavior is streamlined. The polling logic is adjusted to utilize MAX_RETRY, enhancing the overall structure and readability of the code.

Changes

File Change Summary
src/components/Sync.tsx - Added enum LogStatus with an INIT state.
- Introduced constant const MAX_RETRY with a value of 30.
- Created const LogStatusTextMap for associating LogStatus values with text messages.
- Updated logState initialization to LogStatus.INIT.
- Removed showLog function; integrated its functionality into button's onClick handler.
- Adjusted button's loading state based on logState.
- Modified polling logic to use MAX_RETRY and set state to LogStatus.ERROR if exceeded.

Possibly related PRs

  • 修复文件延迟访问的问题,加个轮询 #92: This PR also modifies the Sync component in src/components/Sync.tsx, introducing a LogStatus object and updating the state management for logState, which directly relates to the changes made in the main PR regarding the enum and state initialization.

Poem

In the land of code where rabbits hop,
A Sync component made a big swap.
With enums and retries, it found its way,
Now buttons click bright, come what may!
Hooray for the changes, let the logs flow,
A joyful codebase, watch it grow! 🐇✨


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

@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: 2

🧹 Outside diff range and nitpick comments (2)
src/components/Sync.tsx (2)

53-55: Standardize the order in equality comparisons

In the condition if (LogStatus.WAIT !== logState), consider placing the variable logState on the left side for consistency and readability, i.e., if (logState !== LogStatus.WAIT). This is a common convention that enhances code clarity.

Apply this change:

-if (LogStatus.WAIT !== logState) {
+if (logState !== LogStatus.WAIT) {
  setLogState(LogStatus.WAIT);
}

19-24: Consider implementing internationalization (i18n) for status messages

The LogStatusTextMap uses Chinese text for status messages. If the application is intended for a broader audience or may support multiple languages in the future, consider integrating internationalization to handle translations dynamically.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7d98385 and 2ee5a5b.

📒 Files selected for processing (1)
  • src/components/Sync.tsx (4 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/components/Sync.tsx (1)

88-94: Ensure logId is defined before using non-null assertion

In the href attribute of the Button, you're using logId! with a non-null assertion. While logState === LogStatus.SUCCESS implies that logId should be defined, it's safer to ensure that logId is indeed defined to prevent potential runtime errors. Consider adding a conditional check or adjusting the logic to guarantee logId is defined when needed.

Run the following script to verify that logId is always defined when logState is LogStatus.SUCCESS:

Comment on lines +88 to +95
href={logState === LogStatus.SUCCESS ? genLogFileUrl(logId!) : undefined}
target='_blank'
onClick={() => {
if (!logId) {
doSync();
return;
}
}}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Review the use of both href and onClick on the Button component

Using both href and onClick on the Button can lead to unexpected behaviors. In Ant Design, when href is provided, the button renders as an anchor tag. Since you're also using onClick, it's important to ensure that the combination doesn't cause any issues. Consider separating the concerns:

  • When logState === LogStatus.SUCCESS, render the button as a link.
  • Otherwise, use the onClick handler for initiating the sync.

Here's a possible refactor:

<Button
  size="small"
  type="primary"
  loading={logState === LogStatus.WAIT}
  {...(logState === LogStatus.SUCCESS
    ? {
        href: genLogFileUrl(logId!),
        target: '_blank',
      }
    : {
        onClick: () => {
          if (!logId) {
            doSync();
          }
        },
      })}
>
  {LogStatusTextMap[logState]}
</Button>

Comment on lines +49 to +58
if (retryCountRef.current > MAX_RETRY) {
setLogState(LogStatus.ERROR);
return;
} else {
if (LogStatus.WAIT !== logState) {
setLogState(LogStatus.WAIT);
}
setTimeout(() => {
logPolling(id);
}, 1000);
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Reset retryCountRef.current when initiating a new sync task

Currently, retryCountRef.current is not reset when starting a new sync task. This could lead to incorrect retry counts if the user initiates multiple syncs without refreshing the page, potentially causing the polling to stop prematurely. Please reset retryCountRef.current to 0 at the start of the doSync function to ensure accurate retry counts for each sync operation.

Apply this diff to fix the issue:

async function doSync() {
+  retryCountRef.current = 0;
   try {
     const response = await fetch(`${SYNC_REGISTRY}/-/package/${pkgName}/syncs`, {
       method: 'PUT',
     })

Committable suggestion was skipped due to low confidence.

@fengmk2 fengmk2 merged commit c1b9fa7 into master Oct 18, 2024
6 checks passed
@fengmk2 fengmk2 deleted the sync-log branch October 18, 2024 08:10
@coderabbitai coderabbitai bot mentioned this pull request Oct 21, 2024
@yoyo837
Copy link
Contributor

yoyo837 commented Oct 21, 2024

image

“查看日志”时文字看看不见了,需要hover @elrrrrrrr

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

Successfully merging this pull request may close these issues.

3 participants