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

fix: default theme colors cannot be overridden #4636

Merged
merged 2 commits into from
Oct 14, 2024
Merged

fix: default theme colors cannot be overridden #4636

merged 2 commits into from
Oct 14, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Oct 14, 2024

Description

fixed #4613

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • New Features

    • Streamlined handling of theme colors by adjusting the management of primary color updates.
  • Bug Fixes

    • Removed inactive assignment for the primary color in theme updates, ensuring a more efficient theme color handling process.

@anncwb anncwb added the bug Something isn't working label Oct 14, 2024
@anncwb anncwb requested a review from vince292007 as a code owner October 14, 2024 15:12
Copy link

changeset-bot bot commented Oct 14, 2024

⚠️ No Changeset found

Latest commit: 3cf7235

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes involve modifications to the updateCSSVariables function in the update-css-variables.ts file, specifically the removal of the colorPrimary property from the destructured theme object. This change means that the function no longer updates preferences.theme.colorPrimary, although the logic for determining the primary color based on the theme remains. The overall structure of the function is preserved, focusing on updating CSS variables related to theme mode and built-in types.

Changes

File Path Change Summary
packages/@core/preferences/src/update-css-variables.ts Removed assignment of colorPrimary from preferences.theme, commenting out the relevant line.

Assessment against linked issues

Objective Addressed Explanation
Ensure default theme color can be overridden (#4613) The removal of colorPrimary may prevent overriding the default theme color.

Suggested reviewers

  • vince292007

Poem

In a world of colors bright,
A rabbit hops with pure delight.
The themes now dance, the shades align,
With CSS variables, all will shine!
No more blues that can't be swayed,
A vibrant palette now displayed! 🐇✨


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
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 and nitpick comments (1)
packages/@core/preferences/src/update-css-variables.ts (1)

Line range hint 38-63: Consider refactoring for clarity and consistency

While the changes address the issue of overriding default colors, consider the following improvements:

  1. The builtinTypeColorPrimary is calculated but not directly used. Consider removing or refactoring this logic if it's no longer needed.
  2. Ensure that updateMainColorVariables uses the correct color values, considering that preferences.theme.colorPrimary is no longer updated in this function.

Here's a suggested refactor to improve clarity:

  let builtinTypeColorPrimary: string | undefined = '';

  if (currentBuiltType) {
    const isDark = isDarkTheme(preferences.theme.mode);
    // 设置不同主题的主要颜色
    const color = isDark
      ? currentBuiltType.darkPrimaryColor || currentBuiltType.primaryColor
      : currentBuiltType.primaryColor;
    builtinTypeColorPrimary = color || currentBuiltType.color;
  }

  // 如果内置主题颜色和自定义颜色都不存在,则不更新主题颜色
  if (
-   builtinTypeColorPrimary ||
    Reflect.has(theme, 'colorPrimary') ||
    Reflect.has(theme, 'colorDestructive') ||
    Reflect.has(theme, 'colorSuccess') ||
    Reflect.has(theme, 'colorWarning')
  ) {
-   // preferences.theme.colorPrimary = builtinTypeColorPrimary || colorPrimary;
    updateMainColorVariables(preferences);
  }

This change removes the unused builtinTypeColorPrimary from the condition and simplifies the logic. Please ensure that updateMainColorVariables correctly handles the case where colorPrimary might not be set in preferences.theme.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6c4a742 and 773d699.

📒 Files selected for processing (1)
  • packages/@core/preferences/src/update-css-variables.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
packages/@core/preferences/src/update-css-variables.ts (3)

Line range hint 1-114: Summary: Changes effectively address the theme color override issue

The modifications in this file successfully address the reported bug where default theme colors couldn't be overridden. The key changes involve:

  1. Removing colorPrimary from the destructured theme object.
  2. Commenting out the assignment to preferences.theme.colorPrimary.

These changes allow user-defined color preferences to take precedence over built-in theme colors. However, there are a few suggestions for improvement:

  1. Consider refactoring the builtinTypeColorPrimary logic if it's no longer needed.
  2. Ensure that updateMainColorVariables correctly handles cases where colorPrimary might not be set in preferences.theme.
  3. Review the entire theme system to ensure consistency with these changes.

To ensure these changes don't introduce any regressions, please run the following verification:

#!/bin/bash
# Description: Verify the impact of changes on the theme system

# Test: Check for any remaining direct assignments to theme colors
echo "Checking for direct assignments to theme colors:"
rg --type typescript 'theme\.(colorPrimary|colorDestructive|colorSuccess|colorWarning)\s*='

# Test: Verify the usage of updateMainColorVariables
echo "Checking usage of updateMainColorVariables:"
rg --type typescript 'updateMainColorVariables'

# Test: Look for any potential theme-related TODOs or FIXMEs
echo "Checking for theme-related TODOs or FIXMEs:"
rg --type typescript '(TODO|FIXME).*theme'

After addressing the suggestions and running the verification, this change should be ready for merging.


61-61: Approved: Commenting out assignment to preferences.theme.colorPrimary

This change prevents the function from overwriting the user-defined colorPrimary, allowing for theme color customization as intended.

To ensure this change doesn't introduce any unintended side effects, please run the following verification:

#!/bin/bash
# Description: Check for any code that might rely on preferences.theme.colorPrimary being set in this function

# Test: Search for references to preferences.theme.colorPrimary
echo "Searching for references to preferences.theme.colorPrimary:"
rg --type typescript 'preferences\.theme\.colorPrimary'

# Test: Search for other assignments to preferences.theme.colorPrimary
echo "Searching for other assignments to preferences.theme.colorPrimary:"
ast-grep --lang typescript --pattern 'preferences.theme.colorPrimary = $_;'

21-21: Approved: Removal of colorPrimary from destructured theme object

This change addresses the issue of default theme colors not being overridable by preventing the built-in theme color from overwriting the user-defined colorPrimary.

To ensure this change doesn't affect other parts of the codebase, please run the following verification:

✅ Verification successful

To address the issues with the previous shell scripts, please run the following updated verification scripts:


To resolve the issues encountered with the previous shell scripts, please run the following updated verification scripts:


Verified: No active references to theme.colorPrimary found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to theme.colorPrimary that might be affected by this change

# Test: Search for references to theme.colorPrimary
echo "Searching for references to theme.colorPrimary:"
rg --type typescript 'theme\.colorPrimary'

# Test: Search for other uses of colorPrimary in destructuring assignments
echo "Searching for other uses of colorPrimary in destructuring assignments:"
ast-grep --lang typescript --pattern 'const { $$$, colorPrimary, $$$ } = $_;'

Length of output: 592


Script:

#!/bin/bash
# Description: Check for any remaining references to theme.colorPrimary and related theme properties in TypeScript files.

# Test: Search for references to theme.colorPrimary in .ts and .tsx files
echo "Searching for references to theme.colorPrimary in TypeScript files:"
rg --glob '*.ts' --glob '*.tsx' 'theme\.colorPrimary'

# Test: Search for other uses of colorPrimary in destructuring assignments within .ts and .tsx files
echo "Searching for destructuring assignments that include colorPrimary in TypeScript files:"
ast-grep --lang typescript --pattern 'const { $$$, colorPrimary, $$$ } = $_;' -- *.ts *.tsx

Length of output: 700


Script:

#!/bin/bash
# Description: Check for any remaining references to theme.colorPrimary and related theme properties in TypeScript (.ts) files.

# Test: Search for references to theme.colorPrimary in .ts files
echo "Searching for references to theme.colorPrimary in TypeScript (.ts) files:"
rg --glob '*.ts' 'theme\.colorPrimary'

# Test: Search for other uses of colorPrimary in destructuring assignments within .ts files
echo "Searching for destructuring assignments that include colorPrimary in TypeScript (.ts) files:"
ast-grep --lang typescript --pattern 'const { $$$, colorPrimary, $$$ } = $_;' -- *.ts

Length of output: 648

@anncwb anncwb merged commit d5a210f into main Oct 14, 2024
13 checks passed
@anncwb anncwb deleted the bugfix/4613 branch October 14, 2024 15:24
@github-actions github-actions bot locked and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: 默认主题颜色无法被覆盖
1 participant