Skip to content

Commit 5dc5e62

Browse files
Getting the UI working, SQL isn't yet working
1 parent 9c33a97 commit 5dc5e62

File tree

5 files changed

+53
-1
lines changed

5 files changed

+53
-1
lines changed

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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useFormFieldContext } from "../hooks/form-field-context";
2+
import { useCustomize } from "../hooks/customization-context";
3+
import type { CSSProperties } from "react";
4+
5+
export function ControlSql() {
6+
const formFieldContext = useFormFieldContext();
7+
const {
8+
id, onChange, prop, value,
9+
} = formFieldContext;
10+
const {
11+
getProps, theme,
12+
} = useCustomize();
13+
14+
const baseStyles: CSSProperties = {
15+
color: theme.colors.neutral60,
16+
display: "block",
17+
border: "1px solid",
18+
borderColor: theme.colors.neutral20,
19+
padding: 6,
20+
width: "100%",
21+
borderRadius: theme.borderRadius,
22+
gridArea: "control",
23+
boxShadow: theme.boxShadow.input,
24+
fontSize: "0.875rem",
25+
fontFamily: "monospace",
26+
minHeight: "120px",
27+
resize: "vertical",
28+
};
29+
30+
return (
31+
<textarea
32+
id={id}
33+
name={prop.name}
34+
value={value ?? ""}
35+
onChange={(e) => onChange(e.target.value)}
36+
placeholder="SELECT * FROM table_name"
37+
required={!prop.optional}
38+
{...getProps("controlSql", baseStyles, formFieldContext)}
39+
/>
40+
);
41+
}

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";

packages/sdk/src/shared/component.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ export type ConfigurablePropStringArray = BaseConfigurableProp & {
8686
type: "string[]";
8787
secret?: boolean; // TODO is this supported
8888
} & Defaultable<string[]>; // TODO
89+
export type ConfigurablePropSql = BaseConfigurableProp & {
90+
type: "sql";
91+
} & Defaultable<string>;
8992
// | { type: "$.interface.http" } // source only
9093
// | { type: "$.interface.timer" } // source only
9194
// | { type: "$.service.db" }
9295
// | { type: "data_store" }
9396
// | { type: "http_request" }
94-
// | { type: "sql" } -- not in component api docs!
9597
export type ConfigurableProp =
9698
| ConfigurablePropAlert
9799
| ConfigurablePropAny
@@ -101,6 +103,7 @@ export type ConfigurableProp =
101103
| ConfigurablePropObject
102104
| ConfigurablePropString
103105
| ConfigurablePropStringArray
106+
| ConfigurablePropSql
104107
| (BaseConfigurableProp & { type: "$.discord.channel"; });
105108

106109
export type ConfigurableProps = Readonly<ConfigurableProp[]>;
@@ -121,6 +124,8 @@ export type PropValue<T extends ConfigurableProp["type"]> = T extends "alert"
121124
? string
122125
: T extends "string[]"
123126
? string[] // XXX support arrays differently?
127+
: T extends "sql"
128+
? string
124129
: never;
125130

126131
export type ConfiguredProps<T extends ConfigurableProps> = {

0 commit comments

Comments
 (0)