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

chore: remove typography selection in app theming #36110

Merged
merged 8 commits into from
Sep 13, 2024

Conversation

jsartisan
Copy link
Contributor

@jsartisan jsartisan commented Sep 4, 2024

/ok-to-test tags="@tag.All"

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced new hooks for icon management: useIconDensity and useIconSizing.
  • Improvements

    • Refactored hooks to enhance performance by using useMemo instead of state management, leading to more efficient calculations for icon size, density, spacing, and typography.
    • Streamlined theme management by consolidating logic and removing unnecessary properties, improving clarity and maintainability.
    • Optimized CSS class name management within the useCssTokens hook for better performance.
  • Bug Fixes

    • Removed fontFamily property from various components, which may affect text rendering but simplifies font management.
  • Documentation

    • Updated comments and documentation to reflect changes in typography and theme handling.

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10786030048
Commit: a0d1258
Cypress dashboard.
Tags: @tag.All
Spec:


Tue, 10 Sep 2024 06:00:30 UTC

@jsartisan jsartisan requested a review from a team as a code owner September 4, 2024 07:27
Copy link
Contributor

coderabbitai bot commented Sep 4, 2024

Walkthrough

This update introduces several enhancements to the design system's theming hooks, focusing on optimizing performance by replacing state management with memoization. Key hooks like useIconDensity, useIconSizing, and others have been refactored for improved efficiency. Additionally, typography management has been simplified by removing the fontFamily property, resulting in a more streamlined theme configuration process.

Changes

File Path Change Summary
app/client/packages/design-system/theming/src/hooks/src/index.ts Added exports for useIconDensity and useIconSizing.
app/client/packages/design-system/theming/src/hooks/src/useIconDensity.tsx Refactored to use useMemo for calculating strokeWidth, improving performance and clarity.
app/client/packages/design-system/theming/src/hooks/src/useIconSizing.tsx Refactored to use useMemo for calculating iconSize, enhancing performance and simplifying logic.
app/client/packages/design-system/theming/src/hooks/src/useSizing.tsx Optimized getSizing function with useMemo and defined return type as TokenObj.
app/client/packages/design-system/theming/src/hooks/src/useSpacing.tsx Refactored state management for outerSpacing and innerSpacing to use useMemo, improving performance.
app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx Consolidated theme updates in a single useMemo hook, removed fontFamily from UseThemeProps, and optimized theme logic.
app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx Refactored typography management to use useMemo, removing the fontFamily parameter for simplification.
app/client/src/pages/AppViewer/index.tsx Enhanced type safety in theme properties, integrating ColorMode and IconStyle, and simplifying theme logic.
app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx Optimized management of CSS class names by replacing state management with useMemo, simplifying the fontFamilyCss function.
app/client/cypress/e2e/Regression/ClientSide/Anvil/AppTheming/AnvilAppThemingSnapshot_spec.ts Reorganized test cases for app theming, removing the "Typography" test and renumbering subsequent tests.

Assessment against linked issues

Objective Addressed Explanation
Improve typography handling (#[21632])
Set default font to system default (#[21632])
Simplify theme customization options (#[21632])
  • fix: Video2 spec flaky fix #36166: The changes in this PR involve modifications to the useCssTokens hook, which optimizes CSS class name management, similar to the refactoring of hooks in the main PR that enhances performance and clarity in icon management through useIconDensity and useIconSizing.

🌟 In the realm of code, changes do unfold,
Performance shines bright, as new tales are told.
With hooks refined, and typography clear,
A streamlined design, we all hold dear!
🎨✨

Tip

Announcements
  • The review status is no longer posted as a separate comment when there are no actionable or nitpick comments. In such cases, the review status is included in the walkthrough comment.
  • We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.
  • Possibly related PRs: Walkthrough comment now includes a list of potentially related PRs to help you recall past context. Please share any feedback in the discussion post on our Discord.
  • Suggested labels: CodeRabbit can now suggest labels by learning from your past PRs in the walkthrough comment. You can also provide custom labeling instructions in the UI or configuration file.
  • Possibly related PRs, automatic label suggestions based on past PRs, learnings, and possibly related issues require data opt-in (enabled by default).

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 80b57fd and a0d1258.

Files selected for processing (1)
  • app/client/cypress/e2e/Regression/ClientSide/Anvil/AppTheming/AnvilAppThemingSnapshot_spec.ts (4 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/cypress/e2e/Regression/ClientSide/Anvil/AppTheming/AnvilAppThemingSnapshot_spec.ts

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

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.

@jsartisan jsartisan changed the title remove typography selection chore: remove typography selection in app theming Sep 4, 2024
@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Sep 4, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 420dc9b and 6adeed0.

Files selected for processing (9)
  • app/client/packages/design-system/theming/src/hooks/src/index.ts (1 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useIconDensity.tsx (1 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useIconSizing.tsx (1 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useSizing.tsx (3 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useSpacing.tsx (2 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx (4 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx (2 hunks)
  • app/client/src/pages/Editor/Canvas.tsx (1 hunks)
  • app/client/src/pages/Editor/WDSThemePropertyPane/index.tsx (4 hunks)
Additional comments not posted (16)
app/client/packages/design-system/theming/src/hooks/src/index.ts (2)

6-6: Great work on adding the useIconDensity export! 👍

This new export enhances the functionality of the module by providing a custom hook for managing icon density within the design system. It can be utilized in other parts of the application to improve the flexibility and customization of icon rendering.

The export is properly declared and follows the existing pattern of the module.


7-7: Excellent addition of the useIconSizing export! 🌟

This new export further enhances the functionality of the module by providing a custom hook for managing icon sizing within the design system. It can be utilized in other parts of the application to improve the flexibility and customization of icon sizing.

The export is properly declared and follows the existing pattern of the module.

app/client/packages/design-system/theming/src/hooks/src/useIconSizing.tsx (1)

Line range hint 1-21: Great job refactoring the useIconSizing hook! The changes have improved performance and readability. 👍

The refactoring has several benefits:

  1. By replacing useState and useEffect with useMemo, the hook now directly computes the icon size based on the userSizing and sizing parameters. This eliminates the need for state updates and side effects, reducing unnecessary re-renders and improving performance.

  2. The use of useMemo is appropriate here because the icon size only needs to be recomputed when the userSizing or sizing parameters change. This ensures that the computed value is memoized and reused unless the dependencies change.

  3. The conditional statements in the useMemo callback cover all possible cases for userSizing and return the appropriate icon size based on the provided sizing object. This makes the logic clear and easy to understand.

  4. The hook has a clear and concise implementation, with a single responsibility of computing the icon size based on the provided parameters.

Overall, the refactoring has resulted in a more efficient and maintainable hook. Keep up the good work!

app/client/packages/design-system/theming/src/hooks/src/useIconDensity.tsx (1)

Line range hint 1-21: Great job refactoring the useIconDensity hook! The changes look excellent. 👍

I really like how you've simplified the logic by replacing useState and useEffect with useMemo. This change not only improves performance by avoiding unnecessary re-renders but also makes the code more readable and maintainable.

The conditional statements used to determine the value of strokeWidth based on userDensity are clear and concise. It's easy to understand the flow of the logic and how the appropriate value is returned.

Additionally, specifying the type of userDensity as number in the hook signature is a nice touch. It provides clarity and helps catch potential type-related issues.

Overall, these changes enhance the efficiency and maintainability of the useIconDensity hook. Well done!

app/client/packages/design-system/theming/src/hooks/src/useSizing.tsx (2)

11-11: Great job explicitly defining the return type of getSizing! 👍

Specifying the return type as TokenObj improves type safety and makes the code more self-documenting. This change enhances the clarity and maintainability of the codebase.


38-40: Excellent refactoring of the useSizing hook! 🌟

By replacing useState and useEffect with useMemo, you have optimized the performance of the hook. The sizing value is now memoized based on its dependencies (config, userDensity, and userSizing), ensuring that it is recalculated only when necessary.

This change reduces unnecessary computations and improves the rendering efficiency of components that utilize the useSizing hook. Well done on implementing this performance optimization!

app/client/packages/design-system/theming/src/hooks/src/useSpacing.tsx (2)

39-41: Great use of useMemo for performance optimization! 👍

By wrapping the getSpacing function call with useMemo, you are ensuring that the outerSpacing value is only recalculated when one of its dependencies (outerSpacingConfig, userDensity, or userSizing) changes. This memoization technique helps avoid unnecessary re-computations and improves the overall performance of the component.

Keep up the good work in leveraging React's capabilities effectively!


43-45: Excellent application of useMemo for innerSpacing as well! 🌟

Just like with outerSpacing, you have effectively utilized useMemo to memoize the result of the getSpacing function call for innerSpacing. By specifying the dependencies as innerSpacingConfig, userDensity, and userSizing, you ensure that the memoized value is only recalculated when necessary.

This optimization technique enhances the efficiency of the component by reducing unnecessary re-renders and improving performance. Well done on consistently applying this concept throughout the code!

app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx (1)

67-69: Great job refactoring the useTypography hook! The changes look good to me.

The refactor improves the efficiency of the hook by:

  • Replacing useState and useEffect with useMemo to avoid unnecessary re-renders and state updates.
  • Calculating the typography value synchronously based on the dependencies of config, userDensity, and userSizing.

Additionally, removing the fontFamily parameter from the function signature simplifies the API for users of this hook, indicating a shift in how typography is configured.

Overall, the changes enhance performance and streamline the logic for typography calculation. Well done!

app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx (5)

2-2: Great job updating the imports!

The changes to the imports are necessary to support the refactoring of the useTheme function. The addition of useMemo and the new hooks useIconSizing and useIconDensity will help improve the performance and maintainability of the code.

Also applies to: 4-10


56-128: Excellent refactoring of the useTheme function! 👏

The replacement of multiple useEffect hooks with a single useMemo hook is a great way to improve performance and reduce the number of side effects. By consolidating the theme update logic into the useMemo function, you've made the code more readable and maintainable.

The useMemo hook will ensure that the theme is only recalculated when the relevant dependencies change, which will help optimize the performance of the component.


79-82: Nice work streamlining the typography handling!

The integration of typography updates directly into the memoized theme calculation is a great way to simplify the theme management process. By removing the separate effect for updating typography, you've made the code more cohesive and easier to understand.

This change also ensures that typography updates are applied consistently whenever the theme is recalculated.

Also applies to: 108-108


104-116: Great addition of icon sizing and stroke width to the theme object!

Including the icon sizing and stroke width properties in the returned theme object is a helpful change that ensures these values are easily accessible for components that require them.

This change aligns well with the addition of the new hooks useIconSizing and useIconDensity, which provide a more granular control over icon-related properties in the theme.


Line range hint 18-24: Verify the impact of removing the fontFamily property.

The removal of the fontFamily property from the UseThemeProps interface suggests a change in how typography is managed. Please ensure that this change does not break any existing code that relies on the fontFamily property.

You can use the following script to search for any usage of the fontFamily property in the codebase:

app/client/src/pages/Editor/Canvas.tsx (1)

Line range hint 55-55: Verify that removing the fontFamily property is intentional.

Removing the fontFamily property from the themeSetting object may affect the visual presentation of text within the Canvas component, as it no longer has a specified font family. This could lead to a fallback to a browser default or inherited styles.

The AI-generated summary indicates that this change is part of simplifying typography management. Can you please confirm that this change is intentional and aligns with the broader typography management goals mentioned in the summary?

app/client/src/pages/Editor/WDSThemePropertyPane/index.tsx (1)

15-15: Looks good! The import statement for components from "@appsmith/ads" is correctly added.

@jsartisan
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Sep 4, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10697206787.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36110.
recreate: .

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6adeed0 and b2c6f1b.

Files selected for processing (2)
  • app/client/packages/design-system/theming/src/hooks/src/useIconDensity.tsx (1 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useIconSizing.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/theming/src/hooks/src/useIconSizing.tsx
Additional comments not posted (2)
app/client/packages/design-system/theming/src/hooks/src/useIconDensity.tsx (2)

Line range hint 1-20: Great job refactoring the hook to improve performance! 👏

The changes simplify the logic and avoid unnecessary re-renders by replacing useState and useEffect with useMemo. This is a significant improvement that enhances the efficiency of the hook.


Line range hint 1-20: Acknowledging the previous review comments.

The conversation in the previous review comments provides valuable context for understanding the motivation behind the refactoring. It's great to see that the feedback was taken into account and the code was updated accordingly.

Copy link

github-actions bot commented Sep 4, 2024

Deploy-Preview-URL: https://ce-36110.dp.appsmith.com

znamenskii-ilia
znamenskii-ilia previously approved these changes Sep 4, 2024
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b2c6f1b and d190661.

Files selected for processing (1)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx

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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d190661 and a632db0.

Files selected for processing (5)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx (4 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx (2 hunks)
  • app/client/packages/storybook/.storybook/addons/theming/ThemingPopup.tsx (1 hunks)
  • app/client/packages/storybook/.storybook/decorators/theming.tsx (1 hunks)
  • app/client/packages/storybook/src/components/ThemeSettings.tsx (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx
  • app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx

@jsartisan
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

github-actions bot commented Sep 6, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10734651305.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 36110.
recreate: .

Copy link

github-actions bot commented Sep 6, 2024

Deploy-Preview-URL: https://ce-36110.dp.appsmith.com

@jsartisan
Copy link
Contributor Author

@ichik can you try the DP once? For some reason, there are diffs in few components in storybook. Can you check if they are ok to go in ?

@ichik
Copy link
Contributor

ichik commented Sep 6, 2024

@jsartisan everything seems to be fine, minor changes in Chromatic are a mystery, I don't see them when inspecting Storybook snapshots, there appears to be a minor vertical positioning difference, though, perhaps some rounding did change somewhere. Behavior and looks in the editor seem all fine.

@jsartisan jsartisan added the ok-to-test Required label for CI label Sep 9, 2024
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: 1

Outside diff range, codebase verification and nitpick comments (1)
app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (1)

57-87: Ensure Complete Dependency Arrays in useMemo Hooks

The useMemo hooks for colorClassName and typographyClassName do not have explicit dependencies listed. This could lead to issues with stale or incorrect data if these hooks depend on other variables. Please verify if additional dependencies should be included for these hooks.

  • colorClassName: Consider adding [color] as a dependency.
  • typographyClassName: Consider adding [typography] as a dependency.
Analysis chain

Optimization through useMemo

The use of useMemo for colorClassName, typographyClassName, fontFamilyClassName, providerClassName, and colorModeClassName is a significant improvement. It ensures that these values are recalculated only when their dependencies change, which enhances performance by preventing unnecessary re-renders.

However, it's crucial to ensure that all dependencies are correctly listed in the dependency arrays of useMemo to avoid issues with stale or incorrect data.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all dependencies are correctly listed for useMemo hooks.

# Test: Check the dependency arrays for completeness and correctness.
rg --type javascript -A 3 $'useMemo(() => {'

Length of output: 139


Script:

#!/bin/bash
# Description: Verify that all dependencies are correctly listed for useMemo hooks.

# Test: Check the dependency arrays for completeness and correctness in the specified file.
rg --type js -A 5 'useMemo\(\(\) => {' app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx

Length of output: 213


Script:

#!/bin/bash
# Description: Verify that all dependencies are correctly listed for useMemo hooks.

# Test: Check the dependency arrays for completeness and correctness in the specified file.
rg --type js -A 5 'useMemo\(\[\w*,?\s*\w*\]\)\s*=>\s*\{' app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx

Length of output: 131


Script:

#!/bin/bash
# Description: Verify that all dependencies are correctly listed for useMemo hooks.

# Test: Check the dependency arrays for completeness and correctness in the specified file.
rg --type js -A 5 'useMemo\(\s*\(\)\s*=>\s*\{' app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx

Length of output: 666

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a632db0 and 48a7acc.

Files selected for processing (8)
  • app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (2 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx (4 hunks)
  • app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx (4 hunks)
  • app/client/packages/design-system/theming/src/theme/src/ThemeProvider.tsx (1 hunks)
  • app/client/packages/design-system/theming/src/theme/src/types.ts (1 hunks)
  • app/client/packages/design-system/theming/src/token/src/TokensAccessor.ts (7 hunks)
  • app/client/packages/design-system/theming/src/token/src/types.ts (4 hunks)
  • app/client/src/pages/AppViewer/index.tsx (2 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/packages/design-system/theming/src/token/src/TokensAccessor.ts
Files skipped from review as they are similar to previous changes (2)
  • app/client/packages/design-system/theming/src/hooks/src/useTheme.tsx
  • app/client/packages/design-system/theming/src/hooks/src/useTypography.tsx
Additional comments not posted (8)
app/client/packages/design-system/theming/src/theme/src/types.ts (1)

2-2: Repositioning of CSSProperties import is a good practice.

Moving the CSSProperties import to a more prominent position at the top enhances the organization of imports, making it easier to locate and manage dependencies. Well done on this subtle yet effective improvement!

app/client/packages/design-system/theming/src/theme/src/ThemeProvider.tsx (1)

23-23: Optimized handling of the theme object in useCssTokens.

Passing the theme object directly to the useCssTokens hook instead of using a spread operator is a wise choice. This approach reduces the overhead of creating a shallow copy of the object, which can enhance performance, especially in complex applications. However, please confirm that the useCssTokens function is equipped to handle direct object references without any side effects.

Verification successful

Let's try a different approach to locate the useCssTokens function. I'll search for its occurrences across the codebase to determine where it's defined or imported from. This will help us understand how it handles direct object references.


Direct object reference handling in useCssTokens is confirmed.

The useCssTokens function is designed to accept a Theme object directly, as evidenced by its implementation in useCssTokens.tsx. The function destructures the Theme object properties, ensuring it can handle direct references without issues. This confirms that the change in ThemeProvider.tsx is both safe and efficient.

  • Location of useCssTokens implementation: app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `useCssTokens` handles direct object references correctly.

# Test: Search for the implementation of `useCssTokens` to ensure it handles direct object references. Expect: Proper handling of direct references.
ast-grep --lang typescript --pattern $'function useCssTokens($_) {
  $$$
}'

Length of output: 76


Script:

#!/bin/bash
# Search for occurrences of `useCssTokens` in the codebase to find its definition or import statement.
rg 'useCssTokens' -A 5

Length of output: 2170

app/client/packages/design-system/theming/src/token/src/types.ts (2)

Line range hint 7-7: Removal of fontFamily from TokenSource.

Eliminating the fontFamily property from the TokenSource interface is a bold move towards simplifying the typography settings within the application. This change should make the theme configuration less complex and more maintainable. However, it's crucial to ensure that all components and features that previously relied on this property have been appropriately adjusted to work without it.


Line range hint 7-7: Removal of FONT_METRICS and FontFamily type.

The removal of the FONT_METRICS constant and the FontFamily type indicates a significant shift in how fonts are managed within the system. This could lead to a more centralized control over typography, potentially simplifying the theming system. Ensure that the removal of these elements does not impact the functionality of the application, particularly in areas where font metrics were previously utilized.

app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (2)

9-11: Simplified fontFamilyCss function

The fontFamilyCss function has been simplified to always return a default font family string. This change aligns with the PR's goal to streamline typography settings. However, ensure that this default setting meets all design requirements across the application.


Line range hint 18-26: Review of dynamic CSS generation in getTypographyCss

The function dynamically generates CSS based on typography settings using template literals and reduce. This method is efficient for creating customizable styles but ensure that the keys used in typography are sanitized and validated to prevent CSS injection risks.

app/client/src/pages/AppViewer/index.tsx (2)

49-50: Introduction of new types for theme properties

The introduction of ColorMode and IconStyle types is a positive change that enhances type safety and clarity. Ensure that these types are well-defined and cover all necessary cases in theme management.


114-117: Type casting in theme property assignments

The explicit casting of themeSetting.colorMode and themeSetting.iconStyle to ColorMode and IconStyle, respectively, is a good practice that prevents type mismatches and potential bugs. However, ensure that the values provided by themeSetting are compatible with these types and that there are fallbacks or validations in place in case of mismatches.

ThemeToken,
IconStyle,
} from "../../token";
import type { Typography, ThemeToken, IconStyle } from "../../token";

export type Theme = ThemeToken & {
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

Review and Update References to fontFamily

The removal of the fontFamily property from the Theme type has not been fully propagated throughout the codebase. There are numerous references to fontFamily in various files, including widget styles, tests, migrations, and other components. It's important to review and update these references to ensure consistency and prevent potential errors.

  • Files with fontFamily references:
    • app/client/src/globalStyles/WidgetGlobalStyles.ts
    • app/client/packages/dsl/src/migrate/tests/SelectWidget.test.ts
    • app/client/src/widgets/TextWidget/component/index.tsx
    • app/client/src/pages/AppViewer/index.tsx
    • app/client/src/entities/AppTheming/index.ts
    • ...and many more.

Please ensure that all these references are updated or removed as necessary to align with the changes in the Theme type. This will help maintain a streamlined and consistent theme configuration across the application.

Analysis chain

Removal of fontFamily from Theme type.

The decision to remove the fontFamily property from the Theme type is a significant change. It simplifies the theme configuration by reducing the number of customizable options, which aligns with the PR's goal to streamline typography settings. Ensure that all references to fontFamily in the application have been updated to reflect this change.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that no remaining references to `fontFamily` exist in the project.

# Test: Search for `fontFamily` in the project. Expect: No occurrences outside of historical or documentation contexts.
rg --type ts --type tsx "fontFamily"

Length of output: 64


Script:

#!/bin/bash
# Description: Verify that no remaining references to `fontFamily` exist in the project.

# Test: Search for `fontFamily` in TypeScript and TSX files. Expect: No occurrences outside of historical or documentation contexts.
rg "fontFamily" --glob "**/*.ts" --glob "**/*.tsx"

Length of output: 55381


export const useIconDensity = (density: IconDensity, userDensity = 1) => {
const [strokeWidth, setStrokeWidth] = useState<TokenObj>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: In all these hooks, mainly refactored useState + useEffect pattern to useMemo.

Reason: useState + useEffect create 1 extra render.

@@ -107,21 +108,16 @@ function AppViewer(props: Props) {
);
const isAnvilLayout = useSelector(getIsAnvilLayout);
const themeSetting = useSelector(getAppThemeSettings);
const themeProps = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why were we passing the themeProps for non-anvil apps 🤔
@KelvinOm do you remember?

I think just passing the empty object would be better for non-anvil apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope. Looks like mistake.

@jsartisan jsartisan removed the request for review from KelvinOm September 9, 2024 11:34
@jsartisan jsartisan marked this pull request as draft September 9, 2024 11:34
@jsartisan jsartisan marked this pull request as ready for review September 9, 2024 12:06
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

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 48a7acc and 80b57fd.

Files selected for processing (1)
  • app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (2 hunks)
Additional comments not posted (3)
app/client/packages/design-system/theming/src/hooks/src/useCssTokens.tsx (3)

9-11: Simplified fontFamilyCss function.

The refactoring of fontFamilyCss to directly return a string without parameters simplifies the code and aligns with the PR's objective to streamline typography settings. This change enhances maintainability by reducing complexity.


57-57: Optimized state management using useMemo.

The transition from useState and useEffect to useMemo for managing CSS class names is a significant improvement. This change reduces unnecessary re-renders and enhances performance by recalculating values only when necessary. The implementation is clean and adheres to best practices in React for optimizing performance.

Also applies to: 59-63, 67-71, 75-77, 79-82, 85-89


Line range hint 18-26: Review the dynamic CSS generation in getTypographyCss.

The use of objectKeys to iterate over typography properties and dynamically generate CSS rules is efficient and flexible. However, ensure that the Typography type is strictly typed to avoid runtime errors due to unexpected property access.

Verification successful

Typography Type is Strictly Typed
The Typography type is strictly typed, as it derives its keys from the well-defined TYPOGRAPHY_VARIANTS constant. This ensures that the dynamic CSS generation in getTypographyCss is safe from runtime errors due to unexpected property access. The keys are limited to footnote, caption, body, subtitle, and title, ensuring strict typing.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the strict typing of the Typography type.

# Test: Search for the Typography type definition. Expect: Properties should be strictly defined.
ast-grep --lang typescript --pattern $'type Typography = { $$$ }'

Length of output: 373


Script:

#!/bin/bash
# Description: Verify the definition of TYPOGRAPHY_VARIANTS to ensure strict typing.

# Test: Search for the definition of TYPOGRAPHY_VARIANTS. Expect: It should be a constant or a type with specific keys.
rg 'TYPOGRAPHY_VARIANTS' -A 5

Length of output: 10152


return { theme, setTheme };
return {
...tokensAccessor.getAllTokens(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is all this updated correctly? Have you checked?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep. Looks ok to me.

@@ -107,21 +108,16 @@ function AppViewer(props: Props) {
);
const isAnvilLayout = useSelector(getIsAnvilLayout);
const themeSetting = useSelector(getAppThemeSettings);
const themeProps = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nope. Looks like mistake.

userSizing: themeSetting.sizing,
userDensity: themeSetting.density,
iconStyle: themeSetting.iconStyle.toLowerCase(),
iconStyle: themeSetting.iconStyle.toLowerCase() as IconStyle,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why now we need type casting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just how typescript is.

Consider the following code:

const isFlagTrue = localStorage.getItem('flag')

const a = { one: "one" as string, two: "two" as "two" };
const b = { two: "two" } as const;

function process(value: { one?: "one" | "ONE", two?: "two" | "two" }) {

}

process(isFlagTrue ? a : b); // works fine

In the above, when checking types for args of processt, typescript gets strict only on the types that are common to a and b ( type of two ).

Now consider the following case in which else of part of condition is return is empty object {}:

process(isFlagTrue ? a : {}); // ERROR, value of one should "one" or "ONE" 

Now typescript is strict on the types of a. ( this is what is happening to us in our case, so had to typescript the wdsThemeProp properly )

Now the funny part:

If I extract the logic to a separate line, all works fine:

const arg = isFlagTrue ? a: {};
process(arg);

Not sure why this happens, will check if I can find something on this.

@jsartisan jsartisan merged commit 049a8a9 into release Sep 13, 2024
92 checks passed
@jsartisan jsartisan deleted the chore/remove-typography-from-theme-settings branch September 13, 2024 05:49
Shivam-z pushed a commit to Shivam-z/appsmith that referenced this pull request Sep 26, 2024
/ok-to-test tags="@tag.All"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced new hooks for icon management: `useIconDensity` and
`useIconSizing`.

- **Improvements**
- Refactored hooks to enhance performance by using `useMemo` instead of
state management, leading to more efficient calculations for icon size,
density, spacing, and typography.
- Streamlined theme management by consolidating logic and removing
unnecessary properties, improving clarity and maintainability.
- Optimized CSS class name management within the `useCssTokens` hook for
better performance.

- **Bug Fixes**
- Removed `fontFamily` property from various components, which may
affect text rendering but simplifies font management.

- **Documentation**
- Updated comments and documentation to reflect changes in typography
and theme handling.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10786030048>
> Commit: a0d1258
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10786030048&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Tue, 10 Sep 2024 06:00:30 UTC
<!-- end of auto-generated comment: Cypress test results  -->

---------

Co-authored-by: Pawan Kumar <pawankumar@Pawans-MacBook-Pro-2.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants