Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: cleanup and using mobx-react-lite #356

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

rarajes2
Copy link
Contributor

@rarajes2 rarajes2 commented Jan 10, 2025

JIRA - SPARK-601658

  • Fixes the build and other commands in the cc-task package
  • Fixes the dependencies in multiple packages to ensure proper dependencies
  • Uses mobx-react-lite instead of mobx-react as we are only using functional components
  • Fixes broken UT with jest config

Summary by CodeRabbit

  • Dependency Updates

    • Replaced mobx-react with mobx-react-lite in multiple packages
    • Updated React-related peer dependencies
  • Build Process Improvements

    • Added clean:dist step before webpack builds across multiple packages
    • Enhanced build scripts to ensure clean build environments
  • Testing Configuration

    • Updated Jest configurations to handle CSS, LESS, and SCSS files
  • Webpack Configuration

    • Added external dependencies configuration to reduce bundle size

Copy link

coderabbitai bot commented Jan 10, 2025

Walkthrough

This pull request introduces a series of consistent changes across multiple packages in the contact center project. The modifications primarily focus on updating build scripts to include a clean step before webpack, replacing the mobx-react library with mobx-react-lite, and enhancing Jest configurations to handle stylesheet imports. These changes aim to streamline the build process, optimize dependency management, and improve testing configuration across various packages.

Changes

File Path Change Summary
package.json Removed extra space in build script
packages/contact-center/*/package.json - Updated build:src script to run clean:dist before webpack
- Replaced mobx-react with mobx-react-lite
- Added moduleNameMapper for stylesheet handling in Jest
packages/contact-center/*/src/**/*.tsx Updated observer import from mobx-react to mobx-react-lite
packages/contact-center/task/webpack.config.js Added externals configuration for react, react-dom, and @webex/cc-store

Possibly related PRs

Poem

🐰 Hop, hop, build with care,
Clean the dist before webpack's flair!
MobX-lite, a nimble friend,
Streamlining code from start to end.
Rabbit's build, now swift and bright! 🚀

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@rarajes2 rarajes2 changed the title chore(*): cleanup and using mobx-react-lite fix(*): cleanup and using mobx-react-lite Jan 10, 2025
@Shreyas281299
Copy link

@CodeRabbit review

Copy link

coderabbitai bot commented Jan 10, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@Shreyas281299 Shreyas281299 left a comment

Choose a reason for hiding this comment

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

Looks good. Just a question - What was causing the test failures??

@@ -18,7 +18,7 @@
"clean": "rm -rf dist && rm -rf node_modules",
"clean:dist": "rm -rf dist",
"build": "yarn run -T tsc",

Choose a reason for hiding this comment

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

Are we still using this build command?

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 using but keeping it if we need to test something. If we don't use it for quite some time, we can remove this.

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

🧹 Nitpick comments (3)
packages/contact-center/task/webpack.config.js (1)

12-16: LGTM! Consider adding MobX to externals.

The externals configuration is a good optimization to reduce bundle size and avoid dependency duplication. Since this PR involves MobX-related changes, consider adding MobX as an external as well.

  externals: {
    react: 'react',
    'react-dom': 'react-dom',
    '@webex/cc-store': '@webex/cc-store',
+   'mobx-react-lite': 'mobx-react-lite',
+   'mobx': 'mobx'
  }
packages/contact-center/task/src/IncomingTask/index.tsx (1)

2-2: LGTM! Consider using mobx-react-lite's built-in types.

The migration is correct. For better type safety, consider using the Observer type from mobx-react-lite.

-const IncomingTask: React.FunctionComponent<IncomingTaskProps> = observer(({onAccepted, onDeclined}) => {
+import type {Observer} from 'mobx-react-lite';
+
+const IncomingTask: Observer<IncomingTaskProps> = ({onAccepted, onDeclined}) => {
packages/contact-center/station-login/src/station-login/index.tsx (1)

3-3: LGTM! Consider using mobx-react-lite's built-in types.

The migration is correct. For better type safety, consider using the Observer type from mobx-react-lite.

-const StationLogin: React.FunctionComponent<StationLoginProps> = observer(({onLogin, onLogout}) => {
+import type {Observer} from 'mobx-react-lite';
+
+const StationLogin: Observer<StationLoginProps> = ({onLogin, onLogout}) => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 473cd4f and ec26af6.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (11)
  • package.json (1 hunks)
  • packages/contact-center/cc-widgets/package.json (2 hunks)
  • packages/contact-center/station-login/package.json (2 hunks)
  • packages/contact-center/station-login/src/station-login/index.tsx (1 hunks)
  • packages/contact-center/store/package.json (1 hunks)
  • packages/contact-center/task/package.json (2 hunks)
  • packages/contact-center/task/src/IncomingTask/index.tsx (1 hunks)
  • packages/contact-center/task/src/TaskList/index.tsx (1 hunks)
  • packages/contact-center/task/webpack.config.js (1 hunks)
  • packages/contact-center/user-state/package.json (1 hunks)
  • packages/contact-center/user-state/src/user-state/index.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • package.json
🧰 Additional context used
📓 Learnings (1)
packages/contact-center/task/webpack.config.js (1)
Learnt from: Shreyas281299
PR: webex/widgets#345
File: packages/contact-center/cc-widgets/webpack.config.js:6-12
Timestamp: 2024-12-04T07:40:14.028Z
Learning: In the webex-widgets project, optimizations such as reducing bundle size and improving webpack configurations in files like `packages/contact-center/cc-widgets/webpack.config.js` are handled in separate tickets.
🔇 Additional comments (15)
packages/contact-center/task/src/TaskList/index.tsx (1)

3-3: LGTM! Verify mobx-react-lite compatibility.

The migration to mobx-react-lite is appropriate as this is a functional component. The implementation remains compatible since mobx-react-lite is specifically optimized for function components.

Let's verify no class components are using mobx-react-lite:

✅ Verification successful

✓ Verified: mobx-react-lite usage is correct

The migration to mobx-react-lite is appropriate as TaskList is implemented as a functional component using hooks. No class components were found in the contact-center package that could cause compatibility issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential class components using mobx-react-lite
ast-grep --pattern 'class $_ extends React.Component {
  $$$
}'

# Search for mobx-react-lite imports
rg "from 'mobx-react-lite'" -l

Length of output: 65


Script:

#!/bin/bash
# Search for class components with different patterns
ast-grep --pattern 'class $_ extends Component {
  $$$
}'

ast-grep --pattern 'class $_ extends PureComponent {
  $$$
}'

# Search for mobx-react and mobx-react-lite imports
rg "from ['\"]mobx-react['\"]" -l
rg "from ['\"]mobx-react-lite['\"]" -l

# Search for observer usage patterns
rg "observer\((.*?)\)" --multiline

Length of output: 4072


Script:

#!/bin/bash
# Search for mobx imports in contact-center package
rg "from ['\"]mobx-react(?:-lite)?['\"]" packages/contact-center -l

# Check TaskList component structure
cat packages/contact-center/task/src/TaskList/index.tsx

# Search for other potential class components in contact-center
ast-grep --pattern 'class $_ extends $_ {
  $$$
}' packages/contact-center

Length of output: 888

packages/contact-center/user-state/src/user-state/index.tsx (1)

3-3: LGTM! Clean migration to mobx-react-lite.

The migration is correct as this component is functional and properly typed with TypeScript interfaces.

packages/contact-center/store/package.json (1)

18-18: LGTM! Clean build step added.

Adding the clean step before webpack ensures no stale artifacts remain from previous builds.

packages/contact-center/user-state/package.json (2)

17-17: LGTM! Clean build step added.

Adding the clean step before webpack ensures no stale artifacts remain from previous builds.


23-23: LGTM! Appropriate dependency update.

Replacing mobx-react with mobx-react-lite is a good optimization since the project exclusively uses functional components.

packages/contact-center/station-login/package.json (3)

17-17: LGTM! Clean build step added.

Adding the clean step before webpack ensures no stale artifacts remain from previous builds.


23-23: LGTM! Appropriate dependency update.

Replacing mobx-react with mobx-react-lite is a good optimization since the project exclusively uses functional components.


57-59: LGTM! Jest configuration enhanced.

Added moduleNameMapper to handle CSS/LESS/SCSS imports in tests, which helps fix broken unit tests.

packages/contact-center/task/package.json (5)

14-15: LGTM! Added clean scripts.

New clean scripts provide flexibility for cleaning dist directory or complete cleanup including node_modules.


17-17: LGTM! Clean build step added.

Adding the clean step before webpack ensures no stale artifacts remain from previous builds.


23-23: LGTM! Appropriate dependency update.

Replacing mobx-react with mobx-react-lite is a good optimization since the project exclusively uses functional components.


47-50: LGTM! Proper dependency organization.

Moving React and React DOM to peerDependencies is the correct approach for a library package.


57-59: LGTM! Jest configuration enhanced.

Added moduleNameMapper to handle CSS/LESS/SCSS imports in tests, which helps fix broken unit tests.

packages/contact-center/cc-widgets/package.json (2)

21-21: LGTM! Clean build step added.

Adding the clean step before webpack ensures no stale artifacts remain from previous builds.


69-71: LGTM! Jest configuration enhanced.

Added moduleNameMapper to handle CSS/LESS/SCSS imports in tests, which helps fix broken unit tests.

Comment on lines +12 to +16
externals: {
react: 'react',
'react-dom': 'react-dom',
'@webex/cc-store': '@webex/cc-store',
}
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Add missing peer dependencies for webpack externals

The following externals need to be added as peer dependencies in package.json:

  • react
  • react-dom
  • @webex/cc-store
🔗 Analysis chain

Verify peer dependencies match externals configuration.

Ensure that the package.json peer dependencies align with the webpack externals configuration.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if package.json peer dependencies match webpack externals

# Get peer dependencies from package.json
echo "Checking peer dependencies in package.json:"
cat package.json | jq '.peerDependencies'

# Verify that all externals are listed as peer dependencies
echo -e "\nChecking for potential mismatches between externals and peer dependencies:"
for dep in "react" "react-dom" "@webex/cc-store"; do
  if ! cat package.json | jq -e ".peerDependencies.\"$dep\""; then
    echo "Warning: External '$dep' is not listed in peer dependencies"
  fi
done

Length of output: 1094

Copy link
Contributor

@mkesavan13 mkesavan13 left a comment

Choose a reason for hiding this comment

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

Please remove (*) from the PR title. Not sure if semantic release would like it. Just having fix: commit message would mean it is for the whole repo.

@rarajes2 rarajes2 changed the title fix(*): cleanup and using mobx-react-lite fix: cleanup and using mobx-react-lite Jan 10, 2025
@rarajes2
Copy link
Contributor Author

Looks good. Just a question - What was causing the test failures??

We needed to update the jest config

...
 "moduleNameMapper": {
     "^.+\\.(css|less|scss)$": "babel-jest"
  }

@rarajes2 rarajes2 merged commit 0b304c4 into webex:ccwidgets Jan 10, 2025
2 checks passed
@sreenara
Copy link
Contributor

🎉 This PR is included in version 1.28.0-ccwidgets.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

mkesavan13 pushed a commit to mkesavan13/widgets that referenced this pull request Jan 10, 2025
# [1.28.0-ccwidgets.8](webex/widgets@v1.28.0-ccwidgets.7...v1.28.0-ccwidgets.8) (2025-01-10)

### Bug Fixes

* **bundling:** fixed the multiple React instance and useRef errors  ([webex#355](webex#355)) ([473cd4f](webex@473cd4f))
* cleanup and using mobx-react-lite ([webex#356](webex#356)) ([0b304c4](webex@0b304c4))
@sreenara
Copy link
Contributor

sreenara commented Feb 5, 2025

🎉 This PR is included in version 1.28.0-ccconnectors.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

mkesavan13 pushed a commit to mkesavan13/widgets that referenced this pull request Feb 7, 2025
# [1.28.0-ccconnectors.1](webex/widgets@v1.27.5...v1.28.0-ccconnectors.1) (2025-02-05)

### Bug Fixes

* add material to all components ([webex#376](webex#376)) ([de0ca28](webex@de0ca28))
* **bundling:** fixed the multiple React instance and useRef errors  ([webex#355](webex#355)) ([473cd4f](webex@473cd4f))
* **call-control:** add-call-control-widget ([webex#362](webex#362)) ([a677f5e](webex@a677f5e))
* **cc-station-login:** material design ui ([webex#377](webex#377)) ([aec7034](webex@aec7034))
* **cc-store:** receive webex on init, add store types ([webex#341](webex#341)) ([9648969](webex@9648969))
* **cc-widgets:** ship-all-widgets-together ([webex#345](webex#345)) ([83d5a37](webex@83d5a37))
* cleanup and using mobx-react-lite ([webex#356](webex#356)) ([0b304c4](webex@0b304c4))
* convert npm to yarn ([webex#234](webex#234)) ([432ed3c](webex@432ed3c))
* **release:** add-publish-step-in-tooling ([webex#334](webex#334)) ([ca32235](webex@ca32235))
* rename agent state to user state ([webex#361](webex#361)) ([fe409db](webex@fe409db))
* **samples:** change samples index html hrefs ([webex#367](webex#367)) ([ff126ab](webex@ff126ab))
* **user-state:** receive agent stateChange event ([webex#350](webex#350)) ([21d6ce7](webex@21d6ce7))

### Features

* **cc-components:** setup and move user state sample ui comp ([webex#359](webex#359)) ([16a44d0](webex@16a44d0))
* **cc-store:** add logger from sdk ([webex#354](webex#354)) ([a62494b](webex@a62494b))
* **cc-widgets:** added Agent-Multi-Login-Alert Feature ([webex#364](webex#364)) ([f7d75ca](webex@f7d75ca))
* **release:** add new branch to circleci ([18f7bec](webex@18f7bec))
* **release:** publish pipeline for wxcc widgets ([webex#324](webex#324)) ([864fb52](webex@864fb52))
* taskList and IncomingTask widgets added ([webex#348](webex#348)) ([ce3a619](webex@ce3a619))
* **user-state:** load and change state, client timer ([webex#347](webex#347)) ([f1ccaeb](webex@f1ccaeb))
* **widget-cc-station-login:** Spark 575845 login widget ([webex#239](webex#239)) ([66b8a20](webex@66b8a20))
* **widgets:** added-relogin-logic ([webex#357](webex#357)) ([94dd415](webex@94dd415))
* **widgets:** shifted-timer-to-worker ([webex#352](webex#352)) ([c06fe9c](webex@c06fe9c))
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants