-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from ricokahler/fix/missing-name
fix: missing name in field, sortable and recursive objects
- Loading branch information
Showing
10 changed files
with
16,175 additions
and
794 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,58 @@ | ||
export function getSelectableFields(fields: Array<any> = []) { | ||
import { SelectableField } from '../column-selector'; | ||
|
||
function getInnerFields( | ||
childFields: any[], | ||
parentPath: string, | ||
currentLevel = 1 | ||
): SelectableField[] { | ||
return childFields.reduce((acc: any, cur: any) => { | ||
const fieldPath = parentPath + '.' + cur.name; | ||
const level = currentLevel + 1; | ||
|
||
const child = { | ||
field: cur, | ||
fieldPath, | ||
title: cur.type.title, | ||
level, | ||
sortable: true, | ||
}; | ||
|
||
if (cur.type?.fields?.length) { | ||
child.sortable = false; | ||
const children = cur.type.fields; | ||
const innerFields = getInnerFields(children, fieldPath, level); | ||
|
||
if (innerFields.length) { | ||
return [...acc, child, ...innerFields]; | ||
} | ||
} | ||
|
||
return [...acc, child]; | ||
}, []); | ||
} | ||
|
||
export function getSelectableFields( | ||
fields: Array<any> = [] | ||
): SelectableField[] { | ||
if (!fields.length) return []; | ||
|
||
return fields.reduce((acc: any, cur: any) => { | ||
const selectable = fields.reduce((acc: any, cur: any) => { | ||
const fieldPath: string = cur.name; | ||
const title: string = cur.type.title; | ||
const fields = [{ field: cur, fieldPath, title, level: 0 }]; | ||
const parent = { field: cur, fieldPath, title, level: 0, sortable: true }; | ||
|
||
if (cur.type?.fields?.length) { | ||
const innerFields = cur.type.fields.map((inner: any) => ({ | ||
field: inner, | ||
fieldPath: fieldPath + '.' + inner.name, | ||
title: inner.type.title, | ||
level: 1, | ||
})); | ||
|
||
fields.push(...innerFields); | ||
parent.sortable = false; | ||
const children = cur.type.fields; | ||
const innerFields = getInnerFields(children, fieldPath, 1); | ||
|
||
if (innerFields.length) { | ||
return [...acc, parent, ...innerFields]; | ||
} | ||
} | ||
|
||
return [...acc, ...fields]; | ||
return [...acc, parent]; | ||
}, []); | ||
|
||
return selectable; | ||
} |
Oops, something went wrong.
1bc11db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: