Skip to content

Commit 009aab7

Browse files
committed
Upgrade to the v2 SDK
Use the new v2 version of the Pipedream SDK in the `connect-react` package. This change involves migrating to the new types mostly, but also runtime changes involving the API calls. The runtime behaviour should not be affected from a user's perspective, except for consumers of the `connect-react` package itself, since some components (e.g. `FrontendClientProvider`) expect their consumers to inject a client instance of the same SDK version. For this reason, this change bumps the **major** version of this package.
1 parent 61d0151 commit 009aab7

25 files changed

+279
-210
lines changed

packages/connect-react/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/connect-react",
3-
"version": "1.6.0",
3+
"version": "2.0.0",
44
"description": "Pipedream Connect library for React",
55
"files": [
66
"dist"
@@ -30,7 +30,7 @@
3030
"author": "Pipedream Engineering",
3131
"license": "MIT",
3232
"dependencies": {
33-
"@pipedream/sdk": "^1.8.0",
33+
"@pipedream/sdk": "^2.0.9",
3434
"@tanstack/react-query": "^5.59.16",
3535
"lodash.isequal": "^4.5.0",
3636
"react-markdown": "^9.0.1",

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import {
2-
FormContextProvider, type FormContext,
3-
} from "../hooks/form-context";
4-
import { DynamicProps } from "../types";
51
import type {
2+
Component,
63
ConfigurableProps,
74
ConfiguredProps,
8-
V1Component,
5+
DynamicProps,
96
} from "@pipedream/sdk";
7+
8+
import {
9+
type FormContext,
10+
FormContextProvider,
11+
} from "../hooks/form-context";
1012
import { InternalComponentForm } from "./InternalComponentForm";
1113

1214
export type ComponentFormProps<T extends ConfigurableProps, U = ConfiguredProps<T>> = {
@@ -18,7 +20,7 @@ export type ComponentFormProps<T extends ConfigurableProps, U = ConfiguredProps<
1820
* @deprecated Use `externalUserId` instead.
1921
*/
2022
userId?: string;
21-
component: V1Component<T>;
23+
component: Component;
2224
configuredProps?: U; // XXX value?
2325
disableQueryDisabling?: boolean;
2426
// dynamicPropsId?: string // XXX need to load this initially when passed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function Control<T extends ConfigurableProps, U extends ConfigurableProp>
3838
return <RemoteOptionsContainer queryEnabled={queryDisabledIdx == null || queryDisabledIdx >= idx} />;
3939
}
4040

41-
if ("options" in prop && prop.options) {
41+
if ("options" in prop && Array.isArray(prop.options) && prop.options.length > 0) {
4242
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4343
const options: LabelValueOption<any>[] = prop.options.map(sanitizeOption);
4444
return <ControlSelect options={options} components={{

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
import { useFormFieldContext } from "../hooks/form-field-context";
2-
import { useCustomize } from "../hooks/customization-context";
1+
import {
2+
ConfiguredPropValueInteger,
3+
ConfiguredPropValueObject,
4+
ConfiguredPropValueString,
5+
ConfiguredPropValueStringArray,
6+
} from "@pipedream/sdk";
37
import type { CSSProperties } from "react";
48

9+
import { useCustomize } from "../hooks/customization-context";
10+
import { useFormFieldContext } from "../hooks/form-field-context";
11+
512
export function ControlAny() {
613
const formFieldContext = useFormFieldContext();
714
const {
@@ -18,7 +25,11 @@ export function ControlAny() {
1825
boxShadow: theme.boxShadow.input,
1926
};
2027

21-
let jsonValue = value;
28+
let jsonValue = value as
29+
| ConfiguredPropValueInteger
30+
| ConfiguredPropValueObject
31+
| ConfiguredPropValueString
32+
| ConfiguredPropValueStringArray;
2233
if (typeof jsonValue === "object") {
2334
jsonValue = JSON.stringify(jsonValue);
2435
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function ControlApp({ app }: ControlAppProps) {
7777
};
7878
const selectProps = select.getProps("controlAppSelect", baseSelectProps);
7979

80-
const oauthAppId = oauthAppConfig?.[app.name_slug];
80+
const oauthAppId = oauthAppConfig?.[app.nameSlug];
8181
const {
8282
isLoading: isLoadingAccounts,
8383
// TODO error
@@ -86,14 +86,12 @@ export function ControlApp({ app }: ControlAppProps) {
8686
} = useAccounts(
8787
{
8888
external_user_id: externalUserId,
89-
app: app.name_slug,
89+
app: app.nameSlug,
9090
oauth_app_id: oauthAppId,
9191
},
9292
{
9393
useQueryOpts: {
9494
enabled: !!app,
95-
96-
// @ts-expect-error this seems to work (this overrides enabled so don't just set to true)
9795
suspense: !!app,
9896
},
9997
},
@@ -161,7 +159,7 @@ export function ControlApp({ app }: ControlAppProps) {
161159
isLoading={isLoadingAccounts}
162160
isClearable={true}
163161
isSearchable={true}
164-
getOptionLabel={(a) => a.name}
162+
getOptionLabel={(a) => a.name ?? ""}
165163
getOptionValue={(a) => a.id}
166164
onChange={(a) => {
167165
if (a) {

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { CSSProperties } from "react";
2+
import type { ConfigurablePropInteger } from "@pipedream/sdk";
23
import { useFormFieldContext } from "../hooks/form-field-context";
34
import { useCustomize } from "../hooks/customization-context";
45

@@ -46,20 +47,23 @@ export function ControlInput() {
4647
autoComplete = "new-password"; // in chrome, this is better than "off" here
4748
}
4849

50+
const min = prop.type === "integer"
51+
? (prop as ConfigurablePropInteger).min
52+
: undefined;
53+
const max = prop.type === "integer"
54+
? (prop as ConfigurablePropInteger).max
55+
: undefined;
56+
4957
return (
5058
<input
5159
id={id}
5260
type={inputType}
5361
name={prop.name}
54-
value={value ?? ""}
62+
value={String(value) ?? ""}
5563
onChange={(e) => onChange(toOnChangeValue(e.target.value))}
5664
{...getProps("controlInput", baseStyles, formFieldContextProps)}
57-
min={"min" in prop
58-
? prop.min
59-
: undefined}
60-
max={"max" in prop
61-
? prop.max
62-
: undefined}
65+
min={min}
66+
max={max}
6367
autoComplete={autoComplete}
6468
data-lpignore="true"
6569
data-1p-ignore="true"

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

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { PropOptionValue } from "@pipedream/sdk";
12
import {
23
useEffect,
34
useMemo,
@@ -22,7 +23,7 @@ import {
2223
import { LoadMoreButton } from "./LoadMoreButton";
2324

2425
// XXX T and ConfigurableProp should be related
25-
type ControlSelectProps<T> = {
26+
type ControlSelectProps<T extends PropOptionValue> = {
2627
isCreatable?: boolean;
2728
options: LabelValueOption<T>[];
2829
selectProps?: ReactSelectProps<LabelValueOption<T>, boolean>;
@@ -31,7 +32,7 @@ type ControlSelectProps<T> = {
3132
components?: ReactSelectProps<LabelValueOption<T>, boolean>["components"];
3233
};
3334

34-
export function ControlSelect<T>({
35+
export function ControlSelect<T extends PropOptionValue>({
3536
isCreatable,
3637
options,
3738
selectProps,
@@ -83,37 +84,30 @@ export function ControlSelect<T>({
8384
return null;
8485
}
8586

86-
let ret = rawValue;
87-
if (Array.isArray(ret)) {
87+
if (Array.isArray(rawValue)) {
8888
// if simple, make lv (XXX combine this with other place this happens)
89-
if (!isOptionWithLabel(ret[0])) {
90-
return ret.map((o) =>
91-
selectOptions.find((item) => item.value === o) || {
92-
label: String(o),
93-
value: o,
94-
});
89+
if (!isOptionWithLabel(rawValue[0])) {
90+
return rawValue.map((o) =>
91+
selectOptions.find((item) => item.value === o) || sanitizeOption(o as T),
92+
);
9593
}
96-
} else if (ret && typeof ret === "object" && "__lv" in ret) {
97-
// Extract the actual option from __lv wrapper
98-
ret = ret.__lv;
99-
} else if (!isOptionWithLabel(ret)) {
94+
} else if (rawValue && typeof rawValue === "object" && "__lv" in (rawValue as Record<string, unknown>)) {
95+
// Extract the actual option from __lv wrapper and sanitize to LV
96+
return sanitizeOption(((rawValue as Record<string, unknown>).__lv) as T);
97+
} else if (!isOptionWithLabel(rawValue)) {
10098
const lvOptions = selectOptions?.[0] && isOptionWithLabel(selectOptions[0]);
10199
if (lvOptions) {
102100
for (const item of selectOptions) {
103101
if (item.value === rawValue) {
104-
ret = item;
105-
break;
102+
return item;
106103
}
107104
}
108105
} else {
109-
ret = {
110-
label: String(rawValue),
111-
value: rawValue,
112-
}
106+
return sanitizeOption(rawValue as T);
113107
}
114108
}
115109

116-
return ret;
110+
return null;
117111
}, [
118112
rawValue,
119113
selectOptions,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function Field<T extends ConfigurableProp>(props: FieldProps<T>) {
4343
const app = "app" in field.extra
4444
? field.extra.app
4545
: undefined;
46-
if (app && !app.auth_type) {
46+
if (app && !app.authType) {
4747
return null;
4848
}
4949

@@ -59,7 +59,7 @@ export function Field<T extends ConfigurableProp>(props: FieldProps<T>) {
5959
// XXX use similar pattern as app below for boolean and checkboxing DOM re-ordering?
6060

6161
return (
62-
<div {...getProps("field", baseStyles, props as FieldProps<ConfigurableProp>)}>
62+
<div {...getProps("field", baseStyles, props)}>
6363
<Label text={labelText} field={field} form={form} />
6464
<Control field={field} form={form} />
6565
<Description markdown={prop.description} field={field} form={form} />

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export function InternalComponentForm() {
5656
type: "alert",
5757
alertType: "error",
5858
content: `# ${e.name}\n${e.message}`,
59+
name: e.name,
5960
} as ConfigurablePropAlert
6061
}))
6162
}
@@ -146,7 +147,7 @@ export function InternalComponentForm() {
146147
idx,
147148
]) => {
148149
if (prop.type === "alert") {
149-
return <Alert key={prop.name} prop={prop} />;
150+
return <Alert key={prop.name} prop={prop as ConfigurablePropAlert} />;
150151
}
151152
return <InternalField key={prop.name} prop={prop} idx={idx} />;
152153
})}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ConfigurableProp } from "@pipedream/sdk";
1+
import type { ConfigurableProp, ConfigurablePropApp } from "@pipedream/sdk";
22
import { FormFieldContext } from "../hooks/form-field-context";
33
import { useFormContext } from "../hooks/form-context";
44
import { Field } from "./Field";
@@ -10,6 +10,10 @@ type FieldInternalProps<T extends ConfigurableProp> = {
1010
idx: number;
1111
};
1212

13+
function isConfigurablePropApp(prop: ConfigurableProp): prop is ConfigurablePropApp {
14+
return prop.type === "app";
15+
}
16+
1317
export function InternalField<T extends ConfigurableProp>({
1418
prop, idx,
1519
}: FieldInternalProps<T>) {
@@ -18,17 +22,16 @@ export function InternalField<T extends ConfigurableProp>({
1822
id: formId, configuredProps, registerField, setConfiguredProp, errors, enableDebugging,
1923
} = formCtx;
2024

21-
const appSlug = prop.type === "app" && "app" in prop
22-
? prop.app
23-
: undefined;
25+
let appSlug: ConfigurablePropApp["app"] | undefined;
26+
if (isConfigurablePropApp(prop)) {
27+
appSlug = prop.app;
28+
}
2429
const {
2530
// TODO error
2631
app,
2732
} = useApp(appSlug || "", {
2833
useQueryOpts: {
2934
enabled: !!appSlug,
30-
31-
// @ts-expect-error this seems to work (this overrides enabled so don't just set to true)
3235
suspense: !!appSlug,
3336
},
3437
});

0 commit comments

Comments
 (0)