Skip to content

Commit f32642e

Browse files
Fixing up sql prop handling and PR feedback
1 parent 9e6006c commit f32642e

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
import { useFormFieldContext } from "../hooks/form-field-context";
2-
import { useFormContext } from "../hooks/form-context";
32
import { useCustomize } from "../hooks/customization-context";
43
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: any[] } => {
8+
return (
9+
typeof value === "object" &&
10+
value !== null &&
11+
"query" in value &&
12+
typeof (value as any).query === "string"
13+
);
14+
};
515

616
export function ControlSql() {
717
const formFieldContext = useFormFieldContext();
8-
const formContext = useFormContext();
918
const {
1019
id, onChange, prop, value,
1120
} = formFieldContext;
1221
const {
1322
getProps, theme,
1423
} = useCustomize();
1524

16-
// Find the first app prop to determine which database app to use
17-
const appProp = formContext.configurableProps.find((p: any) => p.type === "app");
18-
const appName = appProp?.app || "postgresql"; // Default to postgresql
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
1930

2031
// Extract the query string from the structured value or use empty string
21-
const queryValue = typeof value === "object" && value && "query" in value
22-
? (value as any).query
23-
: typeof value === "string"
24-
? value
25-
: "";
32+
let queryValue = "";
33+
if (isSqlStructuredValue(value)) {
34+
queryValue = value.query;
35+
} else if (typeof value === "string") {
36+
queryValue = value;
37+
}
2638

2739
const handleChange = (queryText: string) => {
2840
// Transform the simple query string into the structured SQL object

packages/sdk/src/shared/component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ export type ConfigurablePropStringArray = BaseConfigurableProp & {
8888
} & Defaultable<string[]>; // TODO
8989
export type ConfigurablePropSql = BaseConfigurableProp & {
9090
type: "sql";
91+
auth: {
92+
app: string;
93+
};
9194
} & Defaultable<string>;
9295
// | { type: "$.interface.http" } // source only
9396
// | { type: "$.interface.timer" } // source only

0 commit comments

Comments
 (0)