Skip to content

Commit

Permalink
feat(CanvasForm): Use component Title in CanvasForm
Browse files Browse the repository at this point in the history
Currently, the component name is being used as the title in the
`CanvasForm`.

This commit uses the corresponding `Title` property if available from
components, eips and kamelets, and the `ID` as a last resort.

fix: KaotoIO#1462
prerequisite of: KaotoIO#1699
  • Loading branch information
lordrip committed Dec 16, 2024
1 parent ae8bfa4 commit 28187ac
Show file tree
Hide file tree
Showing 32 changed files with 197 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { EntitiesContext, EntitiesProvider } from '../../../../providers/entities.provider';
import { camelRouteJson, kameletJson } from '../../../../stubs';
import { getFirstCatalogMap } from '../../../../stubs/test-load-catalog';
import { ROOT_PATH } from '../../../../utils';
import { CanvasNode } from '../canvas.models';
import { FlowService } from '../flow.service';
import { CanvasForm } from './CanvasForm';
Expand Down Expand Up @@ -77,7 +76,7 @@ describe('CanvasForm', () => {

it('should render nothing if no schema is available', () => {
const vizNode = createVisualizationNode('route', {
path: ROOT_PATH,
path: CamelRouteVisualEntity.ROOT_PATH,
entity: new CamelRouteVisualEntity(camelRouteJson),
isGroup: true,
processorName: 'route',
Expand Down Expand Up @@ -113,7 +112,7 @@ describe('CanvasForm', () => {
};

const vizNode = createVisualizationNode('route', {
path: ROOT_PATH,
path: CamelRouteVisualEntity.ROOT_PATH,
entity: new CamelRouteVisualEntity(camelRouteJson),
isGroup: true,
processorName: 'route',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = ({ selectedNode, o
const { visualFlowsApi } = useContext(VisibleFlowsContext)!;
const flowIdRef = useRef<string | undefined>(undefined);
const vizNode = selectedNode.data?.vizNode;
const title = vizNode?.getTitle();
const title = vizNode?.getNodeTitle();

/** Store the flow's initial Id */
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ exports[`CanvasForm should render 1`] = `
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
>
log
Logger
</h2>
</div>
<div
Expand Down Expand Up @@ -305,7 +305,7 @@ exports[`CanvasForm should render nothing if no schema and no definition is avai
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
>
route
Route
</h2>
</div>
<div
Expand Down Expand Up @@ -561,7 +561,7 @@ exports[`CanvasForm should render nothing if no schema is available 1`] = `
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
>
route
Route
</h2>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child2",
},
],
"data": {
Expand All @@ -59,10 +58,8 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
"previousNode": undefined,
"title": "child1",
},
},
"height": 75,
Expand Down Expand Up @@ -118,7 +115,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child1",
},
[Circular],
],
Expand All @@ -129,10 +125,8 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
"previousNode": undefined,
"title": "child2",
},
},
"height": 75,
Expand Down Expand Up @@ -177,7 +171,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child1",
},
VisualizationNode {
"DISABLED_NODE_INTERACTION": {
Expand All @@ -196,7 +189,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child2",
},
],
"data": {
Expand All @@ -206,7 +198,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nextNode": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
},
"group": true,
Expand Down Expand Up @@ -296,15 +287,13 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "when-leaf",
},
],
"data": {},
"id": "when-1234",
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "when",
},
VisualizationNode {
"DISABLED_NODE_INTERACTION": {
Expand Down Expand Up @@ -347,23 +336,20 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "log",
},
],
"data": {},
"id": "process-1234",
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "process",
},
],
"data": {},
"id": "otherwise-1234",
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "otherwise",
},
],
"data": {},
Expand All @@ -385,19 +371,15 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nextNode": undefined,
"parentNode": undefined,
"previousNode": [Circular],
"title": "direct",
},
"parentNode": undefined,
"previousNode": [Circular],
"title": "choice",
},
"parentNode": undefined,
"previousNode": [Circular],
"title": "set-header",
},
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down Expand Up @@ -443,7 +425,6 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a simple V
"nextNode": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down Expand Up @@ -491,15 +472,13 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a two-node
"nextNode": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child",
},
],
"data": {},
"id": "node-1234",
"nextNode": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ describe('FlowsList.tsx', () => {
});

expect(mockDeleteModalContext.actionConfirmation).toHaveBeenCalledWith({
title: "Do you want to delete the 'route-1234' route?",
title: "Do you want to delete the 'route-1234' Route?",
text: 'All steps will be lost.',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const FlowsList: FunctionComponent<IFlowsList> = (props) => {
"Do you want to delete the '" +
flow.toVizNode().getId() +
"' " +
flow.toVizNode().getTitle() +
flow.toVizNode().getNodeTitle() +
'?',
text: 'All steps will be lost.',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('ItemDeleteGroup', () => {
fireEvent.click(wrapper.getByText('Delete'));

expect(mockDeleteModalContext.actionConfirmation).toHaveBeenCalledWith({
title: "Do you want to delete the 'undefined' test?",
title: "Do you want to delete the 'undefined' test-1234?",
text: 'All steps will be lost.',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useDeleteGroup = (vizNode: IVisualizationNode) => {
const buttonOptions = modalCustoms.length > 0 ? modalCustoms[0].buttonOptions : undefined;
/** Open delete confirm modal, get the confirmation */
const modalAnswer = await deleteModalContext?.actionConfirmation({
title: "Do you want to delete the '" + vizNode.getId() + "' " + vizNode.getTitle() + '?',
title: "Do you want to delete the '" + vizNode.getId() + "' " + vizNode.getNodeTitle() + '?',
text: 'All steps will be lost.',
additionalModalText,
buttonOptions,
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/models/visualization/base-visual-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export interface BaseVisualCamelEntity extends BaseCamelEntity {
/** Given a path, get the component label */
getNodeLabel: (path?: string, labelType?: NodeLabelType) => string;

/** Given a path, get the component title from the catalog */
getNodeTitle: (path?: string) => string;

/** Given a path, get the component tooltip content */
getTooltipContent: (path?: string) => string;

Expand Down Expand Up @@ -83,11 +86,8 @@ export interface IVisualizationNode<T extends IVisualizationNodeData = IVisualiz
/** This method returns the tooltip content to be used by the canvas nodes */
getTooltipContent(): string;

/** This method set the title used by the CanvasForm component */
setTitle(title: string): void;

/** This method returns the title used by the CanvasForm component */
getTitle(): string;
getNodeTitle(): string;

addBaseEntityStep(definedComponent: DefinedComponent, mode: AddStepMode, targetProperty?: string): void;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ exports[`Pipe getNodeInteraction should return the correct interaction for the '
{
"canBeDisabled": false,
"canHaveChildren": false,
"canHaveNextStep": false,
"canHavePreviousStep": false,
"canHaveNextStep": true,
"canHavePreviousStep": true,
"canHaveSpecialChildren": false,
"canRemoveFlow": true,
"canRemoveStep": false,
"canReplaceStep": false,
"canRemoveFlow": false,
"canRemoveStep": true,
"canReplaceStep": true,
}
`;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProcessorDefinition } from '@kaoto/camel-catalog/types';
import { SchemaService } from '../../../components/Form/schema.service';
import { getArrayProperty, getValue, setValue } from '../../../utils';
import { camelCaseToSpaces, getArrayProperty, getValue, setValue } from '../../../utils';
import { NodeIconResolver, NodeIconType } from '../../../utils/node-icon-resolver';
import { DefinedComponent } from '../../camel-catalog-index';
import { EntityType } from '../../camel/entities';
Expand Down Expand Up @@ -56,6 +56,21 @@ export abstract class AbstractCamelVisualEntity<T extends object> implements Bas
return label;
}

getNodeTitle(path?: string): string {
if (!path) return '';
if (path === this.getRootPath()) {
return camelCaseToSpaces(this.getRootPath(), { capitalize: true });
}

const componentModel = getValue(this.entityDef, path);

const title = CamelComponentSchemaService.getNodeTitle(
CamelComponentSchemaService.getCamelComponentLookup(path, componentModel),
);

return title;
}

getTooltipContent(path?: string): string {
if (!path) return '';
const componentModel = getValue(this.entityDef, path);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('CamelErrorHandlerVisualEntity', () => {
const entity = new CamelErrorHandlerVisualEntity(errorHandlerDef);
const vizNode = entity.toVizNode();

expect(vizNode.getTitle()).toEqual('Error Handler');
expect(vizNode.getNodeTitle()).toEqual('Error Handler');
});

it('should serialize the errorHandler definition', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
return errorHandlerId;
}

getNodeTitle(): string {
return 'Error Handler';
}

getTooltipContent(): string {
return 'errorHandler';
}
Expand Down Expand Up @@ -139,7 +143,6 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
errorHandlerGroupNode.data.entity = this;
errorHandlerGroupNode.data.isGroup = true;
errorHandlerGroupNode.data.icon = NodeIconResolver.getIcon(this.type, NodeIconType.VisualEntity);
errorHandlerGroupNode.setTitle('Error Handler');

return errorHandlerGroupNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('CamelRestConfigurationVisualEntity', () => {
const entity = new CamelRestConfigurationVisualEntity(restConfigurationDef);
const vizNode = entity.toVizNode();

expect(vizNode.getTitle()).toEqual('Rest Configuration');
expect(vizNode.getNodeTitle()).toEqual('Rest Configuration');
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export class CamelRestConfigurationVisualEntity implements BaseVisualCamelEntity
return 'restConfiguration';
}

getNodeTitle(): string {
return 'Rest Configuration';
}

getTooltipContent(): string {
return 'restConfiguration';
}
Expand Down Expand Up @@ -131,7 +135,6 @@ export class CamelRestConfigurationVisualEntity implements BaseVisualCamelEntity
restConfigurationGroupNode.data.entity = this;
restConfigurationGroupNode.data.isGroup = true;
restConfigurationGroupNode.data.icon = NodeIconResolver.getIcon(this.type, NodeIconType.VisualEntity);
restConfigurationGroupNode.setTitle('Rest Configuration');

return restConfigurationGroupNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ describe('CamelRouteConfigurationVisualEntity', () => {
const entity = new CamelRouteConfigurationVisualEntity(routeConfigurationDef);
const vizNode = entity.toVizNode();

expect(vizNode.getTitle()).toEqual('Route Configuration');
expect(vizNode.getNodeTitle()).toEqual('Route Configuration');
});
});

Expand Down
Loading

0 comments on commit 28187ac

Please sign in to comment.