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: migrate all lodash usages with ramda in web device mode integrations #1684

Merged
merged 20 commits into from
Jun 13, 2024

Conversation

mihir-4116
Copy link
Contributor

@mihir-4116 mihir-4116 commented Apr 4, 2024

PR Description

  • In this pr we migrate all lodash usages with ramda in web device mode integrations

Linear task (optional)

Linear task link

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • New Features

    • Enhanced utility functions in Adobe Analytics integration for better data handling and configuration.
    • Introduced new test suites to ensure reliability of utility functions.
  • Bug Fixes

    • Improved the implementation of the get function to enhance performance and accuracy.
  • Tests

    • Added comprehensive tests for utility functions in Adobe Analytics integration to validate data mapping, configuration settings, and value retrieval.

@mihir-4116 mihir-4116 added the Ready for review Changes are ready to be reviewed label Apr 4, 2024
@mihir-4116 mihir-4116 requested a review from saikumarrs April 4, 2024 06:52
@mihir-4116 mihir-4116 self-assigned this Apr 4, 2024
Copy link
Contributor

coderabbitai bot commented Apr 4, 2024

Walkthrough

The changes primarily focus on refactoring and enhancing the utility functions within the Adobe Analytics integration of the analytics-js library. Key modifications include replacing the lodash.get import with a custom get function using ramda, consolidating utility imports, and adding new test suites to ensure comprehensive coverage of the utility functions.

Changes

Files Change Summary
.../AdobeAnalytics/util.js Removed lodash.get, added isDefined from @rudderstack/analytics-js-common/utilities/checks, added ramda's path, consolidated utility imports, and updated the get function implementation.
.../AdobeAnalytics/util.js Updated exported functions to include the new get function.
.../AdobeAnalytics/util.test.js Added tests for getDataFromContext, handleLists, mapMerchProductEvents, and get functions.
.../commonUtils.test.js Introduced new test suites for isBlank and isNotEmpty functions, covering various input scenarios.

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

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • 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.

@mihir-4116 mihir-4116 changed the title chore: migrate all lodash usages with ramda in web device mode integrations chore(INT-1613): migrate all lodash usages with ramda in web device mode integrations Apr 4, 2024
@mihir-4116 mihir-4116 changed the title chore(INT-1613): migrate all lodash usages with ramda in web device mode integrations chore: migrate all lodash usages with ramda in web device mode integrations Apr 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: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7b84a6a and 8824de3.
Files selected for processing (5)
  • packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/Braze/browser.js (2 hunks)
  • packages/analytics-js-integrations/src/integrations/FacebookPixel/utils.js (1 hunks)
  • packages/analytics-js-integrations/src/utils/commonUtils.js (3 hunks)
  • packages/analytics-js-integrations/src/utils/utils.js (2 hunks)
Additional comments not posted (7)
packages/analytics-js-integrations/src/utils/commonUtils.js (2)

10-13: Ensure the isDefined function from @rudderstack/analytics-js-common/utilities/checks is correctly implemented and exported, as the local isDefined function seems to have been replaced but its implementation is not visible here.


10-13: The pickBy function from Ramda is used correctly to replace lodash's pickBy functionality. However, ensure that the predicate functions (isDefined, isNotNull, etc.) are correctly defined and imported, as their implementations are not visible in this snippet.

packages/analytics-js-integrations/src/integrations/FacebookPixel/utils.js (1)

8-8: Ensure the isDefined function from @rudderstack/analytics-js-common/utilities/checks is correctly imported and used throughout the file. This change aligns with the migration goal and helps in maintaining consistency across the codebase.

packages/analytics-js-integrations/src/integrations/Braze/browser.js (2)

2-2: The replacement of lodash.isequal with ramda.equals is correctly implemented. This change aligns with the migration goal and leverages Ramda's functional programming capabilities for value comparison.


201-206: Ensure that the equals function from Ramda is used correctly for deep comparison of objects and dates. This change improves consistency and aligns with the migration from lodash to Ramda.

packages/analytics-js-integrations/src/utils/utils.js (1)

4-4: The import of isDefined from @rudderstack/analytics-js-common/utilities/checks is correctly implemented. This change aligns with the goal of using centralized utility functions and improves code maintainability.

packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (1)

5-5: Ensure that all instances previously using isDefined from ../../utils/commonUtils are now correctly using the new import from @rudderstack/analytics-js-common/utilities/checks.

Verification successful

The verification process did not find any remaining references to isDefined being imported from the old path (../../utils/commonUtils). This suggests that the transition to the new import path from @rudderstack/analytics-js-common/utilities/checks has been successfully completed.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for any remaining references to the old `isDefined` import path.
rg --type js "from '../../utils/commonUtils' import .*isDefined"

Length of output: 72

Copy link

codecov bot commented Apr 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 55.47%. Comparing base (8b25cbe) to head (f6bf97f).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1684      +/-   ##
===========================================
+ Coverage    55.10%   55.47%   +0.37%     
===========================================
  Files          464      464              
  Lines        15845    15849       +4     
  Branches      3166     3189      +23     
===========================================
+ Hits          8731     8793      +62     
+ Misses        5854     5731     -123     
- Partials      1260     1325      +65     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Apr 4, 2024

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Common Code - No bundling 15.77 KB 15.77 KB (0%) 16.5 KB
Remote Module Federation Mapping - CDN 330 B 330 B (0%) 512 B
Remote Module Federated Plugins - CDN 5.69 KB 5.69 KB (0%) 6 KB
Core ESM - NPM 7.68 KB 7.68 KB (0%) 8 KB
Core CJS - NPM 23.64 KB 23.64 KB (0%) 24 KB
Core - NPM 23.68 KB 23.68 KB (0%) 24 KB
Core Legacy - CDN 44.38 KB 44.38 KB (0%) 45 KB
Core - CDN 23.93 KB 23.93 KB (0%) 24.5 KB
Core (legacy build) - CDN - v1.1 31.42 KB 31.42 KB (0%) 32 KB
Core - NPM - v1.1 31.49 KB 31.49 KB (0%) 32 KB
Service Worker Module 23.3 KB 20.83 KB (-10.62% ▼) 24 KB
All Integrations (legacy build) - CDN 99.1 KB 92.8 KB (-6.36% ▼) 105 KB

Copy link
Member

@saikumarrs saikumarrs left a comment

Choose a reason for hiding this comment

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

Let's also remove these unwanted dependencies from the package.json file.

Also, we should test all the affected destinations.

Copy link

Hello! This PR has been open for 20 days without any activity. Therefore, it's considered as stale and is scheduled to be closed in 10 days. If you're still working on this, please remove the 'Stale' label or add a comment to keep it open. Thanks for your contribution!

@github-actions github-actions bot added the Stale label Apr 25, 2024
@github-actions github-actions bot removed the Stale label May 1, 2024
@mihir-4116 mihir-4116 requested a review from a team as a code owner May 1, 2024 16:31
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: 2

@ItsSudip ItsSudip requested a review from saikumarrs May 2, 2024 04:35
@saikumarrs
Copy link
Member

@ItsSudip , have we tested all the impacted destinations?

@ItsSudip
Copy link
Member

ItsSudip commented May 2, 2024

@ItsSudip , have we tested all the impacted destinations?

Not yet. As I have updated some utility functions, it will affect many integrations. Let me test the popular one at least and the directly impacted destinations like Braze, and Adobe Analytics.

coderabbitai[bot]
coderabbitai bot previously approved these changes May 2, 2024
Copy link

Hello! This PR has been open for 20 days without any activity. Therefore, it's considered as stale and is scheduled to be closed in 10 days. If you're still working on this, please remove the 'Stale' label or add a comment to keep it open. Thanks for your contribution!

@github-actions github-actions bot added the Stale label May 23, 2024
@MoumitaM MoumitaM removed the Stale label May 24, 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f61a200 and dae6b42.

Files selected for processing (3)
  • packages/analytics-js-integrations/tests/utils/commonUtils.test.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/Braze/browser.js (5 hunks)
  • packages/analytics-js-integrations/src/utils/commonUtils.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/analytics-js-integrations/src/utils/commonUtils.js
Additional comments not posted (1)
packages/analytics-js-integrations/src/integrations/Braze/browser.js (1)

Line range hint 2-11: Changes in the identify method and the use of Ramda functions look good.

The migration from lodash to Ramda for functions like equals and isNotEmpty is correctly implemented. The deduplication logic in the identify method is complex but well-handled, ensuring that only changed user attributes are updated.

Also applies to: 190-240

Copy link
Member

@saikumarrs saikumarrs left a comment

Choose a reason for hiding this comment

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

Mostly looks good to me. But it concerns me that most of these common utilities do not have a proper test suite of their own asserting their expected behavior.

If possible, let's address it. At least for the ones, that have been impacted in this PR.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jun 10, 2024
saikumarrs
saikumarrs previously approved these changes Jun 10, 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: 4

Outside diff range and nitpick comments (1)
packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (1)

Line range hint 132-132: Change to an optional chain to simplify the code and improve readability.

- if (properties[rudderProp.eventMerchProperties])
+ if (properties?.[rudderProp.eventMerchProperties])
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dae6b42 and c061661.

Files selected for processing (3)
  • packages/analytics-js-integrations/tests/integrations/AdobeAnalytics/util.test.js (1 hunks)
  • packages/analytics-js-integrations/tests/utils/commonUtils.test.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (2 hunks)
Additional context used
Learnings (1)
packages/analytics-js-integrations/__tests__/utils/commonUtils.test.js (1)
User: ItsSudip
PR: rudderlabs/rudder-sdk-js#1684
File: packages/analytics-js-integrations/__tests__/utils/commonUtils.test.js:355-357
Timestamp: 2024-06-10T07:43:52.149Z
Learning: The `isBlank` function in `commonUtils.test.js` is expected to return `false` when the input is `null`, as per the specific implementation and requirement of the project.
Biome
packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js

[error] 132-132: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

Additional comments not posted (5)
packages/analytics-js-integrations/__tests__/integrations/AdobeAnalytics/util.test.js (4)

1-7: The imports and exports are correctly updated to reflect the new utility functions.


9-16: Ensure that the windowSpy mock is correctly restored after each test to prevent side effects in subsequent tests.


18-72: The tests for getDataFromContext function are comprehensive and cover various scenarios. Good job on ensuring edge cases are tested.


180-240: The tests for the get function are thorough and effectively test various edge cases. Ensure that the function's behavior is consistent across all browsers, especially with unusual property names.

packages/analytics-js-integrations/__tests__/utils/commonUtils.test.js (1)

349-379: The tests for the isBlank function are correctly implemented according to the project's requirements. No changes are needed here as the behavior of treating null as not blank is intentional.

@ItsSudip ItsSudip requested a review from saikumarrs June 11, 2024 05:38
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 and nitpick comments (1)
packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (1)

Line range hint 132-132: Consider using optional chaining to simplify the code and improve readability.

- const { bitrate, startupTime, fps, droppedFrames } = properties;
+ const { bitrate, startupTime, fps, droppedFrames } = properties || {};

This change ensures that the code does not throw an error if properties is undefined, enhancing robustness.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c061661 and 61f8a8c.

Files ignored due to path filters (2)
  • package-lock.json is excluded by !**/package-lock.json, !**/*.json
  • packages/analytics-js-integrations/package.json is excluded by !**/*.json
Files selected for processing (1)
  • packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js (2 hunks)
Additional context used
Biome
packages/analytics-js-integrations/src/integrations/AdobeAnalytics/util.js

[error] 132-132: Change to an optional chain. (lint/complexity/useOptionalChain)

Unsafe fix: Change to an optional chain.

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 UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 61f8a8c and 0fbe170.

Files selected for processing (1)
  • packages/analytics-js-integrations/tests/integrations/AdobeAnalytics/util.test.js (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/analytics-js-integrations/tests/integrations/AdobeAnalytics/util.test.js

@ItsSudip ItsSudip requested a review from saikumarrs June 11, 2024 13:10
Copy link

@ItsSudip ItsSudip requested a review from saikumarrs June 12, 2024 07:02
@ItsSudip ItsSudip merged commit 2eea5a1 into develop Jun 13, 2024
9 checks passed
@ItsSudip ItsSudip deleted the chore.clean-up branch June 13, 2024 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review Changes are ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants