Skip to content

Commit

Permalink
Make recreateLayoutOnCollapseChange opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 authored and jenny-s51 committed Mar 25, 2024
1 parent f71f08a commit 6ddbbac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const DemoTaskGroup: React.FunctionComponent<DemoTaskGroupProps> = ({ element, .
collapsedWidth={DEFAULT_TASK_WIDTH}
collapsedHeight={DEFAULT_TASK_HEIGHT}
element={element as Node}
recreateLayoutOnCollapseChange
getEdgeCreationTypes={getEdgeCreationTypes}
{...rest}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ interface PipelinesDefaultGroupProps {
onContextMenu?: (e: React.MouseEvent) => void;
/** Flag indicating that the context menu for the node is currently open */
contextMenuOpen?: boolean;
/** Flag to recreate the layout when the group is expanded/collapsed. Be sure you are registering "pipelineElementFactory" when set to true. */
recreateLayoutOnCollapseChange?: boolean;
/** Function to return types used to re-create edges on a group collapse/expand (should be the same as calls to getEdgesFromNodes) */
getEdgeCreationTypes?: () => {
spacerNodeType?: string,
Expand All @@ -102,7 +104,7 @@ interface PipelinesDefaultGroupProps {
type PipelinesDefaultGroupInnerProps = Omit<PipelinesDefaultGroupProps, 'element'> & { element: Node } & WithSelectionProps;

const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerProps> = observer(
({ className, element, onCollapseChange, getEdgeCreationTypes, ...rest }) => {
({ className, element, onCollapseChange, recreateLayoutOnCollapseChange, getEdgeCreationTypes, ...rest }) => {
const childCount = element.getAllNodeChildren().length;

const handleCollapse = (group: Node, collapsed: boolean): void => {
Expand All @@ -111,25 +113,31 @@ const DefaultTaskGroupInner: React.FunctionComponent<PipelinesDefaultGroupInnerP
}
group.setCollapsed(collapsed);

const controller = group.hasController() && group.getController();
if (controller) {
const model = controller.toModel();
const creationTypes: EdgeCreationTypes = getEdgeCreationTypes ? getEdgeCreationTypes() : {};
if (recreateLayoutOnCollapseChange) {
const controller = group.hasController() && group.getController();
if (controller) {
const model = controller.toModel();
const creationTypes: EdgeCreationTypes = getEdgeCreationTypes ? getEdgeCreationTypes() : {};

const pipelineNodes = model.nodes.filter((n) => n.type !== creationTypes.spacerNodeType).map((n) => ({ ...n, visible: true }));
const spacerNodes = getSpacerNodes(pipelineNodes, creationTypes.spacerNodeType, creationTypes.finallyNodeTypes);
const nodes = [...pipelineNodes, ...spacerNodes];
const edges = getEdgesFromNodes(
pipelineNodes,
creationTypes.spacerNodeType,
creationTypes.edgeType,
creationTypes.edgeType,
creationTypes.finallyNodeTypes,
creationTypes.finallyEdgeType
);
controller.fromModel({nodes, edges}, true);
controller.getGraph().layout();
const pipelineNodes = model.nodes.filter((n) => n.type !== creationTypes.spacerNodeType).map((n) => ({
...n,
visible: true
}));
const spacerNodes = getSpacerNodes(pipelineNodes, creationTypes.spacerNodeType, creationTypes.finallyNodeTypes);
const nodes = [...pipelineNodes, ...spacerNodes];
const edges = getEdgesFromNodes(
pipelineNodes,
creationTypes.spacerNodeType,
creationTypes.edgeType,
creationTypes.edgeType,
creationTypes.finallyNodeTypes,
creationTypes.finallyEdgeType
);
controller.fromModel({nodes, edges}, true);
controller.getGraph().layout();
}
}

onCollapseChange && onCollapseChange(group, collapsed);
};

Expand Down

0 comments on commit 6ddbbac

Please sign in to comment.