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: override accent secondary with chain color #24

Merged
merged 6 commits into from
Mar 10, 2024
Merged

Conversation

rossbulat
Copy link
Collaborator

@rossbulat rossbulat commented Mar 10, 2024

Summary by Ross

Adds chain colors and overrides --accent-color-secondary for chain UI.

Summary by CodeRabbit

  • Style
    • Streamlined the codebase by removing unused accent color variables and specific accent color declarations in CSS theme files to enhance performance.
    • Introduced accent color definitions for a developer console theme in a new file.
  • New Features
    • Extended functionality in the PageWithMenu component to dynamically set accent colors based on the active chain ID.
    • Implemented an override for tab color in the Menu.tsx file to match the primary color.

Copy link

coderabbitai bot commented Mar 10, 2024

Walkthrough

The recent updates focus on improving accent color management throughout the project. Changes include dynamic accent color setting based on the active chain ID in PageWithMenu and the introduction of accent color definitions for a developer console theme in developer-console.ts.

Changes

File Path Change Summary
src/IntegrityChecks/index.ts Updated sanitizeKeysForTabExistence and sanitizeAppliedTags using Object.fromEntries and reduce. Changed assignment in sanitizeTags.
src/theme/accents/kusama-relay.css,
src/theme/accents/polkadot-relay.css,
src/theme/accents/westend-relay.css
Removed declarations related to tertiary, stroke, transparent, and pending accent colors.
src/screens/Common/PageWithMenu/index.tsx Extended PageWithMenu to dynamically set accent colors based on chain ID.
src/screens/Settings/Menu.tsx Overrode tab color to match primary color.
src/theme/accents/developer-console.ts Introduced accent color definitions for a developer console theme.

🐇✨
Amidst the code's dance, colors take flight,
Unused hues vanish, streamlining in the night.
Kusama, Polkadot, and Westend too,
Shedding accents old, embracing the new.
🎨 Let the styles sing, in simplicity's grace,
A cleaner palette, a more refined space.
🐾💻


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>.
    • Generate unit-tests 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 tests 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@rossbulat rossbulat changed the title fgeat: override accent secondary with chain color feat: override accent secondary with chain color Mar 10, 2024
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between de213ea and 0ae03f0.
Files selected for processing (3)
  • src/config/networks/index.ts (5 hunks)
  • src/library/HeaderMenu/Wrappers.ts (3 hunks)
  • src/screens/Common/PageWithMenu/index.tsx (1 hunks)
Additional comments: 7
src/screens/Common/PageWithMenu/index.tsx (1)
  • 16-24: The logic for determining the chain-specific color and applying it as an accent color is clear and straightforward. However, there are a few considerations and potential improvements:
  1. Fallback Color Hardcoding: The fallback color (#552bbf) is hardcoded within the component. It might be more maintainable to define this color in a centralized configuration or theme file. This approach would make it easier to update the color in the future and ensure consistency across the application.

  2. Error Handling: There's no explicit error handling if the chainId does not exist within the NetworkDirectory. While the current logic defaults to the hardcoded fallback color, it might be beneficial to log an error or warning for debugging purposes, especially during development.

  3. Performance Consideration: The current implementation recalculates the color variable on every render. If the calculation of the color based on the chainId becomes more complex in the future, consider memoizing the color variable using useMemo to avoid unnecessary recalculations.

Consider defining the fallback color in a centralized configuration or theme file for better maintainability. Additionally, evaluate the need for error handling and performance optimizations as the application evolves.

src/library/HeaderMenu/Wrappers.ts (4)
  • 49-49: The update to use --accent-color-secondary for the hover state of buttons within the HeaderMenuWrapper is consistent with the PR's objective to integrate chain-specific colors into the UI. This change enhances the visual appeal and consistency across different blockchain networks.
  • 52-52: The use of --accent-color-secondary for the active state of buttons aligns with the PR's goal and ensures a cohesive user experience by reflecting the active blockchain network's color scheme.
  • 93-93: Similarly, the update in the ButtonWrapper component to use --accent-color-secondary for the hover state of buttons is a good application of the PR's objectives, ensuring visual consistency across the application.
  • 103-103: Applying --accent-color-secondary for the color of SVG icons in the active state of buttons within the ButtonWrapper component is a thoughtful detail that contributes to the overall aesthetic and consistency of the UI.
src/config/networks/index.ts (2)
  • 17-17: The addition of the color field to the NetworkDirectoryItem interface is a crucial update that supports the PR's objective of integrating chain-specific colors into the UI. This change enables the dynamic application of accent colors based on the active blockchain network.
  • 31-31: Assigning specific color values to the different networks within the NetworkDirectory constant is a foundational step for achieving visual consistency across blockchain networks. It's important to ensure that these color values are accurate representations of their respective networks to maintain the intended visual appeal and user experience.

Also applies to: 50-50, 69-69, 80-80

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 0ae03f0 and a7ed361.
Files selected for processing (4)
  • src/theme/accents/developer-console.css (1 hunks)
  • src/theme/accents/kusama-relay.css (1 hunks)
  • src/theme/accents/polkadot-relay.css (1 hunks)
  • src/theme/accents/westend-relay.css (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/theme/accents/developer-console.css
  • src/theme/accents/polkadot-relay.css
Additional comments: 1
src/theme/accents/kusama-relay.css (1)
  • 7-10: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-9]

The changes align with the PR's objectives by focusing on primary and secondary accent colors for the Kusama relay chain. As with the Westend relay theme, ensure that the removal of other accent colors does not negatively impact UI components that may depend on them.

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a7ed361 and 2596e1c.
Files selected for processing (3)
  • src/screens/Common/PageWithMenu/index.tsx (1 hunks)
  • src/screens/Settings/Menu.tsx (1 hunks)
  • src/theme/accents/developer-console.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • src/theme/accents/developer-console.ts
Files skipped from review as they are similar to previous changes (1)
  • src/screens/Common/PageWithMenu/index.tsx

Comment on lines +19 to +21
style={Object.fromEntries([
['--accent-color-secondary', accentColors.primary.light],
])}
Copy link

Choose a reason for hiding this comment

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

The implementation of dynamic accent color application by overriding --accent-color-secondary with accentColors.primary.light is a good approach to ensure UI consistency with the active chain's color scheme. However, consider the following points for improvement:

  1. Performance Consideration: Directly manipulating styles through inline styles can be less efficient than using CSS classes, especially if these styles need to be dynamically updated often. If the accent color changes frequently, consider using a CSS class and modifying the class based on the active chain.

  2. Maintainability: Inline styles can sometimes make the code harder to maintain, especially if there are multiple places where the accent color needs to be overridden. It might be beneficial to centralize the styling logic or use a context/provider to manage the theme colors dynamically across the application.

  3. Fallback Value: Ensure there's a fallback value for accentColors.primary.light in case it's undefined for some reason. This helps in maintaining a consistent UI experience even when unexpected issues arise.

@rossbulat rossbulat merged commit ea286b7 into main Mar 10, 2024
4 checks passed
@rossbulat rossbulat deleted the rb-chain-styling branch March 10, 2024 11:41
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.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2596e1c and 2069822.
Files selected for processing (1)
  • src/IntegrityChecks/index.ts (4 hunks)

Comment on lines +70 to +84
entries?: Record<string, string>
) => {
const result = entries;
let updated = false;
const updated = false;

if (result) {
Object.entries(result).forEach(([tabId, entry]) => {
if (!activeTabs?.find(({ id }) => id === Number(tabId)) || entry === '') {
delete result[Number(tabId)];
updated = true;
}
});
}
const result = Object.fromEntries(
Object.entries(entries || {}).reduce(
(acc: [string, string][], [tabId, entry]) => {
if (activeTabs.find(({ id }) => id === Number(tabId)) && entry !== '') {
return acc.concat([[tabId, entry]]);
}
return acc;
},
[]
)
);
Copy link

Choose a reason for hiding this comment

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

The implementation of sanitizeKeysForTabExistence using Object.fromEntries and reduce is correct and efficient for filtering and constructing the result object based on the existence of tabs. However, the variable updated is initialized but never changed within the function, which might indicate an oversight or unfinished logic. Consider if the updated flag should reflect changes made during the sanitization process.

@@ -109,7 +110,7 @@ export const sanitizeTags = ({
for (const chain of chains) {
if (!NetworkDirectory[chain]) {
// If error, fallback to defaults if exist, otherwise filter out the chain.
result[tagId] =
result.tagId =
Copy link

Choose a reason for hiding this comment

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

In sanitizeTags, the assignment to result.tagId seems incorrect. This line attempts to assign a value to a property named tagId on the result object, which does not dynamically reference the current tagId being iterated over. Instead, it should use bracket notation to correctly assign the value to the dynamic key represented by tagId.

- result.tagId =
+ result[tagId] =

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
result.tagId =
result[tagId] =

Comment on lines +143 to +163
const updated = false;

if (result) {
Object.entries(appliedTags).forEach(([tabId, applied]) => {
if (!activeTabs?.find(({ id }) => id === Number(tabId))) {
delete result[Number(tabId)];
updated = true;
} else {
const result = Object.fromEntries(
Object.entries(appliedTags || {}).reduce(
(acc: [string, string[]][], [tabId, applied]) => {
if (!activeTabs?.find(({ id }) => id === Number(tabId))) {
return acc;
}
// Check if each `applied` value is a valid tag id, and remove otherwise.
applied.forEach((tagId) => {
applied = applied.reduce((acc2: string[], tagId) => {
if (!tags?.[tagId]) {
result[Number(tabId)].splice(applied.indexOf(tagId), 1);
updated = true;
return acc2;
}
});
}
});
}
return acc2.concat(tagId);
}, []);

return acc.concat([[tabId, applied]]);
},
[]
)
);
Copy link

Choose a reason for hiding this comment

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

The sanitizeAppliedTags function correctly uses Object.fromEntries and reduce to filter and construct the result object. The logic for filtering out invalid tab IDs and ensuring that each applied value is a valid tag ID is implemented correctly. However, similar to sanitizeKeysForTabExistence, the updated variable is initialized but never modified. If the intention is to track whether any changes have been made during the sanitization process, ensure that the updated flag is appropriately updated.

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

Successfully merging this pull request may close these issues.

1 participant