Skip to content

Commit 1eb4668

Browse files
authored
Biz/dj 2780 add support for configurationerror in connect react (#15479)
* Fix linter error * Surface configuration and sdk errors * Update pnpm lock * Render SDK errors in an alert * Add getEnvironment to BaseClient * Add isDevelopment flag to context * Set sdk version to 1.3.1 in example app * Update pnpm * Bump sdk version in nextjs app * Json stringify sdk errors * Update sdk version * Handle sdk errors * Cleanup * Cleanup page.tsx * Commit pnpm-lock.yaml * Undo sdk changes * Use enableDebugging flag instead of environment * Update version and README * Cleanup * Update version * Cleanup * Merge pnpm changes * Refactor sdk error handler * Add types file * Refactor Errors.tsx * Always show ConfigurationError
1 parent 85d818c commit 1eb4668

File tree

17 files changed

+285
-160
lines changed

17 files changed

+285
-160
lines changed

packages/connect-react/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<!-- markdownlint-disable MD024 -->
22
# Changelog
33

4+
# [1.0.0-preview.28] - 2025-02-05
5+
6+
- Surface SDK errors in the form
7+
48
# [1.0.0-preview.27] - 2025-01-30
59

610
- Add styling to alerts

packages/connect-react/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ type ComponentFormProps = {
149149
onUpdateConfiguredProps: (v: Record<string, any>) => void;
150150
/** Hide optional props section */
151151
hideOptionalProps: boolean;
152+
/** SDK response payload. Used in conjunction with enableDebugging to
153+
* show errors in the form. */
154+
sdkResponse: unknown[] | unknown | undefined;
155+
/** Whether to show show errors in the form. Requires sdkErrors to be set. */
156+
enableDebugging?: boolean;
152157
};
153158
```
154159

packages/connect-react/examples/nextjs/package-lock.json

Lines changed: 15 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/connect-react/examples/nextjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"@pipedream/connect-react": "file:../..",
10-
"@pipedream/sdk": "^1.1.4",
10+
"@pipedream/sdk": "^1.3.2",
1111
"next": "15.0.3",
1212
"react": "19.0.0-rc-66855b96-20241106",
1313
"react-dom": "19.0.0-rc-66855b96-20241106"

packages/connect-react/examples/nextjs/src/app/page.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { fetchToken } from "./actions";
1010
export default function Home() {
1111
const userId = "my-authed-user-id";
1212
const client = createFrontendClient({
13-
environment: "development",
1413
externalUserId: userId,
1514
tokenCallback: fetchToken,
1615
});
@@ -26,6 +25,11 @@ export default function Home() {
2625
setDynamicPropsId,
2726
] = useState<string | undefined>();
2827

28+
const [
29+
sdkResponse,
30+
setSdkResponse,
31+
] = useState<unknown | undefined>(undefined);
32+
2933
const handleDynamicProps = (dynamicProps: { id: string | undefined }) => {
3034
setDynamicPropsId(dynamicProps.id)
3135
}
@@ -40,14 +44,17 @@ export default function Home() {
4044
configuredProps={configuredProps}
4145
onUpdateDynamicProps={handleDynamicProps}
4246
onUpdateConfiguredProps={setConfiguredProps}
47+
sdkResponse={sdkResponse}
48+
enableDebugging={true}
4349
onSubmit={async () => {
4450
try {
45-
await client.actionRun({
51+
const response = await client.runAction({
4652
userId,
4753
actionId: "slack-send-message",
4854
configuredProps,
4955
dynamicPropsId,
5056
});
57+
setSdkResponse(response)
5158
} catch (error) {
5259
console.error("Action run failed:", error);
5360
}

packages/connect-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/connect-react",
3-
"version": "1.0.0-preview.27",
3+
"version": "1.0.0-preview.28",
44
"description": "Pipedream Connect library for React",
55
"files": [
66
"dist"

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ type AlertProps = {
77

88
export function Alert({ prop }: AlertProps) {
99
const baseStyles = {
10+
width: "100%",
1011
background: "#e2e3e5",
11-
borderRadius: "10px",
12+
borderRadius: "5px",
1213
paddingTop: "2px",
1314
paddingLeft: "10px",
1415
paddingRight: "10px",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export type ComponentFormProps<T extends ConfigurableProps, U = ConfiguredProps<
2020
onUpdateConfiguredProps?: (v: U) => void; // XXX onChange?
2121
onUpdateDynamicProps?: (dp: DynamicProps<T>) => void;
2222
hideOptionalProps?: boolean;
23+
sdkResponse?: unknown | undefined;
24+
enableDebugging?: boolean;
2325
};
2426

2527
export function ComponentForm<T extends ConfigurableProps>(props: ComponentFormProps<T>) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { CSSProperties } from "react";
22
import Markdown from "react-markdown";
3-
import { ConfigurableProp, ConfigurableProps } from "@pipedream/sdk";
3+
import {
4+
ConfigurableProp, ConfigurableProps,
5+
} from "@pipedream/sdk";
46
import { useCustomize } from "../hooks/customization-context";
57
import { FormFieldContext } from "../hooks/form-field-context";
68
import { FormContext } from "../hooks/form-context";
@@ -14,9 +16,6 @@ export type DescriptionProps<T extends ConfigurableProps, U extends Configurable
1416
// XXX should we rename to FieldDescription (so shared prefix + clear we need field context
1517
// eg. cannot be used in OptionalFieldButton, or they need to be set up better)
1618
export function Description<T extends ConfigurableProps, U extends ConfigurableProp>(props: DescriptionProps<T, U>) {
17-
if (!props.field) {
18-
console.log("props", props);
19-
}
2019
const {
2120
field, markdown,
2221
} = props;
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,50 @@
11
import { FormContext } from "../hooks/form-context";
22
import type { FormFieldContext } from "../hooks/form-field-context";
33
import {
4-
ConfigurableProp, ConfigurableProps,
4+
ConfigurableProp, ConfigurablePropAlert, ConfigurableProps,
55
} from "@pipedream/sdk";
6-
import { useCustomize } from "../hooks/customization-context";
7-
import type { CSSProperties } from "react";
6+
import { Alert } from "./Alert";
87

98
export type ErrorsProps<T extends ConfigurableProps, U extends ConfigurableProp> = {
10-
errors: string[];
119
field: FormFieldContext<U>;
1210
form: FormContext<T>;
1311
};
1412

1513
export function Errors<T extends ConfigurableProps, U extends ConfigurableProp>(props: ErrorsProps<T, U>) {
16-
const { errors } = props;
17-
14+
const { field } = props;
1815
const {
19-
getProps, theme,
20-
} = useCustomize();
16+
errors = {}, prop = {}, enableDebugging,
17+
} = field
2118

22-
const baseStyles: CSSProperties = {
23-
color: theme.colors.danger,
24-
gridArea: "errors",
25-
};
19+
if (!enableDebugging) {
20+
return null
21+
}
2622

27-
if (!errors.length) {
28-
return null;
23+
if (!errors[prop.name]) {
24+
return null
2925
}
3026

3127
// TODO depending on type does different shit... we might need async loader around the label, etc.?
3228
// maybe that should just be handled by FormFieldContext instead of container?
29+
30+
const formattedErrors: ConfigurablePropAlert[] = errors[prop.name].map((e) => {
31+
return {
32+
type: "alert",
33+
alertType: "error",
34+
content: e,
35+
}
36+
})
37+
38+
const baseStyles = {
39+
display: "grid",
40+
gridTemplateColumns: "max-content",
41+
}
42+
43+
const FormattedErrors = () => {
44+
return <>{formattedErrors.map((fe, idx: number) => <Alert prop={fe} key={idx}/>)}</>
45+
}
46+
3347
return (
34-
<ul {...getProps("errors", baseStyles, props)}>
35-
{errors.map((msg) => <li key={msg} {...getProps("error", baseStyles, props)}>{msg}</li>)}
36-
</ul>
48+
<div className="pd-errors" style={baseStyles}><FormattedErrors/></div>
3749
);
3850
}

0 commit comments

Comments
 (0)