Skip to content

Commit

Permalink
Adding Default Selects
Browse files Browse the repository at this point in the history
Making select match v2 and v3 versions of this call.
adding retrieveProperties to allow selecting custom properties
  • Loading branch information
bcameron1231 committed Aug 8, 2024
1 parent 75b5592 commit 8ec5391
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 8ec5391

Please sign in to comment.