Skip to content

Commit ef1c1df

Browse files
fix(ui) Fix nesting logic in properties tab (#12151)
1 parent d5ab001 commit ef1c1df

File tree

2 files changed

+90
-3
lines changed

2 files changed

+90
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import { identifyAndAddParentRows } from '../useStructuredProperties';
2+
3+
describe('identifyAndAddParentRows', () => {
4+
it('should not return parent rows when there are none', () => {
5+
const propertyRows = [
6+
{ displayName: 'test1', qualifiedName: 'test1' },
7+
{ displayName: 'test2', qualifiedName: 'test2' },
8+
];
9+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]);
10+
});
11+
12+
it('should not return parent rows when another row starts with the same letters but is a different token', () => {
13+
const propertyRows = [
14+
{ displayName: 'test1', qualifiedName: 'testing.one' },
15+
{ displayName: 'test2', qualifiedName: 'testingAgain.two' },
16+
];
17+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]);
18+
});
19+
20+
it('should return parent rows properly', () => {
21+
const propertyRows = [
22+
{ displayName: 'test1', qualifiedName: 'testing.one' },
23+
{ displayName: 'test2', qualifiedName: 'testing.two' },
24+
{ displayName: 'test3', qualifiedName: 'testing.three' },
25+
];
26+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
27+
{ displayName: 'testing', qualifiedName: 'testing', childrenCount: 3 },
28+
]);
29+
});
30+
31+
it('should return parent rows properly with multiple layers of nesting', () => {
32+
const propertyRows = [
33+
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.1' },
34+
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.2' },
35+
{ displayName: 'test1', qualifiedName: 'testing.one.two.b' },
36+
{ displayName: 'test1', qualifiedName: 'testing.one.three' },
37+
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
38+
{ displayName: 'test3', qualifiedName: 'testing.three' },
39+
{ displayName: 'test3', qualifiedName: 'testParent' },
40+
];
41+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
42+
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 },
43+
{ displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 },
44+
{ displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 },
45+
{
46+
displayName: 'testing.one.two.a',
47+
qualifiedName: 'testing.one.two.a',
48+
isParentRow: true,
49+
childrenCount: 2,
50+
},
51+
]);
52+
});
53+
54+
it('should return parent rows properly with multiple layers of nesting regardless of order', () => {
55+
const propertyRows = [
56+
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.1' },
57+
{ displayName: 'test3', qualifiedName: 'testParent' },
58+
{ displayName: 'test1', qualifiedName: 'testing.one.three' },
59+
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
60+
{ displayName: 'test1', qualifiedName: 'testing.one.two.b' },
61+
{ displayName: 'test3', qualifiedName: 'testing.three' },
62+
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.2' },
63+
];
64+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
65+
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 },
66+
{ displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 },
67+
{ displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 },
68+
{
69+
displayName: 'testing.one.two.a',
70+
qualifiedName: 'testing.one.two.a',
71+
isParentRow: true,
72+
childrenCount: 2,
73+
},
74+
]);
75+
});
76+
77+
it('should return parent rows properly with simpler layers of nesting', () => {
78+
const propertyRows = [
79+
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
80+
{ displayName: 'test3', qualifiedName: 'testing.three' },
81+
{ displayName: 'test3', qualifiedName: 'testParent' },
82+
];
83+
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
84+
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 2 },
85+
]);
86+
});
87+
});

datahub-web-react/src/app/entity/shared/tabs/Properties/useStructuredProperties.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ export function identifyAndAddParentRows(rows?: Array<PropertyRow>): Array<Prope
122122
// that would tell us to nest. If the count is not equal, we should nest the child properties.
123123
for (let index = 0; index < substrings.length; index++) {
124124
const token = substrings[index];
125-
const currentCount = qualifiedNames.filter((name) => name.startsWith(token)).length;
125+
const currentCount = qualifiedNames.filter((name) => name.startsWith(`${token}.`)).length;
126126

127-
// If we're at the beginning of the path and there is no nesting, break
128-
if (index === 0 && currentCount === 1) {
127+
// If there's only one child, don't nest it
128+
if (currentCount === 1) {
129129
break;
130130
}
131131

0 commit comments

Comments
 (0)