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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui) Fix nesting logic in properties tab #12151

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
@@ -0,0 +1,87 @@
import { identifyAndAddParentRows } from '../useStructuredProperties';

describe('identifyAndAddParentRows', () => {
it('should not return parent rows when there are none', () => {
const propertyRows = [
{ displayName: 'test1', qualifiedName: 'test1' },
{ displayName: 'test2', qualifiedName: 'test2' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]);
});

it('should not return parent rows when another row starts with the same letters but is a different token', () => {
const propertyRows = [
{ displayName: 'test1', qualifiedName: 'testing.one' },
{ displayName: 'test2', qualifiedName: 'testingAgain.two' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([]);
});

it('should return parent rows properly', () => {
const propertyRows = [
{ displayName: 'test1', qualifiedName: 'testing.one' },
{ displayName: 'test2', qualifiedName: 'testing.two' },
{ displayName: 'test3', qualifiedName: 'testing.three' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
{ displayName: 'testing', qualifiedName: 'testing', childrenCount: 3 },
]);
});

it('should return parent rows properly with multiple layers of nesting', () => {
const propertyRows = [
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.1' },
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.2' },
{ displayName: 'test1', qualifiedName: 'testing.one.two.b' },
{ displayName: 'test1', qualifiedName: 'testing.one.three' },
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
{ displayName: 'test3', qualifiedName: 'testing.three' },
{ displayName: 'test3', qualifiedName: 'testParent' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 },
{ displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 },
{ displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 },
{
displayName: 'testing.one.two.a',
qualifiedName: 'testing.one.two.a',
isParentRow: true,
childrenCount: 2,
},
]);
});

it('should return parent rows properly with multiple layers of nesting regardless of order', () => {
const propertyRows = [
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.1' },
{ displayName: 'test3', qualifiedName: 'testParent' },
{ displayName: 'test1', qualifiedName: 'testing.one.three' },
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
{ displayName: 'test1', qualifiedName: 'testing.one.two.b' },
{ displayName: 'test3', qualifiedName: 'testing.three' },
{ displayName: 'test1', qualifiedName: 'testing.one.two.a.2' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 6 },
{ displayName: 'testing.one', qualifiedName: 'testing.one', isParentRow: true, childrenCount: 4 },
{ displayName: 'testing.one.two', qualifiedName: 'testing.one.two', isParentRow: true, childrenCount: 3 },
{
displayName: 'testing.one.two.a',
qualifiedName: 'testing.one.two.a',
isParentRow: true,
childrenCount: 2,
},
]);
});

it('should return parent rows properly with simpler layers of nesting', () => {
const propertyRows = [
{ displayName: 'test2', qualifiedName: 'testing.two.c.d' },
{ displayName: 'test3', qualifiedName: 'testing.three' },
{ displayName: 'test3', qualifiedName: 'testParent' },
];
expect(identifyAndAddParentRows(propertyRows)).toMatchObject([
{ displayName: 'testing', qualifiedName: 'testing', isParentRow: true, childrenCount: 2 },
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export function identifyAndAddParentRows(rows?: Array<PropertyRow>): Array<Prope
// that would tell us to nest. If the count is not equal, we should nest the child properties.
for (let index = 0; index < substrings.length; index++) {
const token = substrings[index];
const currentCount = qualifiedNames.filter((name) => name.startsWith(token)).length;
const currentCount = qualifiedNames.filter((name) => name.startsWith(`${token}.`)).length;

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

Expand Down
Loading