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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃獰 馃悰 Fix validation when setting the connection stream cursor or primary key #18933

Merged
merged 2 commits into from
Nov 4, 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 @@ -28,7 +28,7 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
isLoading,
}) => {
const isNewStreamsTableEnabled = process.env.REACT_APP_NEW_STREAMS_TABLE ?? false;
const { mode } = useConnectionFormService();
const { initialValues, mode } = useConnectionFormService();

const [searchString, setSearchString] = useState("");

Expand All @@ -38,7 +38,7 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
);

const sortedSchema = useMemo(
() => streams.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
() => [...streams].sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
[streams]
);

Expand All @@ -53,6 +53,14 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
return sortedSchema.filter((stream) => filters.every((f) => f(stream)));
}, [searchString, sortedSchema]);

const changedStreams = useMemo(
() =>
streams.filter((stream, idx) => {
return stream.config?.selected !== initialValues.syncCatalog.streams[idx].config?.selected;
}),
[initialValues.syncCatalog.streams, streams]
);

return (
<BulkEditServiceProvider nodes={streams} update={onStreamsChanged}>
<LoadingBackdrop loading={isLoading}>
Expand All @@ -69,7 +77,11 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
<BulkHeader />
</>
)}
<CatalogTreeBody streams={filteredStreams} onStreamChanged={onSingleStreamChanged} />
<CatalogTreeBody
streams={filteredStreams}
changedStreams={changedStreams}
onStreamChanged={onSingleStreamChanged}
/>
</LoadingBackdrop>
{isNewStreamsTableEnabled && <BulkEditPanel />}
</BulkEditServiceProvider>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Field, FieldProps, setIn, useFormikContext } from "formik";
import { Field, FieldProps, setIn } from "formik";
import React, { useCallback } from "react";

import { SyncSchemaStream } from "core/domain/catalog";
import { AirbyteStreamConfiguration } from "core/request/AirbyteClient";
import { useConnectionFormService } from "hooks/services/ConnectionForm/ConnectionFormService";
import { ConnectionFormValues, FormikConnectionFormValues } from "views/Connection/ConnectionForm/formConfig";
import { FormikConnectionFormValues } from "views/Connection/ConnectionForm/formConfig";

import { CatalogSection } from "./CatalogSection";
import styles from "./CatalogTreeBody.module.scss";

interface CatalogTreeBodyProps {
streams: SyncSchemaStream[];
changedStreams: SyncSchemaStream[];
onStreamChanged: (stream: SyncSchemaStream) => void;
}

export const CatalogTreeBody: React.FC<CatalogTreeBodyProps> = ({ streams, onStreamChanged }) => {
export const CatalogTreeBody: React.FC<CatalogTreeBodyProps> = ({ streams, changedStreams, onStreamChanged }) => {
const { mode } = useConnectionFormService();

const onUpdateStream = useCallback(
Expand All @@ -30,12 +31,6 @@ export const CatalogTreeBody: React.FC<CatalogTreeBodyProps> = ({ streams, onStr
[streams, onStreamChanged]
);

const { initialValues } = useFormikContext<ConnectionFormValues>();

const changedStreams = streams.filter((stream, idx) => {
return stream.config?.selected !== initialValues.syncCatalog.streams[idx].config?.selected;
});

return (
<div className={styles.container}>
{streams.map((streamNode) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { FeatureItem, useFeature } from "hooks/services/Feature";
import { useModalService } from "hooks/services/Modal";
import { useConnectionService, ValuesProps } from "hooks/services/useConnectionHook";
import { useCurrentWorkspaceId } from "services/workspaces/WorkspacesService";
import { equal, naturalComparatorBy } from "utils/objects";
import { equal } from "utils/objects";
import { useConfirmCatalogDiff } from "views/Connection/CatalogDiffModal/useConfirmCatalogDiff";
import EditControls from "views/Connection/ConnectionForm/components/EditControls";
import { ConnectionFormFields } from "views/Connection/ConnectionForm/ConnectionFormFields";
Expand Down Expand Up @@ -90,12 +90,8 @@ export const ConnectionReplicationTab: React.FC = () => {
// This could be due to user changes (e.g. in the sync mode) or due to new/removed
// streams due to a "refreshed source schema".
const catalogHasChanged = !equal(
formValues.syncCatalog.streams
.filter((s) => s.config?.selected)
.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
connection.syncCatalog.streams
.filter((s) => s.config?.selected)
.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? ""))
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand why these no longer need the sort. The only place I see us sorting now is the catalogTree. Isn't there still a chance that the order is not preserved between the connection object and the form values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why this was sorted in the first place was that the formValues data was getting mutated by the sort call in the CatalogTree component. The formValues now contain same stream order as received in the connection object, and the order should match.

formValues.syncCatalog.streams.filter((s) => s.config?.selected),
connection.syncCatalog.streams.filter((s) => s.config?.selected)
);

setSubmitError(null);
Expand Down