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

new-log-viewer: Add bundle size optimization tooling; Replace JoyUI path imports with default imports. #73

Merged
merged 10 commits into from
Oct 19, 2024

Conversation

junhaoliao
Copy link
Collaborator

@junhaoliao junhaoliao commented Sep 16, 2024

References

new-log-viewer series: #45 #46 #48 #51 #52 #53 #54 #55 #56 #59 #60 #61 #62 #63 #66 #67 #68 #69 #70 #71 #72

#59 added basic UI components implemented by @mui/joy but in the code the imports are inconsistent. Some code is using the default import provided by the library while others are importing directly from the component sources.

Description

  1. Add Webpack Bundle Analyzer script and update dependencies; Add bundle-stats.json to .gitignore.
  2. Add ESLint rules to restrict imports from @mui/icons-material and @mui/joy packages.
  3. Refactor imports from '@mui/joy' for consistency.

Validation performed

  1. Ran npm run analyze:size and observed the build was successful. After building is done, the analyzer server runs and a web ui pops up in the browser showing sizes of each components in the compiled bundle.
  2. Referred to Add support for loading files, decoding them as JSONL, and formatting them using a Logback-like format string. #46 , started the debug server and loaded a sample log file. Ensured the buttons in the MenuBar and StatusBar are functional; the Setting modal rendered without any warnings; the theming toggle in the settings modal functioned as expected.

Summary by CodeRabbit

  • New Features

    • Introduced a new script for analyzing bundle sizes, enhancing performance insights.
    • Added a dependency for webpack-bundle-analyzer to assist in bundle analysis.
  • Improvements

    • Streamlined import statements across multiple components for better code readability.
    • Enhanced ESLint configuration to enforce import restrictions for specific libraries.

These updates aim to improve the overall development experience and maintainability of the project.

Copy link

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request introduces several updates to the new-log-viewer project. Key changes include modifications to the .gitignore and package.json files, where a new script for bundle analysis is added along with a new dependency for the webpack-bundle-analyzer. Various components have undergone import statement consolidations and adjustments, particularly for the @mui/joy library. Additionally, the ESLint configuration has been enhanced with a new rule to restrict specific imports.

Changes

File Path Change Summary
new-log-viewer/.gitignore Updated to ignore /bundle-stats.json.
new-log-viewer/package.json Added script analyze:size for bundle analysis; added webpack-bundle-analyzer to devDependencies; enhanced ESLint rules.
new-log-viewer/src/components/Layout.tsx Simplified import statement for CssVarsProvider.
new-log-viewer/src/components/MenuBar/PageNumInput.tsx Consolidated import statements for Typography and Input from @mui/joy.
new-log-viewer/src/components/StatusBar/index.tsx Consolidated imports of Button, Sheet, and Typography from @mui/joy.
new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx Added imports for FormControl, FormHelperText, FormLabel, and Input, and updated the render method for layout.
new-log-viewer/src/components/modals/SettingsModal/index.tsx Changed import of Modal from default to named import.
new-log-viewer/src/components/theme.tsx Modified import for extendTheme from @mui/joy/styles to @mui/joy.
new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/TabButton.tsx Updated import for SvgIcon from @mui/material; changed Icon property type in TabButtonProps.
new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx Updated Icon property type in TABS_INFO_LIST.
new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.tsx Changed import for DefaultColorPalette to a type import.

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • Henry8192

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 956d026 and 78b4d80.

⛔ Files ignored due to path filters (1)
  • new-log-viewer/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • new-log-viewer/src/components/StatusBar/index.tsx (1 hunks)
  • new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • new-log-viewer/src/components/StatusBar/index.tsx
  • new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx

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

🧹 Outside diff range and nitpick comments (1)
new-log-viewer/package.json (1)

86-104: Excellent addition of ESLint rules for import standardization

The new "no-restricted-imports" rule effectively addresses the PR's objective of standardizing import statements for JoyUI components. It provides clear guidance for developers on how to import from "@mui/icons-material" and "@mui/joy", which will help maintain consistency in the codebase.

A minor suggestion to enhance this further:

Consider adding an example of the correct import syntax in the error messages. This could help developers quickly understand and implement the desired import style. For instance:

 "message": "Please use path imports and name your imports with postfix \"Icon\" to avoid confusions.",
+"message": "Please use path imports and name your imports with postfix \"Icon\" to avoid confusions. Example: import { AddIcon } from '@mui/icons-material/Add'",
 "message": "Please use the default import from \"@mui/joy\" instead."
+"message": "Please use the default import from \"@mui/joy\" instead. Example: import { Button } from '@mui/joy'"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ae24669 and 28d6fae.

⛔ Files ignored due to path filters (1)
  • new-log-viewer/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • new-log-viewer/.gitignore (1 hunks)
  • new-log-viewer/package.json (3 hunks)
  • new-log-viewer/src/components/Layout.tsx (1 hunks)
  • new-log-viewer/src/components/MenuBar/PageNumInput.tsx (1 hunks)
  • new-log-viewer/src/components/StatusBar/index.tsx (1 hunks)
  • new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx (1 hunks)
  • new-log-viewer/src/components/modals/SettingsModal/index.tsx (1 hunks)
  • new-log-viewer/src/components/theme.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • new-log-viewer/.gitignore
  • new-log-viewer/src/components/Layout.tsx
  • new-log-viewer/src/components/theme.tsx
🧰 Additional context used
📓 Learnings (1)
new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx (2)
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#84
File: new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx:99-114
Timestamp: 2024-10-08T15:52:50.753Z
Learning: When suggesting to add validation for form inputs in `SettingsDialog.tsx`, the user considered it not related to the PR. In future reviews, ensure suggestions align with the PR's scope.
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#84
File: new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx:99-114
Timestamp: 2024-09-30T20:49:32.508Z
Learning: When suggesting to add validation for form inputs in `SettingsDialog.tsx`, the user considered it not related to the PR. In future reviews, ensure suggestions align with the PR's scope.
🔇 Additional comments (11)
new-log-viewer/src/components/modals/SettingsModal/index.tsx (2)

1-1: LGTM! Import statement change aligns with PR objectives.

The modification of the import statement from a default import to a named import, and changing the source from "@mui/joy/Modal" to "@mui/joy", aligns well with the PR objectives of standardizing JoyUI imports and potentially optimizing bundle size. This change maintains the functionality while promoting consistency across the project.


Line range hint 1-33: Functionality preserved, no further changes needed.

The import statement change doesn't affect the rest of the file. The Modal component is used correctly with the new import style, and the overall functionality of the SettingsModal component remains intact. No additional modifications are necessary in this file.

new-log-viewer/src/components/StatusBar/index.tsx (3)

3-7: Excellent import consolidation!

The consolidation of imports from '@mui/joy' into a single, destructured import statement is a great improvement. This change enhances code readability and aligns with modern JavaScript best practices. It also makes the import section more maintainable, especially if more components from '@mui/joy' need to be added in the future.


Line range hint 1-58: Changes align well with PR objectives

The modifications to this file, specifically the consolidation of '@mui/joy' imports, directly support the PR's goal of standardizing import statements for JoyUI components. This change contributes to improved code consistency across the project without altering the functionality of the StatusBar component. Great job on implementing these changes effectively!


Line range hint 30-58: StatusBar component remains functionally unchanged

I've verified that the StatusBar component continues to use the Button, Sheet, and Typography components from '@mui/joy' correctly after the import changes. The component's structure and functionality remain intact, demonstrating that the import consolidation was implemented without introducing any regressions.

To further ensure that no unintended changes were made to the StatusBar component, you can run the following command:

This command will show all non-import lines in the file, allowing you to verify that no other changes were inadvertently made.

✅ Verification successful

StatusBar component import statements successfully verified

After reviewing the changes, only the import statements in new-log-viewer/src/components/StatusBar/index.tsx were modified. No other parts of the StatusBar component were altered, ensuring that the import consolidation was implemented correctly without affecting the component's functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that only import statements were changed in this file

# Test: Check for changes other than import statements
rg --type typescript -n '^[^import].*' new-log-viewer/src/components/StatusBar/index.tsx

Length of output: 125


Script:

#!/bin/bash
# Description: Verify that only import statements were changed in this file

# Test: Check for changes other than import statements using the correct file type
rg --type ts -n '^[^import].*' new-log-viewer/src/components/StatusBar/index.tsx

Length of output: 1358


Script:

#!/bin/bash
# Description: Verify that only import statements were changed in StatusBar component

# Get the list of modified lines in the file
git diff origin/main -- new-log-viewer/src/components/StatusBar/index.tsx | grep '^+' | grep -v '^+++' | grep -v '^+import' 

# If the above command returns any lines, it means non-import lines were changed

Length of output: 187

new-log-viewer/src/components/MenuBar/PageNumInput.tsx (2)

8-11: Excellent import consolidation!

The consolidation of Input and Typography imports from @mui/joy into a single import statement improves code organization and readability. This change aligns well with the PR objective of standardizing JoyUI imports across the project.


8-11: Verify component functionality

The import changes don't appear to affect the functionality of the PageNumInput component. However, it's always good to double-check.

Please run the following script to ensure that the Input and Typography components are still being used correctly throughout the file:

✅ Verification successful

Re-verify component usage

The initial search encountered an issue with the file type. Please run the updated script below to confirm the usage of the Input and Typography components:


Component usage confirmed

The Input and Typography components are correctly used in PageNumInput.tsx, and the import statements are consistent with their usage.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of Input and Typography components

# Test: Search for Input and Typography usage
echo "Checking Input usage:"
rg --type typescript 'Input' new-log-viewer/src/components/MenuBar/PageNumInput.tsx
echo "Checking Typography usage:"
rg --type typescript 'Typography' new-log-viewer/src/components/MenuBar/PageNumInput.tsx

Length of output: 358


Script:

#!/bin/bash
# Description: Verify the usage of Input and Typography components

# Test: Search for Input and Typography usage in the specific file
echo "Checking Input usage:"
rg 'Input' new-log-viewer/src/components/MenuBar/PageNumInput.tsx
echo "Checking Typography usage:"
rg 'Typography' new-log-viewer/src/components/MenuBar/PageNumInput.tsx

Length of output: 762

new-log-viewer/package.json (2)

7-7: Excellent addition of bundle size analysis script!

The new "analyze:size" script is a valuable addition for optimizing the application's bundle size. It generates a JSON file with bundle statistics and then uses webpack-bundle-analyzer to visualize the results, which aligns perfectly with the PR's objective of improving bundle size optimization.


66-66: Appropriate addition of webpack-bundle-analyzer dependency

The inclusion of "webpack-bundle-analyzer" as a devDependency is necessary to support the newly added "analyze:size" script. The version "^4.10.2" allows for minor and patch updates, which is a good practice for development dependencies.

new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx (2)

8-11: Import consolidation looks good!

The addition of FormControl, FormHelperText, FormLabel, and Input imports from @mui/joy aligns well with the PR objective of standardizing JoyUI imports. This change improves code organization and consistency.


Line range hint 99-114: Form structure improvements look great!

The use of FormControl, FormLabel, Input, and FormHelperText components from JoyUI to wrap each configuration field enhances the form's structure and accessibility. This change aligns well with the PR's objective of standardizing JoyUI component usage while maintaining the existing functionality.

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

🧹 Outside diff range and nitpick comments (2)
new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (2)

28-28: LGTM: Type updated correctly with a minor suggestion.

The type change from SvgIconComponent to typeof SvgIcon is appropriate and aligns with TypeScript best practices. It ensures type consistency with the imported SvgIcon component.

Consider adding a type annotation to TABS_INFO_LIST for improved readability:

const TABS_INFO_LIST: ReadonlyArray<{
    tabName: TAB_NAME,
    Icon: typeof SvgIcon,
}> = Object.freeze([
    // ... existing content
]);

This makes the type more explicit and easier to understand at a glance.


Line range hint 1-114: Overall assessment: Changes improve type safety and import consistency.

The modifications in this file align well with the PR objectives. The import of SvgIcon and the subsequent type update in TABS_INFO_LIST enhance type safety and contribute to the standardization of imports from MUI components. These changes maintain the existing functionality while improving the code quality.

As the project continues to grow, consider implementing a centralized import strategy for MUI components to further streamline imports and maintain consistency across the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 28d6fae and 956d026.

📒 Files selected for processing (4)
  • new-log-viewer/package.json (3 hunks)
  • new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/TabButton.tsx (2 hunks)
  • new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (2 hunks)
  • new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • new-log-viewer/package.json
🧰 Additional context used
📓 Learnings (1)
new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.tsx (2)
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#77
File: new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.css:6-6
Timestamp: 2024-09-26T08:05:11.421Z
Learning: When overriding JoyUI's default styling, it's acceptable to use `!important` in CSS in this project.
Learnt from: junhaoliao
PR: y-scope/yscope-log-viewer#77
File: new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.css:6-6
Timestamp: 2024-10-08T15:52:50.753Z
Learning: When overriding JoyUI's default styling, it's acceptable to use `!important` in CSS in this project.
🔇 Additional comments (5)
new-log-viewer/src/components/StatusBar/LogLevelSelect/LogLevelChip.tsx (1)

5-5: Approval: Good optimization of the import statement.

The change from a regular import to a type import for DefaultColorPalette is appropriate, as it's only used as a type in this file. This modification aligns with the PR objective of standardizing imports and may contribute to bundle size optimization.

To ensure the new import path is correct and consistent across the project, please run the following verification script:

✅ Verification successful

To address the issue with the previous script, please run the updated verification script below:

[/run_scripts]


To successfully verify the import path for DefaultColorPalette, please execute the updated verification script below:

[/run_scripts]


Verification Successful: Import Path Correct and Consistent

All instances of DefaultColorPalette have been successfully verified to use the new import path "@mui/joy/styles/types". No issues were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the import path for DefaultColorPalette

# Test: Search for DefaultColorPalette imports
rg --type typescript 'import.*DefaultColorPalette.*from.*@mui/joy'

# Expected result: All imports should use the new path "@mui/joy/styles/types"

Length of output: 103


Script:

#!/bin/bash
# Description: Verify the import path for DefaultColorPalette

# Test: Search for DefaultColorPalette imports in TypeScript files
rg --type ts 'import\s+.*DefaultColorPalette\s+from\s+"@mui/joy/styles/types"'

# Test: Search for DefaultColorPalette imports in TSX files
rg --type tsx 'import\s+.*DefaultColorPalette\s+from\s+"@mui/joy/styles/types"'

Length of output: 190


Script:

#!/bin/bash
# Description: Verify the import path for DefaultColorPalette in TypeScript and TSX files

# Search for DefaultColorPalette imports in .ts and .tsx files using glob patterns
rg 'import\s+.*DefaultColorPalette\s+from\s+"@mui/joy/styles/types"' --glob "*.ts" --glob "*.tsx"

Length of output: 99

new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/TabButton.tsx (3)

Line range hint 1-58: Overall assessment: Changes improve code quality and consistency.

The modifications to import statements and prop types in this file align well with the PR objectives. They contribute to better code consistency and potentially improved bundle size optimization. The changes appear to be well-thought-out and implemented correctly.


17-17: Approval: Prop type updated correctly.

The change from 'SvgIconComponent' to 'typeof SvgIcon' for the 'Icon' prop type is consistent with the import change and ensures better type safety.

Let's verify if this change affects the usage of the TabButton component in parent components:

#!/bin/bash
# Description: Check for usage of TabButton component in parent components

# Test: Search for imports and usage of TabButton
rg --type typescript --type javascript -e 'import.*TabButton' -e '<TabButton' -g '!*.test.*' -g '!*.spec.*'

5-5: Approval: Import statement updated correctly.

The change from importing from "@mui/icons-material" to "@mui/material/SvgIcon" aligns with the PR objective of standardizing imports and may lead to better tree-shaking.

Let's verify if this change is consistent across the codebase:

✅ Verification successful

Import statement change verified successfully.

All imports of SvgIcon from @mui/icons-material have been updated to @mui/material/SvgIcon across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining imports of SvgIcon from @mui/icons-material

# Test: Search for imports of SvgIcon from @mui/icons-material
rg --type typescript --type javascript 'from\s+["\']@mui/icons-material["\']' -g '!*.test.*' -g '!*.spec.*'

Length of output: 238


Script:

#!/bin/bash
# Description: Check for any remaining imports of SvgIcon from @mui/icons-material

# Test: Search for imports of SvgIcon from @mui/icons-material
rg --type ts --type js 'from\s+["'"'"']@mui/icons-material["'"'"']' -g '!*.test.*' -g '!*.spec.*'

Length of output: 97

new-log-viewer/src/components/CentralContainer/Sidebar/SidebarTabs/index.tsx (1)

10-10: LGTM: Import statement added correctly.

The import of SvgIcon from @mui/material/SvgIcon is correctly added and aligns with the project's convention of using default imports from MUI. This change supports the type update in TABS_INFO_LIST and contributes to the standardization of imports as per the PR objectives.

@junhaoliao
Copy link
Collaborator Author

junhaoliao commented Oct 18, 2024

Henry's changes lgtm

@davemarco could you take another look since both @Henry8192 and I worked on this PR?

# Conflicts:
#	new-log-viewer/src/components/modals/SettingsModal/SettingsDialog.tsx
davemarco
davemarco previously approved these changes Oct 19, 2024
Copy link
Contributor

@davemarco davemarco left a comment

Choose a reason for hiding this comment

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

I looked through the PR, seems to make sense to me. Checked that nothing broke.

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.

3 participants