Skip to content

Commit

Permalink
Merge pull request #3106 from bcameron1231/fix/3083
Browse files Browse the repository at this point in the history
Adding getAllChildrenAsTree select properties
  • Loading branch information
juliemturner authored Aug 12, 2024
2 parents 3b7cc83 + 8ec5391 commit 8b886d6
Showing 1 changed file with 10 additions and 6 deletions.
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

0 comments on commit 8b886d6

Please sign in to comment.