Skip to content

Zoho CRM - support picklist fields #14974

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

Merged
merged 4 commits into from
Dec 17, 2024
Merged

Zoho CRM - support picklist fields #14974

merged 4 commits into from
Dec 17, 2024

Conversation

michelle0927
Copy link
Collaborator

@michelle0927 michelle0927 commented Dec 13, 2024

Resolves #14939

Summary by CodeRabbit

  • New Features

    • Introduced a new method for parsing fields, enhancing error handling for JSON values.
    • Updated functionality to include "picklist" data types in filtered results.
  • Version Updates

    • Updated version for create and update actions from "0.3.2" to "0.3.3".
    • Incremented the package version from "0.5.2" to "0.5.3" and updated platform dependency to a newer version.
  • Bug Fixes

    • Improved handling of object construction before API calls for create and update actions.
    • Enhanced error handling for response codes in the update action.

Copy link

vercel bot commented Dec 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Dec 16, 2024 4:23pm
pipedream-docs ⬜️ Ignored (Inspect) Dec 16, 2024 4:23pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Dec 16, 2024 4:23pm

Copy link
Contributor

coderabbitai bot commented Dec 13, 2024

Walkthrough

The pull request introduces several modifications across multiple files within the Zoho CRM component. Key changes include an updated method signature for getType, the addition of a new parseFields method, and the removal of the "picklist" data type from exclusion lists, allowing its inclusion in filtered results. The run methods in both create and update actions now utilize parseFields for object processing before API calls. Additionally, version updates are made in the relevant files, and the package.json reflects an upgrade in dependency versions.

Changes

File Path Change Summary
components/zoho_crm/actions/common/common-objects.mjs - Updated getType method signature.
- Added parseFields method.
- Removed "picklist" from exclusion list in filterFields.
components/zoho_crm/actions/create-object/create-object.mjs - Updated version from "0.3.2" to "0.3.3".
- Modified run method to use this.parseFields(object).
components/zoho_crm/actions/update-object/update-object.mjs - Updated version from "0.3.2" to "0.3.3".
- Modified run method to use this.parseFields(object).
components/zoho_crm/package.json - Updated version from "0.5.2" to "0.5.3".
- Updated dependency @pipedream/platform from ^1.2.0 to ^3.0.3.

Assessment against linked issues

Objective Addressed Explanation
Investigate and allow picklist fields in filtering (14939)

Possibly related PRs

  • Hubspot - Update Deal #14891: The main PR introduces significant changes to the common-objects.mjs file, particularly in the handling of field types and properties, which may relate to the updates made in the HubSpot deal management functionalities in this PR, as both involve modifications to object properties and their management.
  • Hubspot - New Custom Object Property Change #14977: This PR introduces a new source for monitoring changes to custom object properties in HubSpot, which aligns with the main PR's focus on enhancing object handling and property management in the Zoho CRM context.

Suggested labels

action

Suggested reviewers

  • jcortes

Poem

In the fields of code we play,
With picklists now here to stay.
Parsing JSON, oh what a sight,
Making data structures just right!
A hop, a skip, a version change,
In Zoho's world, we now arrange! 🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 62b8546 and 28c490b.

📒 Files selected for processing (3)
  • components/zoho_crm/actions/common/common-objects.mjs (2 hunks)
  • components/zoho_crm/actions/create-object/create-object.mjs (2 hunks)
  • components/zoho_crm/actions/update-object/update-object.mjs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/zoho_crm/actions/create-object/create-object.mjs
🔇 Additional comments (3)
components/zoho_crm/actions/common/common-objects.mjs (1)

151-162: LGTM: Proper handling of picklist values

The implementation correctly maps picklist values to a structured format with value/label pairs, which is essential for proper dropdown rendering in the UI.

components/zoho_crm/actions/update-object/update-object.mjs (2)

3-3: LGTM: Version bump and import

The version bump and ConfigurationError import are appropriate given the new functionality and error handling.

Also applies to: 10-10


62-77: LGTM: Improved error handling

The error handling has been enhanced with specific error messages for different scenarios:

  • SUCCESS: Clear success message
  • INVALID_DATA: Detailed field validation error
  • Other cases: General error message

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.

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)
components/zoho_crm/actions/common/common-objects.mjs (1)

166-183: Refine parseFields to avoid unintended parsing of string values

The parseFields method currently attempts to parse all string values in fields, which might unintentionally parse regular string fields that are not JSON. Consider modifying the method to only parse fields known to contain JSON strings to prevent potential data issues.

Apply this diff to refine the parseFields method:

 def parseFields(fields) {
   if (!fields) {
     return;
   }
   for (const [
     key,
     value,
   ] of Object.entries(fields)) {
     try {
-      if (typeof value === "string") {
+      if (this.isJsonField(key) && typeof value === "string") {
         fields[key] = JSON.parse(value);
       }
     } catch {
       fields[key] = value;
     }
   }
   return fields;
 }

+// Helper method to determine if a field is expected to be a JSON string
+isJsonField(fieldName) {
+  const jsonFields = [
+    // Add field names that are expected to contain JSON strings
+    "jsonField1",
+    "jsonField2",
+  ];
+  return jsonFields.includes(fieldName);
+}

You can define an isJsonField helper method to check if a field should be parsed, preventing unintended parsing of plain string fields.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ace38f7 and 5287926.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (4)
  • components/zoho_crm/actions/common/common-objects.mjs (2 hunks)
  • components/zoho_crm/actions/create-object/create-object.mjs (2 hunks)
  • components/zoho_crm/actions/update-object/update-object.mjs (2 hunks)
  • components/zoho_crm/package.json (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/zoho_crm/package.json
🔇 Additional comments (5)
components/zoho_crm/actions/common/common-objects.mjs (1)

155-162: Properly map picklist values to options

The mapping of pick_list_values to the options property within getOptionalProps is correctly implemented. This will effectively populate the options for fields with picklist values.

components/zoho_crm/actions/update-object/update-object.mjs (2)

9-9: Version updated to "0.3.3"

The version bump from "0.3.2" to "0.3.3" is appropriate given the introduced changes.


64-64: Ensure parseFields usage aligns with data expectations

The object is now processed through this.parseFields(object) before being passed to zohoCrm.updateObject. Verify that this transformation is compatible with the expected data format and that it does not introduce unintended consequences due to parsing, especially in light of the concerns raised about parseFields.

Run the following script to test the integrity of the data after parsing:

Ensure that the parsed object maintains the correct data types and values.

✅ Verification successful

parseFields implementation is safe and appropriate for this usage

The parseFields method implementation in common-objects.mjs is designed to handle string-to-JSON conversion for field values, with proper error handling. It:

  • Only attempts to parse string values that might be JSON
  • Preserves the original value if parsing fails
  • Maintains non-string values as-is
  • Returns undefined if no fields are provided

Its usage in update-object.mjs is appropriate as it ensures any stringified JSON fields are properly converted before being sent to the Zoho CRM API, preventing potential data format issues.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the parsed object fields retain expected data types.

# Assuming you have test cases or sample data
# Output the object before and after parsing to compare
echo "Original object:"
cat sample_object.json

echo "Parsed object:"
node -e '
  const fs = require("fs");
  const common = require("./components/zoho_crm/actions/common/common-objects.mjs");
  const object = JSON.parse(fs.readFileSync("sample_object.json", "utf8"));
  console.log(common.parseFields(object));
'

Length of output: 959


Script:

#!/bin/bash
# Let's examine the parseFields implementation and its usage
ast-grep --pattern 'parseFields($$$)' -l javascript

# Also check the content of the common-objects.mjs file
cat components/zoho_crm/actions/common/common-objects.mjs

# And examine the update-object.mjs file for context
cat components/zoho_crm/actions/update-object/update-object.mjs

Length of output: 6803

components/zoho_crm/actions/create-object/create-object.mjs (2)

8-8: Version updated to "0.3.3"

The version increment from "0.3.2" to "0.3.3" reflects the updates made in the action.


56-56: Validate the use of parseFields when creating objects

The object is now being processed with this.parseFields(object) before the API call in zohoCrm.createObject. Please ensure that this change is appropriate and does not lead to unintended data parsing issues, considering the earlier suggestion to refine parseFields.

Run the following script to confirm that object creation works as expected with the parsed fields:

Check that the parsedObject contains the correct data and types before proceeding with the API call.

✅ Verification successful

parseFields implementation is safe and appropriate for object creation

The implementation of parseFields in common-objects.mjs is straightforward and safe. It attempts to parse string values as JSON only if they are actually strings, preserving the original value if parsing fails. This is appropriate for the create object operation as it:

  • Handles potential JSON strings that might be passed as field values
  • Preserves non-string values as-is
  • Maintains the original value if JSON parsing fails
  • Does not modify the structure of the object, only attempts to parse string values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Test the create object functionality with parsed fields.

# This is a placeholder for an API test; in practice, you would mock the API call
echo "Testing createObject with parsed fields"
node -e '
  const common = require("./components/zoho_crm/actions/common/common-objects.mjs");
  const createObject = require("./components/zoho_crm/actions/create-object/create-object.mjs");
  const sampleObject = {/* provide sample data */};
  const parsedObject = common.parseFields(sampleObject);
  // Mock zohoCrm.createObject or log the parsedObject for inspection
  console.log(parsedObject);
'

Length of output: 1048


Script:

#!/bin/bash
# Let's examine the implementation of parseFields and its usage
ast-grep --pattern 'parseFields($$$)'

# Also check the content of both files
echo "=== Content of create-object.mjs ==="
cat components/zoho_crm/actions/create-object/create-object.mjs

echo -e "\n=== Content of common-objects.mjs ==="
cat components/zoho_crm/actions/common/common-objects.mjs

Length of output: 6984

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)
components/zoho_crm/actions/common/common-objects.mjs (1)

36-57: Simplify the type mapping implementation and remove unnecessary semicolon

The implementation can be improved in a few ways:

  1. Remove the unnecessary semicolon after the switch statement
  2. Consider using an object map for type mapping instead of switch-case

Here's a more concise implementation:

    getType({
      data_type: dataType, json_type: jsonType,
    }) {
-      let type;
-      switch (dataType) {
-      case "boolean":
-        type = "boolean";
-        break;
-      case "integer":
-        type = "integer";
-        break;
-      case "bigint":
-        type = "integer";
-        break;
-      default:
-        type = "string";
-        break;
-      };
+      const typeMap = {
+        boolean: "boolean",
+        integer: "integer",
+        bigint: "integer"
+      };
+      const type = typeMap[dataType] || "string";
      if (jsonType === "jsonarray") {
        return `${type}[]`;
      }
      return type;
    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5287926 and 62b8546.

📒 Files selected for processing (1)
  • components/zoho_crm/actions/common/common-objects.mjs (2 hunks)
🔇 Additional comments (2)
components/zoho_crm/actions/common/common-objects.mjs (2)

151-162: LGTM! Well-structured picklist handling

The changes to getOptionalProps are well implemented:

  • Correctly passes field object to the updated getType method
  • Good handling of picklist values with clear mapping to value/label pairs

36-38: Update all getType method calls in the codebase

The getType method signature has changed to accept an object with data_type and json_type properties. All calls to this method throughout the codebase need to be updated to match the new signature to prevent runtime errors.

GTFalcao
GTFalcao previously approved these changes Dec 13, 2024
Copy link
Collaborator

@GTFalcao GTFalcao left a comment

Choose a reason for hiding this comment

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

LGTM!

@michelle0927
Copy link
Collaborator Author

/approve

@michelle0927 michelle0927 merged commit c413ff5 into master Dec 17, 2024
11 checks passed
@michelle0927 michelle0927 deleted the issue-14939 branch December 17, 2024 17:22
@coderabbitai coderabbitai bot mentioned this pull request Feb 4, 2025
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.

[FEATURE] Investigate Zoho CRM filtering for picklist
2 participants