Skip to content

Commit d35b350

Browse files
authored
🪟 🐛 Fix validation when setting the connection stream cursor or primary key (#18933)
* Update sorted streams memo to make a copy of the stream before sorting Move changedStreams from CatalogTreeBody to CatalogTree so that the order of the changedStreams is based on the correct order * Remove sorting when saving changes. It's no longer needed.
1 parent e0068fc commit d35b350

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
lines changed

airbyte-webapp/src/components/connection/CatalogTree/CatalogTree.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
2828
isLoading,
2929
}) => {
3030
const isNewStreamsTableEnabled = process.env.REACT_APP_NEW_STREAMS_TABLE ?? false;
31-
const { mode } = useConnectionFormService();
31+
const { initialValues, mode } = useConnectionFormService();
3232

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

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

4040
const sortedSchema = useMemo(
41-
() => streams.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
41+
() => [...streams].sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
4242
[streams]
4343
);
4444

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

56+
const changedStreams = useMemo(
57+
() =>
58+
streams.filter((stream, idx) => {
59+
return stream.config?.selected !== initialValues.syncCatalog.streams[idx].config?.selected;
60+
}),
61+
[initialValues.syncCatalog.streams, streams]
62+
);
63+
5664
return (
5765
<BulkEditServiceProvider nodes={streams} update={onStreamsChanged}>
5866
<LoadingBackdrop loading={isLoading}>
@@ -69,7 +77,11 @@ const CatalogTreeComponent: React.FC<React.PropsWithChildren<CatalogTreeProps>>
6977
<BulkHeader />
7078
</>
7179
)}
72-
<CatalogTreeBody streams={filteredStreams} onStreamChanged={onSingleStreamChanged} />
80+
<CatalogTreeBody
81+
streams={filteredStreams}
82+
changedStreams={changedStreams}
83+
onStreamChanged={onSingleStreamChanged}
84+
/>
7385
</LoadingBackdrop>
7486
{isNewStreamsTableEnabled && <BulkEditPanel />}
7587
</BulkEditServiceProvider>

airbyte-webapp/src/components/connection/CatalogTree/CatalogTreeBody.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import { Field, FieldProps, setIn, useFormikContext } from "formik";
1+
import { Field, FieldProps, setIn } from "formik";
22
import React, { useCallback } from "react";
33

44
import { SyncSchemaStream } from "core/domain/catalog";
55
import { AirbyteStreamConfiguration } from "core/request/AirbyteClient";
66
import { useConnectionFormService } from "hooks/services/ConnectionForm/ConnectionFormService";
7-
import { ConnectionFormValues, FormikConnectionFormValues } from "views/Connection/ConnectionForm/formConfig";
7+
import { FormikConnectionFormValues } from "views/Connection/ConnectionForm/formConfig";
88

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

1212
interface CatalogTreeBodyProps {
1313
streams: SyncSchemaStream[];
14+
changedStreams: SyncSchemaStream[];
1415
onStreamChanged: (stream: SyncSchemaStream) => void;
1516
}
1617

17-
export const CatalogTreeBody: React.FC<CatalogTreeBodyProps> = ({ streams, onStreamChanged }) => {
18+
export const CatalogTreeBody: React.FC<CatalogTreeBodyProps> = ({ streams, changedStreams, onStreamChanged }) => {
1819
const { mode } = useConnectionFormService();
1920

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

33-
const { initialValues } = useFormikContext<ConnectionFormValues>();
34-
35-
const changedStreams = streams.filter((stream, idx) => {
36-
return stream.config?.selected !== initialValues.syncCatalog.streams[idx].config?.selected;
37-
});
38-
3934
return (
4035
<div className={styles.container}>
4136
{streams.map((streamNode) => (

airbyte-webapp/src/pages/ConnectionPage/pages/ConnectionItemPage/ConnectionReplicationTab.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { FeatureItem, useFeature } from "hooks/services/Feature";
1818
import { useModalService } from "hooks/services/Modal";
1919
import { useConnectionService, ValuesProps } from "hooks/services/useConnectionHook";
2020
import { useCurrentWorkspaceId } from "services/workspaces/WorkspacesService";
21-
import { equal, naturalComparatorBy } from "utils/objects";
21+
import { equal } from "utils/objects";
2222
import { useConfirmCatalogDiff } from "views/Connection/CatalogDiffModal/useConfirmCatalogDiff";
2323
import EditControls from "views/Connection/ConnectionForm/components/EditControls";
2424
import { ConnectionFormFields } from "views/Connection/ConnectionForm/ConnectionFormFields";
@@ -90,12 +90,8 @@ export const ConnectionReplicationTab: React.FC = () => {
9090
// This could be due to user changes (e.g. in the sync mode) or due to new/removed
9191
// streams due to a "refreshed source schema".
9292
const catalogHasChanged = !equal(
93-
formValues.syncCatalog.streams
94-
.filter((s) => s.config?.selected)
95-
.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? "")),
96-
connection.syncCatalog.streams
97-
.filter((s) => s.config?.selected)
98-
.sort(naturalComparatorBy((syncStream) => syncStream.stream?.name ?? ""))
93+
formValues.syncCatalog.streams.filter((s) => s.config?.selected),
94+
connection.syncCatalog.streams.filter((s) => s.config?.selected)
9995
);
10096

10197
setSubmitError(null);

0 commit comments

Comments
 (0)