|
1 | | -import { FormContext } from "../hooks/form-context" |
2 | | -import { FormFieldContext } from "../hooks/form-field-context" |
3 | | -import { ConfigurableProp } from "@pipedream/sdk" |
| 1 | +import { FormContext } from "../hooks/form-context"; |
| 2 | +import { FormFieldContext } from "../hooks/form-field-context"; |
| 3 | +import { ConfigurableProp } from "@pipedream/sdk"; |
4 | 4 | // import { ControlAny } from "./ControlAny" |
5 | | -import { ControlApp } from "./ControlApp" |
6 | | -import { ControlBoolean } from "./ControlBoolean" |
7 | | -import { ControlInput } from "./ControlInput" |
8 | | -import { ControlSelect } from "./ControlSelect" |
9 | | -import { RemoteOptionsContainer } from "./RemoteOptionsContainer" |
| 5 | +import { ControlApp } from "./ControlApp"; |
| 6 | +import { ControlBoolean } from "./ControlBoolean"; |
| 7 | +import { ControlInput } from "./ControlInput"; |
| 8 | +import { ControlSelect } from "./ControlSelect"; |
| 9 | +import { RemoteOptionsContainer } from "./RemoteOptionsContainer"; |
10 | 10 |
|
11 | 11 | export type ControlProps<T extends ConfigurableProp> = { |
12 | | - field: FormFieldContext<T> |
13 | | - form: FormContext |
14 | | -} |
| 12 | + field: FormFieldContext<T>; |
| 13 | + form: FormContext; |
| 14 | +}; |
15 | 15 |
|
16 | 16 | // TODO for easier Control* overriding, should probably pass more stuff in so they don't need to reach into context? |
17 | 17 | // ... or do we want the API to incentivize just reaching into context? |
18 | 18 | export function Control<T extends ConfigurableProp>(props: ControlProps<T>) { |
19 | | - const { field, form } = props |
20 | | - const { queryDisabledIdx } = form |
21 | | - const { prop, idx } = field |
22 | | - const app = "app" in field.extra ? field.extra.app : undefined |
| 19 | + const { |
| 20 | + field, form, |
| 21 | + } = props; |
| 22 | + const { queryDisabledIdx } = form; |
| 23 | + const { |
| 24 | + prop, idx, |
| 25 | + } = field; |
| 26 | + const app = "app" in field.extra |
| 27 | + ? field.extra.app |
| 28 | + : undefined; |
23 | 29 |
|
24 | 30 | if (prop.remoteOptions || prop.type === "$.discord.channel") { |
25 | | - return <RemoteOptionsContainer queryEnabled={queryDisabledIdx == null || queryDisabledIdx >= idx} /> |
| 31 | + return <RemoteOptionsContainer queryEnabled={queryDisabledIdx == null || queryDisabledIdx >= idx} />; |
26 | 32 | } |
27 | 33 |
|
28 | 34 | if ("options" in prop && prop.options) { |
29 | | - let options = prop.options |
| 35 | + let options = prop.options; |
30 | 36 | if (typeof options[0] !== "object") { |
31 | | - options = options.map((o: unknown) => ({label: o, value: o})) |
| 37 | + options = options.map((o: unknown) => ({ |
| 38 | + label: o, |
| 39 | + value: o, |
| 40 | + })); |
32 | 41 | } |
33 | | - return <ControlSelect options={options} components={{ IndicatorSeparator: () => null }} /> // TODO fix typing issue here! |
| 42 | + return <ControlSelect options={options} components={{ |
| 43 | + IndicatorSeparator: () => null, |
| 44 | + }} />; // TODO fix typing issue here! |
34 | 45 | } |
35 | 46 |
|
36 | 47 | // TODO just look at registry component repo and look for what we should make sure we support |
37 | 48 | // TODO deal with suspense stuff! |
38 | 49 | if (prop.type.endsWith("[][]")) { |
39 | | - throw new Error("Unsupported property type: " + prop.type) |
| 50 | + throw new Error("Unsupported property type: " + prop.type); |
40 | 51 | } |
41 | 52 |
|
42 | 53 | if (prop.type.endsWith("[]")) { |
43 | | - return <ControlSelect isCreatable={true} options={[]} components={{ IndicatorSeparator: () => null }} /> |
| 54 | + return <ControlSelect isCreatable={true} options={[]} components={{ |
| 55 | + IndicatorSeparator: () => null, |
| 56 | + }} />; |
44 | 57 | } |
45 | 58 |
|
46 | 59 | switch (prop.type) { |
47 | | - // problem with this is that it should be the JSON value, but if it is at any point |
48 | | - // not a valid json value, it should just be the string so the value is not lost... so it's just very odd |
49 | | - // without a more stringent JSON builder type component |
50 | | - // case "any": |
51 | | - // return <ControlAny /> |
52 | | - case "app": |
53 | | - return <ControlApp app={app} /> |
54 | | - case "boolean": |
55 | | - return <ControlBoolean /> |
56 | | - case "string": |
57 | | - case "integer": |
58 | | - // XXX split into ControlString, ControlInteger, etc? but want to share autoComplet="off", etc functionality in base one |
59 | | - return <ControlInput /> |
60 | | - default: |
61 | | - // TODO "not supported prop type should bubble up" |
62 | | - throw new Error("Unsupported property type: " + prop.type) |
| 60 | + // problem with this is that it should be the JSON value, but if it is at any point |
| 61 | + // not a valid json value, it should just be the string so the value is not lost... so it's just very odd |
| 62 | + // without a more stringent JSON builder type component |
| 63 | + // case "any": |
| 64 | + // return <ControlAny /> |
| 65 | + case "app": |
| 66 | + return <ControlApp app={app} />; |
| 67 | + case "boolean": |
| 68 | + return <ControlBoolean />; |
| 69 | + case "string": |
| 70 | + case "integer": |
| 71 | + // XXX split into ControlString, ControlInteger, etc? but want to share autoComplet="off", etc functionality in base one |
| 72 | + return <ControlInput />; |
| 73 | + default: |
| 74 | + // TODO "not supported prop type should bubble up" |
| 75 | + throw new Error("Unsupported property type: " + prop.type); |
63 | 76 | } |
64 | 77 | } |
0 commit comments