Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Allow for proper nesting for getting data for lists and grids #671

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
27 changes: 27 additions & 0 deletions src/modules/list/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ describe('list helpers', () => {
expect(result).toBeNull();
});

it('returns property when selector is a nested selector', () => {
let data: any = {
myResults: { nestedValue: 'expected'},
otherResult: 'nothing'
};
let result = getData(data, 'myResults.nestedValue');
expect(result).toBe('expected');
});

it('returns property when selector is a nested selector that does not exits', () => {
let data: any = {
myResults: {},
otherResult: 'nothing'
};
let result = getData(data, 'myResults.nestedValue');
expect(result).toBeNull();
});

it('returns property when selector is a nested selector that is undefined', () => {
let data: any = {
myResults: { nestedValue: undefined },
otherResult: 'nothing'
};
let result = getData(data, 'myResults.nestedValue');
expect(result).toBeNull();
});

it('returns null when empty string selector defined', () => {
let data = {
myResult: 'something',
Expand Down
6 changes: 2 additions & 4 deletions src/modules/list/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ export function getData(item: any, selector: string): any {
if (resultFieldParts.length > 0) {
for (let index = 0; index < resultFieldParts.length; index++) {
let part = resultFieldParts[index];
if (result[part] === undefined) {
break;
}
/* tslint:disable */
else if (result[part] === null) {
/* istanbul ignore else */
if (result[part] === null || result[part] === undefined) {
result = null;
break;
}
Expand Down