Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CanvasForm): Use component Title in CanvasForm #1858

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/ui-tests/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const config: StorybookConfig = {
__GIT_DATE: JSON.stringify('1970-01-01T00:00:00Z'),
__KAOTO_VERSION: JSON.stringify(packageJson.version),
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
};
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ describe('Tests for Design page', () => {
cy.checkCodeSpanLine('json-deserialize-action', 0);
cy.checkCodeSpanLine('kafka-source', 0);
cy.checkCodeSpanLine('kafka-sink', 0);
cy.checkCodeSpanLine('source: {}', 1);
cy.checkCodeSpanLine('sink: {}', 1);
cy.checkCodeSpanLine('source: {}', 0);
cy.checkCodeSpanLine('sink: {}', 0);
});

it('In an integration with at least two steps, user can not delete the from step', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-tests/stories/canvas/Aggregate.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const selectedNode: CanvasNode = {
previousNode: undefined,
label: 'test',
getId: () => 'aggregate-6839',
getTitle: () => 'Aggregate',
getNodeTitle: () => 'Aggregate',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const selectedNode: CanvasNode = {
previousNode: undefined,
label: 'test',
getId: () => 'log-sink-6839',
getTitle: () => 'My Node',
getNodeTitle: () => 'My Node',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
Expand Down Expand Up @@ -77,7 +77,7 @@ const unknownSelectedNode: CanvasNode = {
icon: NodeIconResolver.getIcon(''),
} as IVisualizationNodeData,
getId: () => 'test',
getTitle: () => 'My Node',
getNodeTitle: () => 'My Node',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const mockNode: CanvasNode = {
type: 'node',
data: {
vizNode: {
getTitle: () => 'My Node',
getNodeTitle: () => 'My Node',
getComponentSchema: () => visualComponentSchema,
updateModel: (_value: unknown) => {},
} as IVisualizationNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const mockNode: CanvasNode = {
type: 'node',
data: {
vizNode: {
getTitle: () => 'My Node',
getNodeTitle: () => 'My Node',
getComponentSchema: () => visualComponentSchema,
} as IVisualizationNode,
},
Expand Down
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/camel/kamelet-resource.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { set } from 'lodash';
import { TileFilter } from '../../components/Catalog/Catalog.models';
import { setValue } from '../../utils';
import { IKameletDefinition } from '../kamelets-catalog';
import { AddStepMode } from '../visualization/base-visual-entity';
import { CamelComponentFilterService } from '../visualization/flows/support/camel-component-filter.service';
Expand Down Expand Up @@ -61,9 +61,9 @@ export class KameletResource extends CamelKResource implements RouteTemplateBean
* and this way the kamelet definition is updated when the user interacts with
* the CamelRouteVisualEntity.
*/
set(this.resource, 'metadata.name', this.flow.getId());
set(this.resource, 'spec.template.from', this.flow.entityDef.template.from);
set(this.resource, 'spec.template.beans', this.beans?.parent.beans);
setValue(this.resource, 'metadata.name', this.flow.getId());
setValue(this.resource, 'spec.template.from', this.flow.entityDef.template.from);
setValue(this.resource, 'spec.template.beans', this.beans?.parent.beans);
return this.resource as IKameletDefinition;
}

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
Loading
Loading