diff --git a/airbyte-webapp/src/core/domain/catalog/fieldUtil.ts b/airbyte-webapp/src/core/domain/catalog/fieldUtil.ts index f63cb20648a90..cb352d8b266aa 100644 --- a/airbyte-webapp/src/core/domain/catalog/fieldUtil.ts +++ b/airbyte-webapp/src/core/domain/catalog/fieldUtil.ts @@ -34,8 +34,7 @@ const traverseSchemaToField = ( const traverseJsonSchemaProperties = ( jsonSchema: JSONSchema7Definition, key: string, - path: string = key, - depth = 0 + path: string[] = [] ): SyncSchemaField[] => { if (typeof jsonSchema === "boolean") { return []; @@ -45,12 +44,7 @@ const traverseJsonSchemaProperties = ( if (jsonSchema.properties) { fields = Object.entries(jsonSchema.properties) .flatMap(([k, schema]) => - traverseJsonSchemaProperties( - schema, - k, - depth === 0 ? k : `${path}.${k}`, - depth + 1 - ) + traverseJsonSchemaProperties(schema, k, [...path, k]) ) .flat(2); } @@ -58,7 +52,7 @@ const traverseJsonSchemaProperties = ( return [ { cleanedName: key, - name: path, + path, key, fields, type: diff --git a/airbyte-webapp/src/core/domain/catalog/models.ts b/airbyte-webapp/src/core/domain/catalog/models.ts index cb99d68797dda..965b4f3bccc23 100644 --- a/airbyte-webapp/src/core/domain/catalog/models.ts +++ b/airbyte-webapp/src/core/domain/catalog/models.ts @@ -1,8 +1,8 @@ export type SyncSchemaField = { - name: string; cleanedName: string; type: string; key: string; + path: string[]; fields?: SyncSchemaField[]; }; diff --git a/airbyte-webapp/src/views/Connection/CatalogTree/CatalogSection.tsx b/airbyte-webapp/src/views/Connection/CatalogTree/CatalogSection.tsx index e05db1401aaa3..29e6a4989d65d 100644 --- a/airbyte-webapp/src/views/Connection/CatalogTree/CatalogSection.tsx +++ b/airbyte-webapp/src/views/Connection/CatalogTree/CatalogSection.tsx @@ -97,11 +97,6 @@ const CatalogSectionInner: React.FC = ({ [config, updateStreamWithConfig] ); - const pkPaths = useMemo( - () => new Set(config.primaryKey.map((pkPath) => pkPath.join("."))), - [config.primaryKey] - ); - const onPkSelect = useCallback( (pkPath: string[]) => { let newPrimaryKey: string[][]; @@ -163,19 +158,24 @@ const CatalogSectionInner: React.FC = ({ const flattenedFields = useMemo(() => flatten(fields), [fields]); - const primitiveFieldNames = useMemo( - () => - flattenedFields - .filter(SyncSchemaFieldObject.isPrimitive) - .map((field) => field.name), + const primitiveFields = useMemo( + () => flattenedFields.filter(SyncSchemaFieldObject.isPrimitive), [flattenedFields] ); - const selectedCursorPath = config.cursorField.join("."); const configErrors = getIn(errors, `schema.streams[${streamNode.id}].config`); const hasError = configErrors && Object.keys(configErrors).length > 0; const hasChildren = fields && fields.length > 0; + const isCursor = (field: SyncSchemaField): boolean => + equal(config.cursorField, field.path); + + const isPrimaryKey = (field: SyncSchemaField): boolean => { + const existIndex = config.primaryKey.findIndex((p) => equal(p, field.path)); + + return existIndex !== -1; + }; + return (
@@ -187,7 +187,7 @@ const CatalogSectionInner: React.FC = ({ onSelectStream={onSelectStream} onSelectSyncMode={onSelectSyncMode} isRowExpanded={isRowExpanded} - primitiveFields={primitiveFieldNames} + primitiveFields={primitiveFields} pkType={ pkRequired ? (shouldDefinePk ? "required" : "sourceDefined") : null } @@ -211,14 +211,15 @@ const CatalogSectionInner: React.FC = ({ {flattenedFields.map((field) => ( - + ` padding-right: ${({ depth }) => (depth ? depth * 38 : 0)}px; `; -const FieldRowInner: React.FC = (props) => { - const { name: fieldName, onPrimaryKeyChange, onCursorChange } = props; - const handlePkChange = useCallback( - () => onPrimaryKeyChange(fieldName.split(".")), - [fieldName, onPrimaryKeyChange] - ); - - const handleCursorChange = useCallback( - () => onCursorChange(fieldName.split(".")), - [fieldName, onCursorChange] - ); +const FieldRowInner: React.FC = ({ + onPrimaryKeyChange, + onCursorChange, + path, + ...props +}) => { return ( <> @@ -61,7 +57,10 @@ const FieldRowInner: React.FC = (props) => { {props.isPrimaryKeyEnabled && ( - + onPrimaryKeyChange(path)} + /> )} @@ -69,7 +68,7 @@ const FieldRowInner: React.FC = (props) => { onCursorChange(path)} /> )} diff --git a/airbyte-webapp/src/views/Connection/CatalogTree/StreamHeader.tsx b/airbyte-webapp/src/views/Connection/CatalogTree/StreamHeader.tsx index e460cfb13efdd..2eafe3a2945e9 100644 --- a/airbyte-webapp/src/views/Connection/CatalogTree/StreamHeader.tsx +++ b/airbyte-webapp/src/views/Connection/CatalogTree/StreamHeader.tsx @@ -10,6 +10,7 @@ import { SyncSettingsCell } from "./components/SyncSettingsCell"; import { DestinationSyncMode, SyncMode, + SyncSchemaField, SyncSchemaStream, } from "core/domain/catalog"; import { Popout } from "components/base/Popout"; @@ -44,7 +45,7 @@ interface StreamHeaderProps { onSelectSyncMode: (selectedMode: DropDownRow.IDataItem) => void; onSelectStream: () => void; - primitiveFields: string[]; + primitiveFields: SyncSchemaField[]; pkType: null | "required" | "sourceDefined"; onPrimaryKeyChange: (pkPath: string[][]) => void; @@ -89,8 +90,8 @@ export const StreamHeader: React.FC = ({ ); const dropdownFields = primitiveFields.map((field) => ({ - value: field.split("."), - label: field, + value: field.path, + label: field.path.join("."), })); return ( diff --git a/airbyte-webapp/src/views/layout/SideBar/components/ConnectionsIcon.tsx b/airbyte-webapp/src/views/layout/SideBar/components/ConnectionsIcon.tsx index e36c07780a471..6b998dff1cc72 100644 --- a/airbyte-webapp/src/views/layout/SideBar/components/ConnectionsIcon.tsx +++ b/airbyte-webapp/src/views/layout/SideBar/components/ConnectionsIcon.tsx @@ -5,8 +5,8 @@ const ConnectionsIcon = ({ }): JSX.Element => (