Skip to content

Commit

Permalink
fix(ui) Fix nesting logic in properties tab (#12151)
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscollins3456 authored Dec 17, 2024
1 parent d5ab001 commit ef1c1df
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
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

0 comments on commit ef1c1df

Please sign in to comment.