Skip to content

Commit

Permalink
TEMP: 3rd iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
lordrip committed Jan 17, 2025
1 parent a1085ba commit 8c32011
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const CustomGroupInner: FunctionComponent<ICustomGroup> = observer(({ element, o
);
});

const CustomGroup: React.FunctionComponent<ICustomGroup> = ({ element, ...rest }: ICustomGroup) => {
const CustomGroup: FunctionComponent<ICustomGroup> = ({ element, ...rest }: ICustomGroup) => {
if (!isNode(element)) {
throw new Error('CustomGroup must be used only on Node elements');

Check warning on line 54 in packages/ui/src/components/Visualization/Custom/Group/CustomGroup.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Group/CustomGroup.tsx#L54

Added line #L54 was not covered by tests
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { FunctionComponent, useContext, useRef } from 'react';
import { AddStepMode, IVisualizationNode, NodeToolbarTrigger } from '../../../../models';
import { SettingsContext } from '../../../../providers';
import { LayoutType } from '../../Canvas';
import { StepToolbar } from '../../Canvas/StepToolbar/StepToolbar';
import { CanvasDefaults } from '../../Canvas/canvas.defaults';
import { AddStepIcon } from '../Edge/AddStepIcon';
Expand Down Expand Up @@ -47,7 +48,7 @@ export const CustomGroupExpandedInner: FunctionComponent<CustomGroupProps> = obs
: selected;

Check warning on line 48 in packages/ui/src/components/Visualization/Custom/Group/CustomGroupExpanded.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Group/CustomGroupExpanded.tsx#L48

Added line #L48 was not covered by tests
const shouldShowAddStep =
shouldShowToolbar && vizNode?.getNodeInteraction().canHaveNextStep && vizNode.getNextNode() === undefined;
const isHorizontal = true; //element.getGraph().getLayout() === LayoutType.DagreHorizontal;
const isHorizontal = element.getGraph().getLayout() === LayoutType.DagreHorizontal;

useAnchor((element: Node) => {
return new TargetAnchor(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
useCombineRefs,
useDragNode,
useHover,
useVisualizationController,
withContextMenu,
withDndDrop,
withSelection,
Expand All @@ -33,7 +32,7 @@ import { useEntityContext } from '../../../../hooks/useEntityContext/useEntityCo
import { AddStepMode, IVisualizationNode, NodeToolbarTrigger } from '../../../../models';
import { SettingsContext } from '../../../../providers';
import { CanvasDefaults } from '../../Canvas/canvas.defaults';
import { CanvasNode } from '../../Canvas/canvas.models';
import { CanvasNode, LayoutType } from '../../Canvas/canvas.models';
import { StepToolbar } from '../../Canvas/StepToolbar/StepToolbar';
import { NodeContextMenuFn } from '../ContextMenu/NodeContextMenu';
import { customNodeDropTargetSpec } from '../customComponentUtils';
Expand All @@ -57,7 +56,6 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(

const vizNode: IVisualizationNode | undefined = element.getData()?.vizNode;
const entitiesContext = useEntityContext();
const controller = useVisualizationController();
const settingsAdapter = useContext(SettingsContext);
const label = vizNode?.getNodeLabel(settingsAdapter.getSettings().nodeLabel);
const isDisabled = !!vizNode?.getComponentSchema()?.definition?.disabled;
Expand All @@ -77,7 +75,7 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
: selected;

Check warning on line 75 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L75

Added line #L75 was not covered by tests
const shouldShowAddStep =
shouldShowToolbar && vizNode?.getNodeInteraction().canHaveNextStep && vizNode.getNextNode() === undefined;
const isHorizontal = true; //element.getGraph().getLayout() === LayoutType.DagreHorizontal;
const isHorizontal = element.getGraph().getLayout() === LayoutType.DagreHorizontal;

useAnchor((element: Node) => {
return new TargetAnchor(element);
Expand All @@ -92,9 +90,13 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
> = {
item: { type: '#node#' },
begin: () => {
const graph = controller.getGraph();
// Hide all edges when dragging starts
graph.getEdges().forEach((edge) => edge.setVisible(false));
element

Check warning on line 94 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L94

Added line #L94 was not covered by tests
.getGraph()
.getEdges()
.forEach((edge) => {
edge.setVisible(false);

Check warning on line 98 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L97-L98

Added lines #L97 - L98 were not covered by tests
});
},
canDrag: () => {
if (settingsAdapter.getSettings().experimentalFeatures.enableDragAndDrop) {
Expand All @@ -107,14 +109,21 @@ const CustomNodeInner: FunctionComponent<CustomNodeProps> = observer(
if (monitor.didDrop() && dropResult) {
const draggedNodePath = element.getData().vizNode.data.path;
dropResult.getData()?.vizNode?.moveNodeTo(draggedNodePath);
// Set an empty model to clear the graph
element.getController().fromModel({

Check warning on line 113 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L113

Added line #L113 was not covered by tests
nodes: [],
edges: [],
});
entitiesContext.updateEntitiesFromCamelResource();
} else {
// Show all edges after dropping
controller
element

Check warning on line 120 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L120

Added line #L120 was not covered by tests
.getGraph()
.getEdges()
.forEach((edge) => edge.setVisible(true));
controller.getGraph().layout();
.forEach((edge) => {
edge.setVisible(true);

Check warning on line 124 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L123-L124

Added lines #L123 - L124 were not covered by tests
});
element.getGraph().layout();

Check warning on line 126 in packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ui/src/components/Visualization/Custom/Node/CustomNode.tsx#L126

Added line #L126 was not covered by tests
}
},
};
Expand Down

0 comments on commit 8c32011

Please sign in to comment.