Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/connect-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<!-- markdownlint-disable MD024 -->
# Changelog

# [1.0.0-preview.22] - 2025-01-21

- Allow custom string input for remote options

# [1.0.0-preview.21] - 2025-01-17

- Fix a bug in async prop value validation when the prop is a string
Expand Down
2 changes: 1 addition & 1 deletion packages/connect-react/examples/nextjs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/connect-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/connect-react",
"version": "1.0.0-preview.21",
"version": "1.0.0-preview.22",
"description": "Pipedream Connect library for React",
"files": [
"dist"
Expand Down
9 changes: 9 additions & 0 deletions packages/connect-react/src/components/ControlSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export function ControlSelect<T>({
MenuList: LoadMore,
}
}

const handleCreate = (inputValue: string) => {
options.unshift({
label: inputValue,
value: inputValue,
})
};
Comment on lines +100 to +105
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

Avoid direct array mutation and add input validation.

The handleCreate function directly mutates the options array, which could lead to unexpected behavior in React. Additionally, there's no validation of the input value.

Consider this safer implementation:

-  const handleCreate = (inputValue: string) => {
-    options.unshift({
-      label: inputValue,
-      value: inputValue,
-    })
-  };
+  const handleCreate = (inputValue: string) => {
+    if (!inputValue?.trim()) return;
+    const newOption = {
+      label: inputValue,
+      value: inputValue as T,
+    };
+    onChange([newOption, ...(Array.isArray(value) ? value : [])]);
+  };

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


const MaybeCreatableSelect = isCreatable
? CreatableSelect
: Select;
Expand All @@ -110,6 +118,7 @@ export function ControlSelect<T>({
required={!prop.optional}
{...props}
{...selectProps}
onCreateOption={handleCreate}
onChange={(o) => {
if (o) {
if (Array.isArray(o)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export function RemoteOptionsContainer({ queryEnabled }: RemoteOptionsContainerP

return (
<ControlSelect
isCreatable={true}
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

🛠️ Refactor suggestion

Confirmed: isCreatable needs to be configurable

The component's props interface (RemoteOptionsContainerProps) currently only includes queryEnabled and doesn't have any configuration for controlling the creatable behavior. Making isCreatable configurable through props would indeed improve component flexibility.

  • Add allowCustomInput?: boolean to RemoteOptionsContainerProps
  • Document the new prop's purpose and default behavior
🔗 Analysis chain

Make isCreatable configurable instead of hardcoded.

Hardcoding isCreatable to true forces all remote options to be creatable, which might not be appropriate for all use cases and could bypass server-side validation.

Consider making it configurable:

-      isCreatable={true}
+      isCreatable={prop.allowCustomInput}

This would require adding an allowCustomInput flag to the prop configuration schema.

Let's check if the prop configuration schema already supports this:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for prop configuration schema
rg -A 5 "type.*PropConfiguration" || rg -A 5 "interface.*PropConfiguration"

Length of output: 76


Script:

#!/bin/bash
# Check RemoteOptionsContainer.tsx for prop definitions
cat packages/connect-react/src/components/RemoteOptionsContainer.tsx | grep -A 10 "interface.*Props"

# Search for any remote options related types/interfaces
rg -g "*.ts*" -A 5 "interface.*Remote.*Props|type.*Remote.*Props"

Length of output: 760

showLoadMoreButton={showLoadMoreButton()}
onLoadMore={onLoadMore}
options={pageable.data}
Expand Down
3 changes: 1 addition & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading