-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟🎉 Connector builder: Form-encoded and freeform request bodies (#6854)
Co-authored-by: flash1293 <flash1293@users.noreply.github.com> Co-authored-by: Lake Mossman <lake@airbyte.io>
- Loading branch information
1 parent
254b079
commit df81681
Showing
7 changed files
with
291 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
airbyte-webapp/src/components/connectorBuilder/Builder/RequestOptionSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { useIntl } from "react-intl"; | ||
|
||
import { BuilderCard } from "./BuilderCard"; | ||
import { BuilderField } from "./BuilderField"; | ||
import { BuilderOneOf, OneOfOption } from "./BuilderOneOf"; | ||
import { KeyValueListField } from "./KeyValueListField"; | ||
import { useBuilderWatch } from "../types"; | ||
|
||
interface RequestOptionSectionProps { | ||
streamFieldPath: <T extends string>(fieldPath: T) => `streams.${number}.${T}`; | ||
currentStreamIndex: number; | ||
} | ||
export const RequestOptionSection: React.FC<RequestOptionSectionProps> = ({ streamFieldPath, currentStreamIndex }) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
const bodyValue = useBuilderWatch(streamFieldPath("requestOptions.requestBody")); | ||
|
||
const getBodyOptions = (): OneOfOption[] => [ | ||
{ | ||
label: "JSON (key-value pairs)", | ||
typeValue: "json_list", | ||
default: { | ||
values: [], | ||
}, | ||
children: ( | ||
<KeyValueListField | ||
path={streamFieldPath("requestOptions.requestBody.values")} | ||
manifestPath="HttpRequester.properties.request_body_json" | ||
/> | ||
), | ||
}, | ||
{ | ||
label: "Form encoded (key-value pairs)", | ||
typeValue: "form_list", | ||
default: { | ||
values: [], | ||
}, | ||
children: ( | ||
<KeyValueListField | ||
path={streamFieldPath("requestOptions.requestBody.values")} | ||
manifestPath="HttpRequester.properties.request_body_data" | ||
/> | ||
), | ||
}, | ||
{ | ||
label: "JSON (free form)", | ||
typeValue: "json_freeform", | ||
default: { | ||
value: bodyValue.type === "json_list" ? JSON.stringify(Object.fromEntries(bodyValue.values)) : "{}", | ||
}, | ||
children: ( | ||
<BuilderField | ||
type="jsoneditor" | ||
path={streamFieldPath("requestOptions.requestBody.value")} | ||
manifestPath="HttpRequester.properties.request_body_json" | ||
/> | ||
), | ||
}, | ||
]; | ||
|
||
return ( | ||
<BuilderCard | ||
copyConfig={{ | ||
path: "requestOptions", | ||
currentStreamIndex, | ||
copyFromLabel: formatMessage({ id: "connectorBuilder.copyFromRequestOptionsTitle" }), | ||
copyToLabel: formatMessage({ id: "connectorBuilder.copyToRequestOptionsTitle" }), | ||
}} | ||
> | ||
<KeyValueListField | ||
path={streamFieldPath("requestOptions.requestParameters")} | ||
manifestPath="HttpRequester.properties.request_parameters" | ||
/> | ||
<KeyValueListField | ||
path={streamFieldPath("requestOptions.requestHeaders")} | ||
manifestPath="HttpRequester.properties.request_headers" | ||
/> | ||
<BuilderOneOf | ||
path={streamFieldPath("requestOptions.requestBody")} | ||
label="Request body" | ||
options={getBodyOptions()} | ||
/> | ||
</BuilderCard> | ||
); | ||
}; | ||
|
||
RequestOptionSection.displayName = "RequestOptionSection"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.