Skip to content

Commit ff5e01a

Browse files
Adding support for the sql prop type in connect-react (#17011)
* Getting the UI working, SQL isn't yet working * SQL queries are working * Update pnpm-lock.yaml * Update pnpm-lock.yaml * Fixing up sql prop handling and PR feedback * Changelog, versions, and linting * Update ControlSql.tsx * Revert SDK changes to isolate connect-react changes Remove SQL prop type definitions from SDK to separate into standalone PR, keeping only connect-react component changes. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Reverting version and changelog from /sdk --------- Co-authored-by: Claude <[email protected]>
1 parent 300ff0a commit ff5e01a

File tree

6 files changed

+87
-1
lines changed

6 files changed

+87
-1
lines changed

packages/connect-react/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
# Changelog
44

5+
# [1.2.0] - 2025-06-05
6+
7+
- Adding basic support for 'sql' prop types
8+
59
# [1.1.0] - 2025-06-04
610

711
- Adding support for 'object' prop types

packages/connect-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/connect-react",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"description": "Pipedream Connect library for React",
55
"files": [
66
"dist"

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ControlBoolean } from "./ControlBoolean";
1111
import { ControlInput } from "./ControlInput";
1212
import { ControlObject } from "./ControlObject";
1313
import { ControlSelect } from "./ControlSelect";
14+
import { ControlSql } from "./ControlSql";
1415
import { RemoteOptionsContainer } from "./RemoteOptionsContainer";
1516

1617
export type ControlProps<T extends ConfigurableProps, U extends ConfigurableProp> = {
@@ -82,6 +83,8 @@ export function Control<T extends ConfigurableProps, U extends ConfigurableProp>
8283
return <ControlInput />;
8384
case "object":
8485
return <ControlObject />;
86+
case "sql":
87+
return <ControlSql />;
8588
default:
8689
// TODO "not supported prop type should bubble up"
8790
throw new Error("Unsupported property type: " + prop.type);
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { useFormFieldContext } from "../hooks/form-field-context";
2+
import { useCustomize } from "../hooks/customization-context";
3+
import type { CSSProperties } from "react";
4+
import type { ConfigurablePropSql } from "@pipedream/sdk";
5+
6+
// Type guard to check if value is a structured SQL object
7+
const isSqlStructuredValue = (value: unknown): value is { app: string; query: string; params: unknown[] } => {
8+
return (
9+
typeof value === "object" &&
10+
value !== null &&
11+
"query" in value &&
12+
typeof (value as Record<string, unknown>).query === "string"
13+
);
14+
};
15+
16+
export function ControlSql() {
17+
const formFieldContext = useFormFieldContext();
18+
const {
19+
id, onChange, prop, value,
20+
} = formFieldContext;
21+
const {
22+
getProps, theme,
23+
} = useCustomize();
24+
25+
// Cast prop to SQL prop type (this component is only used for SQL props)
26+
const sqlProp = prop as ConfigurablePropSql;
27+
28+
// Get the app name from the SQL prop's auth configuration
29+
const appName = sqlProp.auth?.app || "postgresql"; // Default to postgresql
30+
31+
// Extract the query string from the structured value or use empty string
32+
let queryValue = "";
33+
if (isSqlStructuredValue(value)) {
34+
queryValue = value.query;
35+
} else if (typeof value === "string") {
36+
queryValue = value;
37+
}
38+
39+
const handleChange = (queryText: string) => {
40+
// Transform the simple query string into the structured SQL object
41+
const sqlObject = {
42+
app: appName,
43+
query: queryText,
44+
params: [], // For now, always empty array
45+
};
46+
onChange(sqlObject);
47+
};
48+
49+
const baseStyles: CSSProperties = {
50+
color: theme.colors.neutral60,
51+
display: "block",
52+
border: "1px solid",
53+
borderColor: theme.colors.neutral20,
54+
padding: 6,
55+
width: "100%",
56+
borderRadius: theme.borderRadius,
57+
gridArea: "control",
58+
boxShadow: theme.boxShadow.input,
59+
fontSize: "0.875rem",
60+
fontFamily: "monospace",
61+
minHeight: "120px",
62+
resize: "vertical",
63+
};
64+
65+
return (
66+
<textarea
67+
id={id}
68+
name={prop.name}
69+
value={queryValue}
70+
onChange={(e) => handleChange(e.target.value)}
71+
placeholder="SELECT * FROM table_name"
72+
required={!prop.optional}
73+
{...getProps("controlSql", baseStyles, formFieldContext)}
74+
/>
75+
);
76+
}

packages/connect-react/src/hooks/customization-context.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { ControlBoolean } from "../components/ControlBoolean";
2929
import { ControlInput } from "../components/ControlInput";
3030
import { ControlObject } from "../components/ControlObject";
3131
import { ControlSelect } from "../components/ControlSelect";
32+
import { ControlSql } from "../components/ControlSql";
3233
import { ControlSubmit } from "../components/ControlSubmit";
3334
import { Description } from "../components/Description";
3435
import { Errors } from "../components/Errors";
@@ -73,6 +74,7 @@ export type CustomizableProps = {
7374
controlBoolean: ComponentProps<typeof ControlBoolean> & FormFieldContext<ConfigurableProp>;
7475
controlInput: ComponentProps<typeof ControlInput> & FormFieldContext<ConfigurableProp>;
7576
controlObject: ComponentProps<typeof ControlObject> & FormFieldContext<ConfigurableProp>;
77+
controlSql: ComponentProps<typeof ControlSql> & FormFieldContext<ConfigurableProp>;
7678
controlSubmit: ComponentProps<typeof ControlSubmit>;
7779
description: ComponentProps<typeof Description>;
7880
error: ComponentProps<typeof Errors>;

packages/connect-react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export { ControlApp } from "./components/ControlApp";
88
export { ControlBoolean } from "./components/ControlBoolean";
99
export { ControlInput } from "./components/ControlInput";
1010
export { ControlSelect } from "./components/ControlSelect";
11+
export { ControlSql } from "./components/ControlSql";
1112
export { ControlSubmit } from "./components/ControlSubmit";
1213
export { Description } from "./components/Description";
1314
export { ErrorBoundary } from "./components/ErrorBoundary";

0 commit comments

Comments
 (0)