Skip to content

Commit ae87133

Browse files
author
Joe Reuter
committed
add copy stream button
1 parent e931956 commit ae87133

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

airbyte-webapp/src/components/connectorBuilder/Builder/AddStreamButton.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Form, Formik, useField } from "formik";
22
import { useState } from "react";
3+
import React from "react";
34
import { FormattedMessage, useIntl } from "react-intl";
45

56
import { Button } from "components/ui/Button";
@@ -19,39 +20,46 @@ interface AddStreamValues {
1920

2021
interface AddStreamButtonProps {
2122
onAddStream: (addedStreamNum: number) => void;
23+
button?: React.ReactElement;
24+
initialValues?: Partial<BuilderStream>;
2225
}
2326

24-
export const AddStreamButton: React.FC<AddStreamButtonProps> = ({ onAddStream }) => {
27+
export const AddStreamButton: React.FC<AddStreamButtonProps> = ({ onAddStream, button, initialValues }) => {
2528
const { formatMessage } = useIntl();
2629
const [isOpen, setIsOpen] = useState(false);
2730
const [streamsField, , helpers] = useField<BuilderStream[]>("streams");
2831
const numStreams = streamsField.value.length;
2932

33+
const buttonClickHandler = () => {
34+
setIsOpen(true);
35+
};
36+
3037
return (
3138
<>
32-
<Button
33-
className={styles.addButton}
34-
onClick={() => {
35-
setIsOpen(true);
36-
}}
37-
icon={<PlusIcon />}
38-
/>
39+
{button ? (
40+
React.cloneElement(button, {
41+
onClick: buttonClickHandler,
42+
})
43+
) : (
44+
<Button className={styles.addButton} onClick={buttonClickHandler} icon={<PlusIcon />} />
45+
)}
3946
{isOpen && (
4047
<Formik
4148
initialValues={{ streamName: "", urlPath: "" }}
4249
onSubmit={(values: AddStreamValues) => {
4350
helpers.setValue([
4451
...streamsField.value,
4552
{
46-
name: values.streamName,
47-
urlPath: values.urlPath,
4853
fieldPointer: [],
4954
httpMethod: "GET",
5055
requestOptions: {
5156
requestParameters: [],
5257
requestHeaders: [],
5358
requestBody: [],
5459
},
60+
...initialValues,
61+
name: values.streamName,
62+
urlPath: values.urlPath,
5563
},
5664
]);
5765
setIsOpen(false);
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
11
@use "scss/variables";
22
@use "scss/colors";
33

4-
$deleteButtonWidth: 24px;
4+
$controlButtonWidth: 24px;
55

66
.controls {
77
display: flex;
88
justify-content: center;
99
}
1010

11-
.deleteButton {
11+
.controlButton {
1212
border: none;
1313
background-color: transparent;
1414
color: colors.$grey-400;
1515
border-radius: variables.$border-radius-xs;
16-
width: $deleteButtonWidth;
17-
height: $deleteButtonWidth;
16+
width: $controlButtonWidth;
17+
height: $controlButtonWidth;
1818
padding: variables.$spacing-xs;
1919
padding: 0;
2020
cursor: pointer;
2121
transition: variables.$transition;
2222

2323
&:hover {
2424
color: colors.$white;
25+
background-color: colors.$grey-800;
26+
}
27+
}
28+
29+
.deleteButton {
30+
&:hover {
2531
background-color: colors.$red;
2632
}
2733
}

airbyte-webapp/src/components/connectorBuilder/Builder/StreamConfigView.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import { faTrashCan } from "@fortawesome/free-regular-svg-icons";
1+
import { faTrashCan, faCopy } from "@fortawesome/free-regular-svg-icons";
22
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
3+
import classNames from "classnames";
34
import { useField } from "formik";
45
import { useIntl } from "react-intl";
56

67
import { useConfirmationModalService } from "hooks/services/ConfirmationModal";
78
import { BuilderView, useConnectorBuilderState } from "services/connectorBuilder/ConnectorBuilderStateService";
89

910
import { BuilderStream } from "../types";
11+
import { AddStreamButton } from "./AddStreamButton";
1012
import { BuilderCard } from "./BuilderCard";
1113
import { BuilderConfigView } from "./BuilderConfigView";
1214
import { BuilderField } from "./BuilderField";
@@ -49,7 +51,19 @@ export const StreamConfigView: React.FC<StreamConfigViewProps> = ({ streamNum })
4951
{/* Not using intl for the labels and tooltips in this component in order to keep maintainence simple */}
5052
<BuilderTitle path={streamFieldPath("name")} label="Stream Name" size="md" />
5153
<div className={styles.controls}>
52-
<button className={styles.deleteButton} type="button" onClick={handleDelete}>
54+
<AddStreamButton
55+
onAddStream={(addedStreamNum) => {
56+
setSelectedView(addedStreamNum);
57+
setTestStreamIndex(addedStreamNum);
58+
}}
59+
initialValues={field.value[streamNum]}
60+
button={
61+
<button className={styles.controlButton} type="button" onClick={handleDelete}>
62+
<FontAwesomeIcon icon={faCopy} />
63+
</button>
64+
}
65+
/>
66+
<button className={classNames(styles.deleteButton, styles.controlButton)} type="button" onClick={handleDelete}>
5367
<FontAwesomeIcon icon={faTrashCan} />
5468
</button>
5569
</div>

0 commit comments

Comments
 (0)