Skip to content

Conversation

bzwrk
Copy link
Contributor

@bzwrk bzwrk commented Jan 24, 2025

[1.0.0-preview.24] - 2025-01-24

  • Fix the bug where inputting multiple strings into an array prop would merge the strings into one
  • Fix custom string input for remote options
  • Fix the reloading of a previously selected remote option when re-rendering the form component

Summary by CodeRabbit

  • Bug Fixes

    • Resolved issue with multiple string inputs merging into a single string
    • Fixed problems with custom string input for remote options
    • Corrected reloading of previously selected remote options during form re-rendering
    • Improved dropdown selection behavior to show prop label instead of value
  • Version Update

    • Package version updated to 1.0.0-preview.24

Copy link

linear bot commented Jan 24, 2025

Copy link

vercel bot commented Jan 24, 2025

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 Jan 27, 2025 7:01pm
pipedream-docs ⬜️ Ignored (Inspect) Jan 27, 2025 7:01pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Jan 27, 2025 7:01pm

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • packages/connect-react/examples/nextjs/package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request updates the @pipedream/connect-react package from version 1.0.0-preview.23 to 1.0.0-preview.24. The changes focus on improving the handling of remote options, string array properties, and form component rendering. Key modifications include enhancing state management in the ControlSelect component, updating the Control component to pass previous values, and adding a new optional prevValues property to the RemoteOptionsContainer component.

Changes

File Change Summary
packages/connect-react/CHANGELOG.md Updated to version 1.0.0-preview.24, documenting bug fixes for string array inputs, remote options, and form component re-rendering
packages/connect-react/package.json Version bumped from 1.0.0-preview.23 to 1.0.0-preview.24
packages/connect-react/src/components/Control.tsx Added value property to destructured field object, passing prevValues to RemoteOptionsContainer
packages/connect-react/src/components/ControlSelect.tsx Introduced new state management hooks for selectOptions and rawValue, refactored option handling and change management
packages/connect-react/src/components/RemoteOptionsContainer.tsx Added optional prevValues property to component props

Possibly related PRs

Suggested labels

bug, javascript, tracked internally, prioritized

Suggested reviewers

  • adolfo-pd
  • jverce

Poem

🐰 A rabbit's tale of code so bright,
Fixing strings with all my might,
Remote options dancing free,
React components in harmony!
Version bump, a preview's delight! 🚀


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

🔭 Outside diff range comments (1)
packages/connect-react/src/components/RemoteOptionsContainer.tsx (1)

Line range hint 127-146: Consider preserving options during refetch.

The current implementation might lose options when configuredProps change, as the pageable state is reset with each query. Consider:

  1. Using the new prevValues parameter to preserve options during refetch
  2. Implementing a merge strategy for existing and new options

Here's a suggested approach:

 const newOptions = []
 const allValues = new Set(pageable.values)
+// Preserve previous values if available
+if (prevValues && Array.isArray(prevValues)) {
+  for (const value of prevValues) {
+    allValues.add(typeof value === 'object' ? value.value : value)
+  }
+}
 for (const o of _options || []) {
   const value = typeof o === "string"
     ? o
     : o.value
   if (allValues.has(value)) {
     continue
   }
   allValues.add(value)
   newOptions.push(o)
 }
 let data = pageable.data
 if (newOptions.length) {
   data = [
+    ...(prevValues || []),  // Include previous values
     ...pageable.data,
     ...newOptions,
   ]
🧰 Tools
🪛 eslint

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: Lint Code Base

[failure] 15-15:
'prevValues' is defined but never used. Allowed unused args must match /^_/u

🪛 GitHub Actions: Pull Request Checks

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u

🧹 Nitpick comments (3)
packages/connect-react/src/components/ControlSelect.tsx (3)

34-53: Consider memoizing state updates to prevent unnecessary re-renders.

The state management changes help preserve remote options, but the current implementation might cause unnecessary re-renders when options or value reference equality changes but content remains the same.

Consider using deep comparison or memoization:

  useEffect(() => {
+   if (JSON.stringify(options) !== JSON.stringify(selectOptions)) {
      setSelectOptions(options)
+   }
  }, [options, selectOptions])

  useEffect(() => {
+   if (JSON.stringify(value) !== JSON.stringify(rawValue)) {
      setRawValue(value)
+   }
  }, [value, rawValue])

Line range hint 77-83: Add early return for empty selectOptions.

The loop through selectOptions could be simplified and made safer.

-            for (const item of selectOptions) {
+            const matchingOption = selectOptions?.find(item => item.value === o);
+            if (matchingOption) {
+              obj = matchingOption;
+            }
-              if (item.value === o) {
-                obj = item;
-                break;
-              }
-            }

202-223: Add proper TypeScript types for remote options prop.

The component would benefit from explicit TypeScript types for the remote options functionality.

  type ControlSelectProps<T> = {
    isCreatable?: boolean;
    options: {label: string; value: T;}[];
    selectProps?: ReactSelectProps;
    showLoadMoreButton?: boolean;
    onLoadMore?: () => void;
+   prop: {
+     remoteOptions?: boolean;
+     type: string;
+     withLabel?: boolean;
+     optional?: boolean;
+   };
  };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8781da4 and 238bfea.

⛔ Files ignored due to path filters (2)
  • packages/connect-react/examples/nextjs/package-lock.json is excluded by !**/package-lock.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (5)
  • packages/connect-react/CHANGELOG.md (1 hunks)
  • packages/connect-react/package.json (1 hunks)
  • packages/connect-react/src/components/Control.tsx (1 hunks)
  • packages/connect-react/src/components/ControlSelect.tsx (6 hunks)
  • packages/connect-react/src/components/RemoteOptionsContainer.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/connect-react/package.json
🧰 Additional context used
🪛 GitHub Actions: Pull Request Checks
packages/connect-react/CHANGELOG.md

[warning] File ignored because of a matching ignore pattern. Use "--no-ignore" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning

packages/connect-react/src/components/RemoteOptionsContainer.tsx

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u

🪛 eslint
packages/connect-react/src/components/RemoteOptionsContainer.tsx

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: Lint Code Base
packages/connect-react/src/components/RemoteOptionsContainer.tsx

[failure] 15-15:
'prevValues' is defined but never used. Allowed unused args must match /^_/u

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: pnpm publish
🔇 Additional comments (4)
packages/connect-react/CHANGELOG.md (2)

4-5: LGTM! Version and date are properly formatted.

The new version entry follows the established format and maintains chronological order.

🧰 Tools
🪛 GitHub Actions: Pull Request Checks

[warning] File ignored because of a matching ignore pattern. Use "--no-ignore" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning


6-8: LGTM! Bug fixes are well-documented.

The changelog entries clearly describe three distinct fixes:

  1. String array property merging issue
  2. Custom string input for remote options
  3. Remote options reloading during form re-render (addresses the PR title issue)
🧰 Tools
🪛 GitHub Actions: Pull Request Checks

[warning] File ignored because of a matching ignore pattern. Use "--no-ignore" to disable file ignore settings or use "--no-warn-ignored" to suppress this warning

packages/connect-react/src/components/Control.tsx (1)

27-27: LGTM! Clean addition of the value prop.

The addition of value to the destructured properties is well-typed and necessary for supporting the remote options state management.

packages/connect-react/src/components/ControlSelect.tsx (1)

Line range hint 1-223: Overall implementation looks good with suggested improvements.

The changes effectively address the issue of remote options getting unset by maintaining separate state for options and values. The implementation could be enhanced with the suggested improvements for type safety, performance, and error handling, but the core functionality appears solid.


if (prop.remoteOptions || prop.type === "$.discord.channel") {
return <RemoteOptionsContainer queryEnabled={queryDisabledIdx == null || queryDisabledIdx >= idx} />;
return <RemoteOptionsContainer prevValues={value} queryEnabled={queryDisabledIdx == null || queryDisabledIdx >= idx} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Type incompatibility detected with prevValues prop

The RemoteOptionsContainer explicitly types prevValues as never, indicating it should not receive any value. However, the Control component is attempting to pass a value to it. Either:

  • Remove the prevValues prop from the Control component's usage, or
  • Update RemoteOptionsContainerProps to accept the appropriate type if the prop is needed
🔗 Analysis chain

Verify type safety of the prevValues prop.

While the addition of prevValues={value} aligns with the PR's objective to maintain remote options state, please ensure:

  1. The RemoteOptionsContainer component properly handles undefined values
  2. The type of value matches what RemoteOptionsContainer expects for prevValues

Let's verify the type compatibility:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for RemoteOptionsContainer's type definition and usage
ast-grep --pattern 'type $_ = {
  $$$
  prevValues?: $_
  $$$
}'

# Search for all usages to verify consistent typing
rg -A 2 'RemoteOptionsContainer.*prevValues'

Length of output: 759

Comment on lines +170 to +200
if (o) {
if (Array.isArray(o)) {
if (typeof o[0] === "object" && "value" in o[0]) {
const vs = [];
for (const _o of o) {
if (prop.withLabel) {
vs.push(_o);
} else {
vs.push(_o.value);
}
}
onChange(vs);
} else {
onChange(o);
}
} else if (typeof o === "object" && "value" in o) {
if (prop.withLabel) {
onChange({
__lv: o,
});
} else {
onChange(o.value);
}
} else {
throw new Error("unhandled option type"); // TODO
}
} else {
onChange(undefined);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve error handling and type checking.

The error handling and type checking in handleChange could be improved:

  1. The error message is not descriptive enough
  2. The type checking logic could be simplified using TypeScript type guards
+ type SelectOption = { value: unknown; label: string };
+ 
+ function isSelectOption(o: unknown): o is SelectOption {
+   return typeof o === "object" && o !== null && "value" in o;
+ }
+ 
  const handleChange = (o: unknown) => {
    if (o) {
      if (Array.isArray(o)) {
-        if (typeof o[0] === "object" && "value" in o[0]) {
+        if (o.length > 0 && isSelectOption(o[0])) {
          const vs = [];
          for (const _o of o) {
            if (prop.withLabel) {
              vs.push(_o);
            } else {
              vs.push(_o.value);
            }
          }
          onChange(vs);
        } else {
          onChange(o);
        }
-      } else if (typeof o === "object" && "value" in o) {
+      } else if (isSelectOption(o)) {
        if (prop.withLabel) {
          onChange({
            __lv: o,
          });
        } else {
          onChange(o.value);
        }
      } else {
-        throw new Error("unhandled option type"); // TODO
+        throw new Error(`Unhandled option type: ${typeof o}. Expected an array or an object with 'value' property.`);
      }
    } else {
      onChange(undefined);
    }
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const handleChange = (o: unknown) => {
if (o) {
if (Array.isArray(o)) {
if (typeof o[0] === "object" && "value" in o[0]) {
const vs = [];
for (const _o of o) {
if (prop.withLabel) {
vs.push(_o);
} else {
vs.push(_o.value);
}
}
onChange(vs);
} else {
onChange(o);
}
} else if (typeof o === "object" && "value" in o) {
if (prop.withLabel) {
onChange({
__lv: o,
});
} else {
onChange(o.value);
}
} else {
throw new Error("unhandled option type"); // TODO
}
} else {
onChange(undefined);
}
}
type SelectOption = { value: unknown; label: string };
function isSelectOption(o: unknown): o is SelectOption {
return typeof o === "object" && o !== null && "value" in o;
}
const handleChange = (o: unknown) => {
if (o) {
if (Array.isArray(o)) {
if (o.length > 0 && isSelectOption(o[0])) {
const vs = [];
for (const _o of o) {
if (prop.withLabel) {
vs.push(_o);
} else {
vs.push(_o.value);
}
}
onChange(vs);
} else {
onChange(o);
}
} else if (isSelectOption(o)) {
if (prop.withLabel) {
onChange({
__lv: o,
});
} else {
onChange(o.value);
}
} else {
throw new Error(`Unhandled option type: ${typeof o}. Expected an array or an object with 'value' property.`);
}
} else {
onChange(undefined);
}
}


export type RemoteOptionsContainerProps = {
queryEnabled?: boolean;
prevValues?: never;
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect type definition for prevValues.

The type never makes this prop unusable. If this prop is intended to store previous values, consider using a more appropriate type that matches the value structure of your form field.

-  prevValues?: never;
+  prevValues?: unknown;  // Replace with actual type based on your form field value structure

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 14 to 16
export function RemoteOptionsContainer({
queryEnabled, prevValues,
}: RemoteOptionsContainerProps) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

⚠️ Potential issue

Type definition contradicts component usage

The review comment is valid and reveals additional issues:

  1. prevValues is typed as never in props type but being passed a value in Control.tsx
  2. The parameter is unused in the implementation

Please address these inconsistencies by either:

  1. Implementing the prevValues logic and updating its type definition to match the expected value type, or
  2. Removing both the parameter and its usage in Control.tsx
🔗 Analysis chain

Address unused parameter and clarify implementation.

The prevValues parameter is added but never used in the implementation. Based on the PR title suggesting a fix for "remote options gets unset when loading configuredProps", this parameter seems important.

Please either:

  1. Implement the logic using prevValues to fix the unset remote options issue, or
  2. Remove the parameter if it's not needed.

Let's verify if this component is used with the prevValues prop:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for RemoteOptionsContainer usage with prevValues prop
ast-grep --pattern 'RemoteOptionsContainer $props={$_}'

Length of output: 57


Script:

#!/bin/bash
# Search for any usage of RemoteOptionsContainer
rg "RemoteOptionsContainer" -A 3 -B 3

# Also check the implementation to understand the component
cat packages/connect-react/src/components/RemoteOptionsContainer.tsx

Length of output: 8607

🧰 Tools
🪛 eslint

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u.

(@typescript-eslint/no-unused-vars)

🪛 GitHub Check: Lint Code Base

[failure] 15-15:
'prevValues' is defined but never used. Allowed unused args must match /^_/u

🪛 GitHub Actions: Pull Request Checks

[error] 15-15: 'prevValues' is defined but never used. Allowed unused args must match /^_/u

@bzwrk bzwrk merged commit 9b478e3 into master Jan 27, 2025
8 checks passed
@bzwrk bzwrk deleted the biz/dj-2825-remote-options-gets-unset-when-loading-configuredprops branch January 27, 2025 20:20
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.

2 participants