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

Include icons used in enabled apps while treeshaking the icons #9068

Merged
merged 1 commit into from
Nov 8, 2024

Conversation

khavinshankar
Copy link
Member

@khavinshankar khavinshankar commented Nov 8, 2024

Proposed Changes

  • Fixes #issue_number
  • Change 1
  • Change 2
  • More?

@ohcnetwork/care-fe-code-reviewers

Merge Checklist

  • Add specs that demonstrate bug / test a new feature.
  • Update product documentation.
  • Ensure that UI text is kept in I18n files.
  • Prep screenshot or demo video for changelog entry, and attach it to issue.
  • Request for Peer Reviews
  • Completion of QA

Summary by CodeRabbit

  • New Features

    • Enhanced icon extraction by broadening the search to include both apps and src directories.
    • Introduced a new interface for configuration options.
  • Bug Fixes

    • Maintained robust error handling for missing icons, ensuring stability in the icon extraction process.

@khavinshankar khavinshankar requested a review from a team as a code owner November 8, 2024 17:53
Copy link
Contributor

coderabbitai bot commented Nov 8, 2024

Walkthrough

The changes in this pull request focus on the treeShakeCareIcons.ts file, involving updates to import statements and the logic for file path resolution. The glob pattern for file discovery has been modified to include both apps and src directories, enhancing the range of files considered for icon extraction. Additionally, an interface TreeShakeCareIconsOptions has been introduced, and the function signature for treeShakeCareIcons has been updated to reflect this change, while error handling remains unchanged.

Changes

File Change Summary
plugins/treeShakeCareIcons.ts - Rearranged import order.
- Modified glob pattern to search in both apps and src directories.
- Added interface TreeShakeCareIconsOptions.
- Updated function signature for treeShakeCareIcons.

Suggested labels

needs review

Suggested reviewers

  • rithviknishad

Poem

In the forest where icons play,
A plugin danced and found its way.
With paths anew, it shakes the trees,
Gathering icons with the breeze.
Oh, what joy, a rabbit's cheer,
For every change brings icons near! 🐇✨


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

netlify bot commented Nov 8, 2024

Deploy Preview for care-ohc ready!

Name Link
🔨 Latest commit 0e32531
🔍 Latest deploy log https://app.netlify.com/sites/care-ohc/deploys/672e50093d17d7000859806e
😎 Deploy Preview https://deploy-preview-9068--care-ohc.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

Deploying care-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 0e32531
Status: ✅  Deploy successful!
Preview URL: https://4380917f.care-fe.pages.dev
Branch Preview URL: https://app-icons-treeshaking.care-fe.pages.dev

View logs

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 (2)
plugins/treeShakeCareIcons.ts (2)

Line range hint 24-29: Consider making the root directory path configurable.

The comment "update this if moving this code to a different file" suggests a brittle implementation. Consider making the root directory path configurable through the options interface to improve maintainability.

 export interface TreeShakeCareIconsOptions {
   iconWhitelist: string[];
+  rootDir?: string;
 }

 export function treeShakeCareIcons(
   options: TreeShakeCareIconsOptions = { iconWhitelist: [] },
 ): Plugin {
-  const rootDir = path.resolve(__dirname, ".."); // update this if moving this code to a different file
+  const rootDir = options.rootDir || path.resolve(__dirname, "..");

Line range hint 69-71: Enhance error message with more context.

While the error handling is good, the error message could be more informative to help developers quickly identify the source of the issue.

-        throw new Error(`Icon ${iconName} is not found in UniconPaths.json`);
+        throw new Error(
+          `Icon "${iconName}" is not found in UniconPaths.json. ` +
+          `Please ensure the icon exists or add it to the iconWhitelist if needed.`
+        );
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 66ef112 and 0e32531.

📒 Files selected for processing (1)
  • plugins/treeShakeCareIcons.ts (2 hunks)
🔇 Additional comments (2)
plugins/treeShakeCareIcons.ts (2)

3-4: LGTM! Well-structured interface and clean imports.

The TreeShakeCareIconsOptions interface is properly documented and typed, providing a clear contract for the plugin options.

Also applies to: 13-15


51-51: Verify completeness of file extension patterns.

The glob pattern now correctly includes both apps and src directories. However, let's verify if there are any other file extensions that might contain icon references.

✅ Verification successful

Based on the results, I can now generate the final response since I have sufficient information about icon usage patterns in the codebase.

The current file extension pattern is sufficient for icon references

The glob pattern {apps,src}/**/*.{tsx,res} is appropriate as the search results show that icon references primarily exist in TypeScript/React components (.tsx) and ReScript (.res) files. While there are icon definitions in .ts files (like iconMap.ts), these are just mapping files that don't represent actual icon usage in the UI.

The only other icon-related files found are:

  • UniconPaths.json: Contains icon definitions/paths
  • Configuration/build files that don't need scanning for tree-shaking
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential icon usage in files with different extensions

# Test 1: Find all unique file extensions in the codebase
echo "Unique file extensions in the codebase:"
fd -t f -x basename {} \; | grep -o '\.[^.]*$' | sort -u

# Test 2: Search for line icon patterns in files with extensions other than .tsx and .res
echo -e "\nChecking for icon usage in other file types:"
rg -g '!*.{tsx,res}' '"l-[a-z]+(?:-[a-z]+)*"'

Length of output: 66895

Copy link

cypress bot commented Nov 8, 2024

CARE    Run #3846

Run Properties:  status check passed Passed #3846  •  git commit 0e32531351: Include icons used in enabled apps while treeshaking the icons
Project CARE
Branch Review app-icons-treeshaking
Run status status check passed Passed #3846
Run duration 04m 28s
Commit git commit 0e32531351: Include icons used in enabled apps while treeshaking the icons
Committer Khavin Shankar
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 125
View all changes introduced in this branch ↗︎

@nihal467 nihal467 added urgent P1 breaking issue or vital feature tested labels Nov 8, 2024
@khavinshankar khavinshankar merged commit 6bd2aa8 into develop Nov 8, 2024
61 checks passed
@khavinshankar khavinshankar deleted the app-icons-treeshaking branch November 8, 2024 18:32
Copy link

github-actions bot commented Nov 8, 2024

@khavinshankar Your efforts have helped advance digital healthcare and TeleICU systems. 🚀 Thank you for taking the time out to make CARE better. We hope you continue to innovate and contribute; your impact is immense! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 breaking issue or vital feature tested urgent
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants