mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-02-23 14:48:35 +00:00
refactor: Convert ProcessGroup to ProcessGroupLite for type safety.
This commit is contained in:
parent
39c62b9c0e
commit
e6b6de2c44
@ -36,6 +36,22 @@ type OwnProps = {
|
|||||||
processModelAction: ProcessModelAction;
|
processModelAction: ProcessModelAction;
|
||||||
navigateToPage?: boolean;
|
navigateToPage?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a ProcessGroup to a ProcessGroupLite.
|
||||||
|
*/
|
||||||
|
const processGroupToLite = (group: ProcessGroup): ProcessGroupLite => {
|
||||||
|
return {
|
||||||
|
id: group.id,
|
||||||
|
display_name: group.display_name,
|
||||||
|
description: group.description || '', // Ensure description is not undefined
|
||||||
|
process_models: group.process_models,
|
||||||
|
process_groups: group.process_groups
|
||||||
|
? group.process_groups.map(processGroupToLite)
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top level layout and control container for this view,
|
* Top level layout and control container for this view,
|
||||||
* feeds various streams, data and callbacks to children.
|
* feeds various streams, data and callbacks to children.
|
||||||
@ -243,7 +259,7 @@ export default function ProcessModelTreePage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
function findProcessGroupByPath(
|
function findProcessGroupByPath(
|
||||||
groupsToProcess: ProcessGroup[] | ProcessGroupLite[] | null,
|
groupsToProcess: ProcessGroupLite[] | null,
|
||||||
path: string,
|
path: string,
|
||||||
): ProcessGroupLite | undefined {
|
): ProcessGroupLite | undefined {
|
||||||
const levels = path.split('/');
|
const levels = path.split('/');
|
||||||
@ -257,24 +273,13 @@ export default function ProcessModelTreePage({
|
|||||||
assembledGroups = `${assembledGroups}/${level}`;
|
assembledGroups = `${assembledGroups}/${level}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// let newGroups = currentGroup
|
let newGroups: ProcessGroupLite[] = [];
|
||||||
// ? currentGroup.process_groups
|
|
||||||
// : groupsToProcess;
|
|
||||||
|
|
||||||
// works
|
|
||||||
// let newGroups = currentGroup ? currentGroup.process_groups : [];
|
|
||||||
|
|
||||||
let newGroups: ProcessGroupLite[] | ProcessGroup[] = [];
|
|
||||||
if (currentGroup && currentGroup.process_groups !== undefined) {
|
if (currentGroup && currentGroup.process_groups !== undefined) {
|
||||||
newGroups = currentGroup.process_groups;
|
newGroups = currentGroup.process_groups;
|
||||||
} else if (groupsToProcess) {
|
} else if (groupsToProcess) {
|
||||||
newGroups = groupsToProcess;
|
newGroups = groupsToProcess;
|
||||||
}
|
}
|
||||||
|
|
||||||
// currentGroup
|
|
||||||
// ? currentGroup.process_groups
|
|
||||||
// : groupsToProcess;
|
|
||||||
|
|
||||||
if (!newGroups) {
|
if (!newGroups) {
|
||||||
newGroups = [];
|
newGroups = [];
|
||||||
}
|
}
|
||||||
@ -319,18 +324,21 @@ export default function ProcessModelTreePage({
|
|||||||
const unModifiedProcessGroupId = unModifyProcessIdentifierForPathParam(
|
const unModifiedProcessGroupId = unModifyProcessIdentifierForPathParam(
|
||||||
`${params.process_group_id}`,
|
`${params.process_group_id}`,
|
||||||
);
|
);
|
||||||
|
const processGroupsLite: ProcessGroupLite[] = processGroups.map(
|
||||||
|
processGroupToLite,
|
||||||
|
);
|
||||||
const foundProcessGroup = findProcessGroupByPath(
|
const foundProcessGroup = findProcessGroupByPath(
|
||||||
processGroups || [],
|
processGroupsLite,
|
||||||
unModifiedProcessGroupId,
|
unModifiedProcessGroupId,
|
||||||
);
|
);
|
||||||
if (foundProcessGroup) {
|
if (foundProcessGroup) {
|
||||||
setGroups(foundProcessGroup.process_groups || null);
|
setGroups(foundProcessGroup.process_groups || null);
|
||||||
setCrumbs(processCrumbs(foundProcessGroup, flattened));
|
setCrumbs(processCrumbs(foundProcessGroup, flattened));
|
||||||
} else {
|
} else {
|
||||||
setGroups(processGroups);
|
setGroups(processGroupsLite);
|
||||||
setCrumbs([]);
|
setCrumbs([]);
|
||||||
}
|
}
|
||||||
setGroupsExpanded(!!processGroups.length);
|
setGroupsExpanded(!!processGroupsLite.length);
|
||||||
if (setNavElementCallback) {
|
if (setNavElementCallback) {
|
||||||
setNavElementCallback(
|
setNavElementCallback(
|
||||||
<TreePanel
|
<TreePanel
|
||||||
|
Loading…
x
Reference in New Issue
Block a user