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

Adding getAllChildrenAsTree select properties #3106

Merged
merged 1 commit into from
Aug 12, 2024
Merged
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
16 changes: 10 additions & 6 deletions packages/graph/taxonomy/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,14 @@ export class _TermSet extends _GraphInstance<ITermStoreType.Set> {
*
* @returns Array of children for this item
*/
public async getAllChildrenAsTree(): Promise<IOrderedTermInfo[]> {
public async getAllChildrenAsTree(props?: {retrieveProperties?: boolean}): Promise<IOrderedTermInfo[]> {

const visitor = async (source: { children(): Promise<ITermStoreType.Term[]> }, parent: IOrderedTermInfo[]) => {

const children = await source.children();
const visitor = async (source: ITerm | ITermSet, parent: IOrderedTermInfo[]) => {
const children = await source.children.select(...selects)();

for (let i = 0; i < children.length; i++) {

const child = children[i];

const orderedTerm: Partial<IOrderedTermInfo> = {
children: <IOrderedTermInfo[]>[],
defaultLabel: child.labels.find(l => l.isDefault).name,
Expand All @@ -99,9 +97,15 @@ export class _TermSet extends _GraphInstance<ITermStoreType.Set> {
}
};

let selects = ["*"];
if(props?.retrieveProperties){
// graph does not let us wildcard + select properties
selects=["id", "labels", "createdDateTime", "lastModifiedDateTime", "labels", "descriptions", "properties"];
}

const tree: IOrderedTermInfo[] = [];

await visitor(this, tree);
await visitor(<any>this, tree);

return tree;
}
Expand Down