Skip to content

Commit

Permalink
feat(CanvasForm): Add title API
Browse files Browse the repository at this point in the history
Currently, there's no mechanism for setting the Canvas Form title per
component.

This commit adds that possibility.
  • Loading branch information
lordrip committed Sep 17, 2024
1 parent 9b7cd80 commit dc3f4a1
Show file tree
Hide file tree
Showing 30 changed files with 599 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('LoadBalancerEditor', () => {
CamelCatalogService.setCatalogKey(CatalogKind.Loadbalancer, loadbalancerCatalog);

const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down Expand Up @@ -54,7 +53,6 @@ describe('LoadBalancerEditor', () => {

it('should render with only the user updated fields', () => {
const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down Expand Up @@ -96,7 +94,6 @@ describe('LoadBalancerEditor', () => {

it('should render with only the Required fields', () => {
const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe('StepExpressionEditor', () => {
CamelCatalogService.setCatalogKey(CatalogKind.Language, languageCatalog);

const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down Expand Up @@ -52,7 +51,6 @@ describe('StepExpressionEditor', () => {

it('should render with only the user updated fields', () => {
const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import { EntitiesContext, EntitiesProvider } from '../../../../providers/entitie
import { camelRouteJson, kameletJson } from '../../../../stubs';
import { getFirstCatalogMap } from '../../../../stubs/test-load-catalog';
import { ROOT_PATH } from '../../../../utils';
import { CanvasForm } from './CanvasForm';
import { CanvasNode } from '../canvas.models';
import { FlowService } from '../flow.service';
import { CanvasForm } from './CanvasForm';

describe('CanvasForm', () => {
let camelRouteVisualEntity: CamelRouteVisualEntity;
Expand Down Expand Up @@ -104,7 +104,6 @@ describe('CanvasForm', () => {

it('should render nothing if no schema and no definition is available', () => {
const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: null as unknown as KaotoSchemaDefinition['schema'],
definition: null,
};
Expand Down Expand Up @@ -137,39 +136,6 @@ describe('CanvasForm', () => {
expect(container).toMatchSnapshot();
});

it('should update the parameters object if null', () => {
const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: null as unknown as KaotoSchemaDefinition['schema'],
definition: {
parameters: null,
},
};

const selectedNode: CanvasNode = {
id: '1',
type: 'node',
data: {
vizNode: {
getComponentSchema: () => visualComponentSchema,
getBaseEntity: () => new CamelRouteVisualEntity(camelRouteJson),
getId: () => 'route-8888',
getOmitFields: () => [],
} as unknown as IVisualizationNode,
},
};

render(
<EntitiesContext.Provider value={null}>
<VisibleFlowsProvider>
<CanvasForm selectedNode={selectedNode} />
</VisibleFlowsProvider>
</EntitiesContext.Provider>,
);

expect(visualComponentSchema.definition.parameters).toEqual({});
});

it("should serialize empty strings `''` as `undefined`", async () => {
const flowId = camelRouteVisualEntity.id;
const dispatchSpy = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Card, CardBody, CardHeader } from '@patternfly/react-core';
import { FunctionComponent, useCallback, useContext, useEffect, useMemo, useRef } from 'react';
import { FunctionComponent, useCallback, useContext, useEffect, useRef } from 'react';
import { VisibleFlowsContext } from '../../../../providers';
import { ErrorBoundary } from '../../../ErrorBoundary';
import { CanvasNode } from '../canvas.models';
Expand All @@ -16,16 +16,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = ({ selectedNode, o
const { visualFlowsApi } = useContext(VisibleFlowsContext)!;
const flowIdRef = useRef<string | undefined>(undefined);
const vizNode = selectedNode.data?.vizNode;

const visualComponentSchema = useMemo(() => {
const answer = vizNode?.getComponentSchema();
// Overriding parameters with an empty object When the parameters property is mistakenly set to null
if (answer?.definition?.parameters === null) {
answer!.definition.parameters = {};
}
return answer;
}, [vizNode]);
const title = visualComponentSchema?.title;
const title = vizNode?.getTitle();

/** Store the flow's initial Id */
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ exports[`CanvasForm should render nothing if no schema and no definition is avai
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
>
My Node
route
</h2>
</div>
<div
Expand Down Expand Up @@ -578,7 +578,9 @@ exports[`CanvasForm should render nothing if no schema is available 1`] = `
data-ouia-component-id="OUIA-Generated-Title-2"
data-ouia-component-type="PF5/Title"
data-ouia-safe="true"
/>
>
route
</h2>
</div>
<div
class="pf-v5-l-grid__item pf-m-1-col"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ exports[`Canvas should render correctly 1`] = `
data-layer-id="groups"
>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
transform="translate(0, 0)"
Expand Down Expand Up @@ -1099,7 +1099,7 @@ exports[`Canvas should render correctly 1`] = `
</g>
</g>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
>
Expand Down Expand Up @@ -1414,7 +1414,7 @@ exports[`Canvas should render correctly with more routes 1`] = `
data-layer-id="groups"
>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
transform="translate(0, 0)"
Expand Down Expand Up @@ -1826,7 +1826,7 @@ exports[`Canvas should render correctly with more routes 1`] = `
</g>
</g>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
>
Expand Down Expand Up @@ -2141,7 +2141,7 @@ exports[`Canvas should render the Catalog button if \`CatalogModalContext\` is p
data-layer-id="groups"
>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
transform="translate(0, 0)"
Expand Down Expand Up @@ -2553,7 +2553,7 @@ exports[`Canvas should render the Catalog button if \`CatalogModalContext\` is p
</g>
</g>
<g
data-id="route-8888-1234"
data-id="route-1234"
data-kind="node"
data-type="group"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child2",
},
],
"data": {
Expand All @@ -61,8 +62,10 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
"previousNode": undefined,
"title": "child1",
},
},
"height": 75,
Expand Down Expand Up @@ -120,6 +123,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child1",
},
[Circular],
],
Expand All @@ -131,8 +135,10 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
"previousNode": undefined,
"title": "child2",
},
},
"height": 75,
Expand Down Expand Up @@ -178,6 +184,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child1",
},
VisualizationNode {
"DISABLED_NODE_INTERACTION": {
Expand All @@ -197,6 +204,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child2",
},
],
"data": {
Expand All @@ -207,6 +215,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a group wi
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "group",
},
},
"group": true,
Expand Down Expand Up @@ -297,6 +306,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "when-leaf",
},
],
"data": {},
Expand All @@ -305,6 +315,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "when",
},
VisualizationNode {
"DISABLED_NODE_INTERACTION": {
Expand Down Expand Up @@ -348,6 +359,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "log",
},
],
"data": {},
Expand All @@ -356,6 +368,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "process",
},
],
"data": {},
Expand All @@ -364,6 +377,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "otherwise",
},
],
"data": {},
Expand All @@ -386,18 +400,22 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a multiple
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": [Circular],
"title": "direct",
},
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": [Circular],
"title": "choice",
},
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": [Circular],
"title": "set-header",
},
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down Expand Up @@ -444,6 +462,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a simple V
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down Expand Up @@ -492,6 +511,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a two-node
"nodeInteraction": undefined,
"parentNode": [Circular],
"previousNode": undefined,
"title": "child",
},
],
"data": {},
Expand All @@ -500,6 +520,7 @@ exports[`FlowService getFlowDiagram should return nodes and edges for a two-node
"nodeInteraction": undefined,
"parentNode": undefined,
"previousNode": undefined,
"title": "node",
},
},
"height": 75,
Expand Down
7 changes: 6 additions & 1 deletion packages/ui/src/models/visualization/base-visual-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ 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;

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

getNodeInteraction(): NodeInteraction;
Expand Down Expand Up @@ -131,7 +137,6 @@ export interface IVisualizationNodeData {
* the name and the schema of the component.
*/
export interface VisualComponentSchema {
title: string;
schema: KaotoSchemaDefinition['schema'];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
definition: any;
Expand Down
Loading

0 comments on commit dc3f4a1

Please sign in to comment.