Skip to content

Commit

Permalink
[#55480] Fix Include subprojects return wrong total sum
Browse files Browse the repository at this point in the history
  • Loading branch information
Reza98Sh authored and oliverguenther committed Oct 7, 2024
1 parent 8aa773c commit 54b8303
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
map,
mergeMap,
shareReplay,
switchMap,
take,
} from 'rxjs/operators';

Expand Down Expand Up @@ -158,7 +159,28 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
}),
);

public numberOfProjectsInFilter$ = this.projectsInFilter$.pipe(map((selected) => selected.length));
public numberOfProjectsInFilter$ = this.projectsInFilter$.pipe(
switchMap((selected) => this.projects$.pipe(
map((projects) => {
if (this.includeSubprojects && projects.length > 0) {
const selectedParents = projects.filter((project) => selected.includes(project.href));
const hrefs:string[] = [];
// Function to traverse projects and collect hrefs
const traverse = (nodes:IProjectData[]) => {
nodes.forEach((node) => {
hrefs.push(node.href);
if (node.children && node.children.length > 0) {
traverse(node.children);
}
});
};
traverse(selectedParents);
selected = [...new Set([...selected, ...hrefs])];
}
return selected.length;
}),
)),
);

public projects$ = combineLatest([
this.searchableProjectListService.allProjects$,
Expand Down Expand Up @@ -298,6 +320,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
)
.subscribe((includeSubprojects) => {
this.includeSubprojects = includeSubprojects;
this.searchableProjectListService.loadAllProjects();
});
}

Expand Down

0 comments on commit 54b8303

Please sign in to comment.