Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🪟 🎨 Move Add button into the line of Connector Builder key value list fields #20699

Merged
merged 3 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ $border-width: variables.$border-thick;
white-space: nowrap;
}

.dropdown {
.control {
margin-left: auto;
padding: 0 variables.$spacing-xs;
background-color: colors.$white;
min-width: calc(50% - 100px);
}

.content {
Expand Down
14 changes: 11 additions & 3 deletions airbyte-webapp/src/components/GroupControls/GroupControls.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import classNames from "classnames";
import React from "react";

import styles from "./GroupControls.module.scss";

interface GroupControlsProps {
label: React.ReactNode;
dropdown?: React.ReactNode;
control?: React.ReactNode;
controlClassName?: string;
name?: string;
}

const GroupControls: React.FC<React.PropsWithChildren<GroupControlsProps>> = ({ label, dropdown, children, name }) => {
const GroupControls: React.FC<React.PropsWithChildren<GroupControlsProps>> = ({
label,
control,
children,
name,
controlClassName,
}) => {
return (
// This outer div is necessary for .content > :first-child padding to be properly applied in the case of nested GroupControls
<div>
<div className={styles.container}>
<div className={styles.title}>
<div className={styles.label}>{label}</div>
<div className={styles.dropdown}>{dropdown}</div>
<div className={classNames(styles.control, controlClassName)}>{control}</div>
</div>
<div className={styles.content} data-testid={name}>
{children}
Expand Down
19 changes: 19 additions & 0 deletions airbyte-webapp/src/components/GroupControls/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ComponentStory, ComponentMeta } from "@storybook/react";

import { Button } from "components/ui/Button";
import { Card } from "components/ui/Card";

import { FormBlock, FormConditionItem } from "core/form/types";
Expand Down Expand Up @@ -71,3 +72,21 @@ WithContent.args = {
</>
),
};

export const EmptyWithControl = Template.bind({});
EmptyWithControl.args = {
label,
control: <Button variant="secondary">Control</Button>,
};

export const ControlAndContent = Template.bind({});
ControlAndContent.args = {
label,
control: <Button variant="secondary">Control</Button>,
children: (
<>
<SectionContainer>Content part 1</SectionContainer>
<SectionContainer>Content part 2</SectionContainer>
</>
),
};
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@ export const KeyValueListField: React.FC<KeyValueListFieldProps> = ({ path, labe
const [{ value: keyValueList }, , { setValue: setKeyValueList }] = useField<Array<[string, string]>>(path);

return (
<GroupControls label={<ControlLabels label={label} infoTooltipContent={tooltip} />}>
<GroupControls
label={<ControlLabels label={label} infoTooltipContent={tooltip} />}
control={
<Button variant="secondary" onClick={() => setKeyValueList([...keyValueList, ["", ""]])}>
<FormattedMessage id="connectorBuilder.addKeyValue" />
</Button>
}
>
{keyValueList.map((keyValue, keyValueIndex) => (
<KeyValueInput
key={keyValueIndex}
Expand All @@ -64,11 +71,6 @@ export const KeyValueListField: React.FC<KeyValueListFieldProps> = ({ path, labe
}}
/>
))}
<div>
<Button variant="secondary" onClick={() => setKeyValueList([...keyValueList, ["", ""]])}>
<FormattedMessage id="connectorBuilder.addKeyValue" />
</Button>
</div>
</GroupControls>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.dropdown {
min-width: calc(50% - 100px);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isDefined } from "utils/common";

import { useConnectorForm } from "../../connectorFormContext";
import { ConnectorFormValues } from "../../types";
import styles from "./ConditionSection.module.scss";
import { FormSection } from "./FormSection";
import { GroupLabel } from "./GroupLabel";
import { SectionContainer } from "./SectionContainer";
Expand Down Expand Up @@ -67,7 +68,7 @@ export const ConditionSection: React.FC<ConditionSectionProps> = ({ formField, p
<GroupControls
key={`form-field-group-${formField.fieldKey}`}
label={<GroupLabel formField={formField} />}
dropdown={
control={
<DropDown
options={options}
onChange={onOptionChange}
Expand All @@ -77,6 +78,7 @@ export const ConditionSection: React.FC<ConditionSectionProps> = ({ formField, p
error={typeof meta.error === "string" && !!meta.error}
/>
}
controlClassName={styles.dropdown}
>
<FormSection
blocks={formField.conditions[currentlySelectedCondition]}
Expand Down