fix: Handle null process groups in findProcessGroupByPath

This commit is contained in:
burnettk 2025-02-10 17:29:22 -05:00 committed by burnettk (aider)
parent 57c7829cd4
commit 39c62b9c0e
No known key found for this signature in database

View File

@ -243,7 +243,7 @@ export default function ProcessModelTreePage({
};
function findProcessGroupByPath(
groupsToProcess: ProcessGroup[] | ProcessGroupLite[],
groupsToProcess: ProcessGroup[] | ProcessGroupLite[] | null,
path: string,
): ProcessGroupLite | undefined {
const levels = path.split('/');
@ -256,12 +256,36 @@ export default function ProcessModelTreePage({
} else {
assembledGroups = `${assembledGroups}/${level}`;
}
currentGroup = (
(currentGroup ? currentGroup.process_groups : groupsToProcess) || []
).find(
(processGroup: ProcessGroup | ProcessGroupLite) =>
processGroup.id === assembledGroups,
);
// let newGroups = currentGroup
// ? currentGroup.process_groups
// : groupsToProcess;
// works
// let newGroups = currentGroup ? currentGroup.process_groups : [];
let newGroups: ProcessGroupLite[] | ProcessGroup[] = [];
if (currentGroup && currentGroup.process_groups !== undefined) {
newGroups = currentGroup.process_groups;
} else if (groupsToProcess) {
newGroups = groupsToProcess;
}
// currentGroup
// ? currentGroup.process_groups
// : groupsToProcess;
if (!newGroups) {
newGroups = [];
}
if (newGroups === null) {
newGroups = [];
}
if (newGroups && Array.isArray(newGroups)) {
currentGroup = newGroups.find(
(processGroup: any) => processGroup.id === assembledGroups,
);
}
if (!currentGroup) {
return undefined;
}