diff --git a/packages/ui-tests/stories/canvas/Aggregate.stories.tsx b/packages/ui-tests/stories/canvas/Aggregate.stories.tsx index 49fd0d0a8..41d1ba3f5 100644 --- a/packages/ui-tests/stories/canvas/Aggregate.stories.tsx +++ b/packages/ui-tests/stories/canvas/Aggregate.stories.tsx @@ -30,6 +30,8 @@ const selectedNode: CanvasNode = { parentNode: undefined, previousNode: undefined, label: 'test', + getId: () => 'aggregate-6839', + getOmitFormFields: () => [], getComponentSchema: () => { return { title: 'aggregate', diff --git a/packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx b/packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx index 330b0d635..3c38d75c9 100644 --- a/packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx +++ b/packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx @@ -33,6 +33,8 @@ const selectedNode: CanvasNode = { parentNode: undefined, previousNode: undefined, label: 'test', + getId: () => 'log-sink-6839', + getOmitFormFields: () => [], getComponentSchema: () => { return { title: 'My Node', @@ -73,6 +75,8 @@ const unknownSelectedNode: CanvasNode = { label: 'test', icon: NodeIconResolver.getIcon(''), } as IVisualizationNodeData, + getId: () => 'test', + getOmitFormFields: () => [], getComponentSchema: () => { return { title: 'My Node', diff --git a/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx b/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx index 8bb85bd44..cb8c9ea38 100644 --- a/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx +++ b/packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx @@ -5,6 +5,7 @@ import { CamelCatalogService, CamelRouteVisualEntity, CatalogKind, + createVisualizationNode, ICamelComponentDefinition, ICamelProcessorDefinition, IKameletDefinition, @@ -26,6 +27,7 @@ import { CanvasForm } from './CanvasForm'; import { CanvasNode } from './canvas.models'; import { CanvasService } from './canvas.service'; import { FormTabsModes } from './canvasformtabs.modes'; +import { ROOT_PATH } from '../../../utils'; describe('CanvasForm', () => { let camelRouteVisualEntity: CamelRouteVisualEntity; @@ -73,17 +75,23 @@ describe('CanvasForm', () => { }); it('should render nothing if no schema is available', () => { + const vizNode = createVisualizationNode('route', { + path: ROOT_PATH, + entity: new CamelRouteVisualEntity(camelRouteJson), + isGroup: true, + processorName: 'route', + }); + const selectedNode: CanvasNode = { id: '1', type: 'node', data: { - vizNode: { - getComponentSchema: () => undefined, - getBaseEntity: () => new CamelRouteVisualEntity(camelRouteJson), - } as unknown as IVisualizationNode, + vizNode, }, }; + jest.spyOn(vizNode, 'getComponentSchema').mockReturnValue(undefined); + const { container } = render( @@ -102,17 +110,23 @@ describe('CanvasForm', () => { definition: null, }; + const vizNode = createVisualizationNode('route', { + path: ROOT_PATH, + entity: new CamelRouteVisualEntity(camelRouteJson), + isGroup: true, + processorName: 'route', + }); + const selectedNode: CanvasNode = { id: '1', type: 'node', data: { - vizNode: { - getComponentSchema: () => visualComponentSchema, - getBaseEntity: () => new CamelRouteVisualEntity(camelRouteJson), - } as unknown as IVisualizationNode, + vizNode, }, }; + jest.spyOn(vizNode, 'getComponentSchema').mockReturnValue(visualComponentSchema); + const { container } = render( @@ -140,6 +154,8 @@ describe('CanvasForm', () => { vizNode: { getComponentSchema: () => visualComponentSchema, getBaseEntity: () => new CamelRouteVisualEntity(camelRouteJson), + getId: () => 'route-8888', + getOmitFields: () => [], } as unknown as IVisualizationNode, }, }; diff --git a/packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx b/packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx index 17274e98e..fbcd9d96a 100644 --- a/packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx +++ b/packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx @@ -32,12 +32,12 @@ export const CanvasForm: FunctionComponent = (props) => { /** Store the flow's initial Id */ useEffect(() => { - flowIdRef.current = props.selectedNode.data?.vizNode?.getBaseEntity()?.getId(); + flowIdRef.current = props.selectedNode.data?.vizNode?.getId(); }, []); const onClose = useCallback(() => { props.onClose?.(); - const newId = props.selectedNode.data?.vizNode?.getBaseEntity()?.getId(); + const newId = props.selectedNode.data?.vizNode?.getId(); if (typeof flowIdRef.current === 'string' && typeof newId === 'string' && flowIdRef.current !== newId) { visualFlowsApi.renameFlow(flowIdRef.current, newId); } diff --git a/packages/ui/src/components/Visualization/Canvas/CanvasFormTabs.tsx b/packages/ui/src/components/Visualization/Canvas/CanvasFormTabs.tsx index 6e712e443..c1e9bcbc5 100644 --- a/packages/ui/src/components/Visualization/Canvas/CanvasFormTabs.tsx +++ b/packages/ui/src/components/Visualization/Canvas/CanvasFormTabs.tsx @@ -21,7 +21,7 @@ export const CanvasFormTabs: FunctionComponent = (props) => const { selectedTab } = useContext(CanvasFormTabsContext); const divRef = useRef(null); const formRef = useRef(null); - const omitFields = useRef(props.selectedNode.data?.vizNode?.getBaseEntity()?.getOmitFormFields() || []); + const omitFields = useRef(props.selectedNode.data?.vizNode?.getOmitFormFields() || []); const visualComponentSchema = useMemo(() => { const answer = props.selectedNode.data?.vizNode?.getComponentSchema(); diff --git a/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteGroup.tsx b/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteGroup.tsx index 5092d7549..10c31727f 100644 --- a/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteGroup.tsx +++ b/packages/ui/src/components/Visualization/Custom/ContextMenu/ItemDeleteGroup.tsx @@ -13,7 +13,7 @@ interface ItemDeleteGroupProps extends PropsWithChildren { export const ItemDeleteGroup: FunctionComponent = (props) => { const entitiesContext = useContext(EntitiesContext); const deleteModalContext = useContext(DeleteModalContext); - const flowId = props.vizNode?.getBaseEntity()?.getId(); + const flowId = props.vizNode?.getId(); const onRemoveGroup = useCallback(async () => { /** Open delete confirm modal, get the confirmation */ diff --git a/packages/ui/src/models/visualization/base-visual-entity.ts b/packages/ui/src/models/visualization/base-visual-entity.ts index 003d61a35..be104d8b5 100644 --- a/packages/ui/src/models/visualization/base-visual-entity.ts +++ b/packages/ui/src/models/visualization/base-visual-entity.ts @@ -72,8 +72,7 @@ export interface IVisualizationNode { expect(node.id).toEqual('test-1234'); }); - it('should return the base visual entity', () => { - const visualEntity = {} as BaseVisualCamelEntity; + it('should return the base entity ID', () => { + const visualEntity = new CamelRouteVisualEntity(camelRouteJson); node = createVisualizationNode('test', { entity: visualEntity }); - expect(node.getBaseEntity()).toEqual(visualEntity); + expect(node.getId()).toEqual('route-8888'); }); it('should return the component schema from the underlying BaseVisualCamelEntity', () => { @@ -34,6 +34,18 @@ describe('VisualizationNode', () => { expect(getComponentSchemaSpy).toHaveBeenCalledWith(node.data.path); }); + it('should delegate getOmitFormFields() to the underlying BaseVisualCamelEntity', () => { + const getOmitFormFieldsSpy = jest.fn(); + const visualEntity = { + getOmitFormFields: getOmitFormFieldsSpy, + } as unknown as BaseVisualCamelEntity; + + node = createVisualizationNode('test', { path: 'test-path', entity: visualEntity }); + node.getOmitFormFields(); + + expect(getOmitFormFieldsSpy).toHaveBeenCalled(); + }); + describe('getNodeLabel', () => { it('should return the label from the underlying BaseVisualCamelEntity', () => { const getNodeLabelSpy = jest.fn().mockReturnValue('test-label'); diff --git a/packages/ui/src/models/visualization/visualization-node.ts b/packages/ui/src/models/visualization/visualization-node.ts index e7ad546fd..5e5de73f8 100644 --- a/packages/ui/src/models/visualization/visualization-node.ts +++ b/packages/ui/src/models/visualization/visualization-node.ts @@ -41,8 +41,8 @@ class VisualizationNode