Skip to content

Commit 3d080a6

Browse files
SQL queries are working
1 parent 5dc5e62 commit 3d080a6

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
11
import { useFormFieldContext } from "../hooks/form-field-context";
2+
import { useFormContext } from "../hooks/form-context";
23
import { useCustomize } from "../hooks/customization-context";
34
import type { CSSProperties } from "react";
45

56
export function ControlSql() {
67
const formFieldContext = useFormFieldContext();
8+
const formContext = useFormContext();
79
const {
810
id, onChange, prop, value,
911
} = formFieldContext;
1012
const {
1113
getProps, theme,
1214
} = useCustomize();
1315

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
19+
20+
// 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+
: "";
26+
27+
const handleChange = (queryText: string) => {
28+
// Transform the simple query string into the structured SQL object
29+
const sqlObject = {
30+
app: appName,
31+
query: queryText,
32+
params: [], // For now, always empty array
33+
};
34+
onChange(sqlObject);
35+
};
36+
1437
const baseStyles: CSSProperties = {
1538
color: theme.colors.neutral60,
1639
display: "block",
@@ -31,8 +54,8 @@ export function ControlSql() {
3154
<textarea
3255
id={id}
3356
name={prop.name}
34-
value={value ?? ""}
35-
onChange={(e) => onChange(e.target.value)}
57+
value={queryValue}
58+
onChange={(e) => handleChange(e.target.value)}
3659
placeholder="SELECT * FROM table_name"
3760
required={!prop.optional}
3861
{...getProps("controlSql", baseStyles, formFieldContext)}

packages/sdk/src/shared/component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export type PropValue<T extends ConfigurableProp["type"]> = T extends "alert"
125125
: T extends "string[]"
126126
? string[] // XXX support arrays differently?
127127
: T extends "sql"
128-
? string
128+
? { app: string; query: string; params: any[]; }
129129
: never;
130130

131131
export type ConfiguredProps<T extends ConfigurableProps> = {

0 commit comments

Comments
 (0)