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): Add title API #1442

Merged
merged 1 commit into from
Sep 17, 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
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 @@ -31,10 +31,10 @@ const selectedNode: CanvasNode = {
previousNode: undefined,
label: 'test',
getId: () => 'aggregate-6839',
getTitle: () => 'Aggregate',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
title: 'aggregate',
schema: {
title: 'Aggregate',
description: 'Aggregates many messages into a single message',
Expand Down
3 changes: 2 additions & 1 deletion packages/ui-tests/stories/canvas/CanvasSideBar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const selectedNode: CanvasNode = {
previousNode: undefined,
label: 'test',
getId: () => 'log-sink-6839',
getTitle: () => 'My Node',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand Down Expand Up @@ -76,6 +76,7 @@ const unknownSelectedNode: CanvasNode = {
icon: NodeIconResolver.getIcon(''),
} as IVisualizationNodeData,
getId: () => 'test',
getTitle: () => 'My Node',
getOmitFormFields: () => [],
getComponentSchema: () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { Meta, StoryFn } from '@storybook/react';

const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand All @@ -37,6 +36,7 @@ const mockNode: CanvasNode = {
type: 'node',
data: {
vizNode: {
getTitle: () => 'My Node',
getComponentSchema: () => visualComponentSchema,
updateModel: (_value: unknown) => {},
} as IVisualizationNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { Meta, StoryFn } from '@storybook/react';

const visualComponentSchema: VisualComponentSchema = {
title: 'My Node',
schema: {
type: 'object',
properties: {
Expand All @@ -39,6 +38,7 @@ const mockNode: CanvasNode = {
type: 'node',
data: {
vizNode: {
getTitle: () => 'My Node',
getComponentSchema: () => visualComponentSchema,
} as IVisualizationNode,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ describe('DataFormatEditor', () => {
CamelCatalogService.setCatalogKey(CatalogKind.Dataformat, catalogsMap.dataformatCatalog);

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

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

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