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

🪟🎨 Clean up connector form form controls #21698

Merged
merged 13 commits into from
Jan 27, 2023
Merged
22 changes: 3 additions & 19 deletions airbyte-webapp/src/components/common/DeleteBlock/DeleteBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { useCallback } from "react";
import React from "react";
import { FormattedMessage } from "react-intl";
import { useNavigate } from "react-router-dom";

import { H5 } from "components/base/Titles";
import { Button } from "components/ui/Button";
import { Card } from "components/ui/Card";

import { useConfirmationModalService } from "hooks/services/ConfirmationModal";
import { useDeleteModal } from "hooks/useDeleteModal";

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

Expand All @@ -16,22 +15,7 @@ interface IProps {
}

export const DeleteBlock: React.FC<IProps> = ({ type, onDelete }) => {
const { openConfirmationModal, closeConfirmationModal } = useConfirmationModalService();
const navigate = useNavigate();

const onDeleteButtonClick = useCallback(() => {
openConfirmationModal({
text: `tables.${type}DeleteModalText`,
title: `tables.${type}DeleteConfirm`,
submitButtonText: "form.delete",
onSubmit: async () => {
await onDelete();
closeConfirmationModal();
navigate("../..");
},
submitButtonDataId: "delete",
});
}, [closeConfirmationModal, onDelete, openConfirmationModal, navigate, type]);
const onDeleteButtonClick = useDeleteModal(type, onDelete);

return (
<Card className={styles.deleteBlock}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useLocalStorage } from "react-use";

import { Button } from "components/ui/Button";
import { Callout } from "components/ui/Callout";
import { FlexContainer, FlexItem } from "components/ui/Flex";
import { Modal, ModalBody } from "components/ui/Modal";
import { NumberBadge } from "components/ui/NumberBadge";
import { Tooltip } from "components/ui/Tooltip";
Expand Down Expand Up @@ -112,13 +113,35 @@ export const ConfigMenu: React.FC<ConfigMenuProps> = ({ className, testInputJson
<ConnectorForm
formType="source"
bodyClassName={styles.formContent}
footerClassName={styles.inputFormModalFooter}
selectedConnectorDefinitionSpecification={connectorDefinitionSpecification}
formValues={{ connectionConfiguration: testInputJson }}
onSubmit={async (values) => {
setTestInputJson(values.connectionConfiguration as StreamReadRequestBodyConfig);
setIsOpen(false);
}}
renderFooter={({ dirty, isSubmitting }) => (
<div className={styles.inputFormModalFooter}>
<FlexContainer>
<FlexItem grow>
<Button
onClick={() => {
setTestInputJson({});
}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the inputs in this ConfigMenu are blank (e.g. first time filling them out, or Reset was clicked to clear them), then you type a value into an input, and click Reset again without saving, it doesn't clear out the value.

I think we need to also clear the formik state here to make that work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, it needs to call resetConnectorForm which is passed in as well, forgot about that.

type="button"
variant="danger"
>
<FormattedMessage id="form.reset" />
</Button>
</FlexItem>
<Button type="button" variant="secondary" onClick={() => setIsOpen(false)}>
<FormattedMessage id="form.cancel" />
</Button>
<Button type="submit" disabled={isSubmitting || !dirty}>
<FormattedMessage id="connectorBuilder.saveInputsForm" />
</Button>
</FlexContainer>
</div>
)}
onCancel={() => {
setIsOpen(false);
}}
Expand Down
23 changes: 23 additions & 0 deletions airbyte-webapp/src/hooks/useDeleteModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useCallback } from "react";
import { useNavigate } from "react-router-dom";

import { useConfirmationModalService } from "./services/ConfirmationModal";

export function useDeleteModal(type: "source" | "destination" | "connection", onDelete: () => Promise<unknown>) {
const { openConfirmationModal, closeConfirmationModal } = useConfirmationModalService();
const navigate = useNavigate();

return useCallback(() => {
openConfirmationModal({
text: `tables.${type}DeleteModalText`,
title: `tables.${type}DeleteConfirm`,
submitButtonText: "form.delete",
onSubmit: async () => {
await onDelete();
closeConfirmationModal();
navigate("../..");
},
submitButtonDataId: "delete",
});
}, [closeConfirmationModal, onDelete, openConfirmationModal, navigate, type]);
}
5 changes: 4 additions & 1 deletion airbyte-webapp/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,12 @@
"form.saveChanges": "Save changes",
"form.openDatepicker": "Open datepicker",
"form.datepickerTimeCaption": "Time (UTC)",
"form.saveChangesAndTest": "Save changes and test",
"form.saveChangesAndTest": "Test and save",
"form.sourceRetest": "Retest source",
"form.destinationRetest": "Retest destination",
"form.test": "Test",
"form.sourceRetestTitle": "Test the source",
"form.destinationRetestTitle": "Test the destination",
"form.discardChanges": "Discard changes",
"form.discardChangesConfirmation": "There are unsaved changes. Are you sure you want to discard your changes?",
"form.every.minutes": "Every {value, plural, one {minute} other {# minutes}}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React, { useEffect } from "react";
import React, { useCallback, useEffect } from "react";
import { FormattedMessage } from "react-intl";

import { DeleteBlock } from "components/common/DeleteBlock";

import { ConnectionConfiguration } from "core/domain/connection";
import { SourceRead, WebBackendConnectionListItem } from "core/request/AirbyteClient";
import { useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import { useFormChangeTrackerService, useUniqueFormId } from "hooks/services/FormChangeTracker";
import { useDeleteSource, useUpdateSource } from "hooks/services/useSourceHook";
import { useDeleteModal } from "hooks/useDeleteModal";
import { useSourceDefinition } from "services/connector/SourceDefinitionService";
import { useGetSourceDefinitionSpecification } from "services/connector/SourceDefinitionSpecificationService";
import { ConnectorCard } from "views/Connector/ConnectorCard";
Expand Down Expand Up @@ -49,10 +48,12 @@ const SourceSettings: React.FC<SourceSettingsProps> = ({ currentSource, connecti
});
};

const onDelete = async () => {
const onDelete = useCallback(async () => {
clearFormChange(formId);
await deleteSource({ connectionsWithSource, source: currentSource });
};
}, [clearFormChange, connectionsWithSource, currentSource, deleteSource, formId]);

const onDeleteClick = useDeleteModal("source", onDelete);

return (
<div className={styles.content}>
Expand All @@ -66,8 +67,8 @@ const SourceSettings: React.FC<SourceSettingsProps> = ({ currentSource, connecti
selectedConnectorDefinitionId={sourceDefinitionSpecification.sourceDefinitionId}
connector={currentSource}
onSubmit={onSubmit}
onDeleteClick={onDeleteClick}
/>
<DeleteBlock type="source" onDelete={onDelete} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from "react";
import React, { useCallback } from "react";
import { FormattedMessage } from "react-intl";
import { useParams } from "react-router-dom";

import { DeleteBlock } from "components/common/DeleteBlock";
import { StepsTypes } from "components/ConnectorBlocks";

import { useTrackPage, PageTrackingCodes } from "hooks/services/Analytics";
import { useFormChangeTrackerService, useUniqueFormId } from "hooks/services/FormChangeTracker";
import { useConnectionList } from "hooks/services/useConnectionHook";
import { useDeleteDestination, useGetDestination, useUpdateDestination } from "hooks/services/useDestinationHook";
import { useDeleteModal } from "hooks/useDeleteModal";
import { useDestinationDefinition } from "services/connector/DestinationDefinitionService";
import { useGetDestinationDefinitionSpecification } from "services/connector/DestinationDefinitionSpecificationService";
import { ConnectorCard } from "views/Connector/ConnectorCard";
Expand Down Expand Up @@ -36,13 +36,15 @@ export const DestinationSettingsPage: React.FC = () => {
});
};

const onDelete = async () => {
const onDelete = useCallback(async () => {
clearFormChange(formId);
await deleteDestination({
connectionsWithDestination,
destination,
});
};
}, [clearFormChange, connectionsWithDestination, deleteDestination, destination, formId]);

const onDeleteClick = useDeleteModal("destination", onDelete);

return (
<div className={styles.content}>
Expand All @@ -56,8 +58,8 @@ export const DestinationSettingsPage: React.FC = () => {
selectedConnectorDefinitionId={destinationSpecification.destinationDefinitionId}
connector={destination}
onSubmit={onSubmitForm}
onDeleteClick={onDeleteClick}
/>
<DeleteBlock type="destination" onDelete={onDelete} />
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
@use "scss/variables";

.cardForm {
padding: 22px 27px 23px 24px;
}

.connectorSelectControl {
margin-bottom: variables.$spacing-xl;
}
Expand All @@ -19,7 +15,3 @@
margin-top: variables.$spacing-md;
margin-left: variables.$spacing-lg;
}

.connectionTestLogs {
margin-top: variables.$spacing-lg;
}
Loading