Skip to content

Commit b5b8897

Browse files
committed
fix: DataMapper: Document node is a duplicate of the header
1 parent c75d271 commit b5b8897

3 files changed

Lines changed: 31 additions & 19 deletions

File tree

packages/ui/src/components/View/SourcePanel.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,34 @@ export const SourcePanel: FunctionComponent<SourcePanelProps> = ({ isReadOnly =
4747
if (!sourceBodyTree) return [];
4848
return sourceBodyTree.flatten(documentExpansionState);
4949
}, [sourceBodyTree, documentExpansionState]);
50+
51+
const hasSchema = !sourceBodyNodeData.isPrimitive;
52+
53+
const visibleNodes = useMemo(() => {
54+
return hasSchema ? flattenedNodes.slice(1) : flattenedNodes;
55+
}, [flattenedNodes, hasSchema]);
5056

5157
// Recalculate connection ports when flattened nodes change (expand/collapse)
5258
useEffect(() => {
5359
syncConnectionPorts();
54-
}, [flattenedNodes.length, syncConnectionPorts]);
60+
}, [visibleNodes.length, syncConnectionPorts]);
5561

5662
const renderSourceItem = useCallback(
5763
(index: number) => {
58-
const flattenedNode = flattenedNodes[index];
64+
const flattenedNode = visibleNodes[index];
5965
return (
6066
<SourceDocumentNodeWithContextMenu
6167
key={flattenedNode.path}
6268
treeNode={flattenedNode.treeNode}
6369
documentId={sourceBodyNodeData.id}
6470
isReadOnly={isReadOnly}
65-
rank={flattenedNode.depth + 1}
71+
rank={hasSchema ? flattenedNode.depth : flattenedNode.depth + 1}
6672
/>
6773
);
6874
},
69-
[flattenedNodes, sourceBodyNodeData.id, isReadOnly],
75+
[hasSchema, sourceBodyNodeData.id, isReadOnly, visibleNodes],
7076
);
7177

72-
// Check if body has schema (similar to parameter logic)
73-
const hasSchema = !sourceBodyNodeData.isPrimitive;
74-
7578
// Edge markers for virtual scroll connection ports
7679
const edgeMarkers = useMemo(
7780
() => [
@@ -121,7 +124,7 @@ export const SourcePanel: FunctionComponent<SourcePanelProps> = ({ isReadOnly =
121124
{/* Only render children if body has schema */}
122125
{hasSchema && sourceBodyTree && (
123126
<Virtuoso
124-
totalCount={flattenedNodes.length}
127+
totalCount={visibleNodes.length}
125128
components={virtuosoComponents}
126129
itemContent={renderSourceItem}
127130
overscan={VIRTUOSO_OVERSCAN}

packages/ui/src/components/View/SourceTargetView.test.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ describe('SourceTargetView', () => {
7474

7575
const shipTo = await screen.findByText('ShipTo');
7676
expect(shipTo).toBeTruthy();
77+
expect(screen.queryByTestId('node-source-doc-sourceBody-Body')).toBeFalsy();
78+
expect(screen.getAllByTestId('detach-schema-sourceBody-Body-button')).toHaveLength(1);
7779
const detachButton = screen.getByTestId('detach-schema-sourceBody-Body-button');
7880
act(() => {
7981
fireEvent.click(detachButton);
@@ -151,9 +153,11 @@ describe('SourceTargetView', () => {
151153

152154
const shipTo = await screen.findByText('ShipTo');
153155
expect(shipTo).toBeTruthy();
154-
const detachButtons = screen.getAllByTestId('detach-schema-targetBody-Body-button');
156+
expect(screen.queryByTestId('node-target-doc-targetBody-Body')).toBeFalsy();
157+
expect(screen.getAllByTestId('detach-schema-targetBody-Body-button')).toHaveLength(1);
158+
const detachButton = screen.getByTestId('detach-schema-targetBody-Body-button');
155159
act(() => {
156-
fireEvent.click(detachButtons[0]);
160+
fireEvent.click(detachButton);
157161
});
158162
const detachConfirmButton = screen.getByTestId('detach-schema-modal-confirm-btn');
159163
act(() => {
@@ -206,8 +210,9 @@ describe('SourceTargetView', () => {
206210

207211
const shipTo = await screen.findByText('map [@key = ShipTo]');
208212
expect(shipTo).toBeTruthy();
209-
const detachButtons = screen.getAllByTestId('detach-schema-targetBody-Body-button');
210-
const detachButton = detachButtons[0];
213+
expect(screen.queryByTestId('node-target-doc-targetBody-Body')).toBeFalsy();
214+
expect(screen.getAllByTestId('detach-schema-targetBody-Body-button')).toHaveLength(1);
215+
const detachButton = screen.getByTestId('detach-schema-targetBody-Body-button');
211216
act(() => {
212217
fireEvent.click(detachButton);
213218
});

packages/ui/src/components/View/TargetPanel.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,17 @@ export const TargetPanel: FunctionComponent = () => {
5050
return targetBodyTree.flatten(documentExpansionState);
5151
}, [targetBodyTree, documentExpansionState]);
5252

53+
const hasSchema = !targetBodyNodeData.isPrimitive;
54+
55+
const visibleNodes = useMemo(() => {
56+
return hasSchema ? flattenedNodes.slice(1) : flattenedNodes;
57+
}, [flattenedNodes, hasSchema]);
58+
5359
// Recalculate connection ports when flattened nodes change (expand/collapse)
5460
// Also sync when mappingTree changes (new mappings added/removed)
5561
useEffect(() => {
5662
syncConnectionPorts();
57-
}, [flattenedNodes.length, mappingTree, syncConnectionPorts]);
58-
59-
const hasSchema = !targetBodyNodeData.isPrimitive;
63+
}, [visibleNodes.length, mappingTree, syncConnectionPorts]);
6064

6165
const handleUpdate = useCallback(() => {
6266
refreshMappingTree();
@@ -91,17 +95,17 @@ export const TargetPanel: FunctionComponent = () => {
9195

9296
const renderTargetItem = useCallback(
9397
(index: number) => {
94-
const flattenedNode = flattenedNodes[index];
98+
const flattenedNode = visibleNodes[index];
9599
return (
96100
<TargetDocumentNodeWithContextMenu
97101
key={flattenedNode.path}
98102
treeNode={flattenedNode.treeNode}
99103
documentId={targetBodyNodeData.id}
100-
rank={flattenedNode.depth + 1}
104+
rank={hasSchema ? flattenedNode.depth : flattenedNode.depth + 1}
101105
/>
102106
);
103107
},
104-
[flattenedNodes, targetBodyNodeData.id],
108+
[hasSchema, targetBodyNodeData.id, visibleNodes],
105109
);
106110

107111
// Actions for target body document
@@ -160,7 +164,7 @@ export const TargetPanel: FunctionComponent = () => {
160164
>
161165
{hasSchema && targetBodyTree && (
162166
<Virtuoso
163-
totalCount={flattenedNodes.length}
167+
totalCount={visibleNodes.length}
164168
components={virtuosoComponents}
165169
itemContent={renderTargetItem}
166170
overscan={VIRTUOSO_OVERSCAN}

0 commit comments

Comments
 (0)