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(canvas): Add root containers for Camel Routes #768

Merged
merged 1 commit into from
Feb 6, 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
14 changes: 13 additions & 1 deletion packages/ui/src/components/Form/schema.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,21 @@ import { filterDOMProps, FilterDOMPropsKeys } from 'uniforms';
import { JSONSchemaBridge } from 'uniforms-bridge-json-schema';

export class SchemaService {
static readonly DROPDOWN_PLACEHOLDER = 'Select an option...';
static readonly OMIT_FORM_FIELDS = [
'from',
'expression',
'dataFormatType',
'outputs',
'steps',
'when',
'otherwise',
'doCatch',
'doFinally',
'uri',
];
private readonly ajv: Ajv;
private readonly FILTER_DOM_PROPS = ['$comment', 'additionalProperties'];
static readonly DROPDOWN_PLACEHOLDER = 'Select an option...';

constructor() {
this.ajv = new Ajv({
Expand Down
27 changes: 17 additions & 10 deletions packages/ui/src/components/Visualization/Canvas/CanvasForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { act } from 'react-dom/test-utils';
import { RouteDefinition } from '@kaoto-next/camel-catalog/types';

describe('CanvasForm', () => {
const omitFields = ['expression', 'dataFormatType', 'outputs', 'steps', 'when', 'otherwise', 'doCatch', 'doFinally'];
const schemaService = new SchemaService();

const schema = {
Expand Down Expand Up @@ -179,11 +178,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const setHeaderNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: setHeaderNode,
},
};

Expand Down Expand Up @@ -242,11 +242,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const setHeaderNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: setHeaderNode,
},
};

Expand Down Expand Up @@ -306,11 +307,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const marshalNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: marshalNode,
},
};

Expand Down Expand Up @@ -339,6 +341,7 @@ describe('CanvasForm', () => {
expect(camelRoute.from.steps[0].marshal!.avro).toBeDefined();
expect(camelRoute.from.steps[0].marshal!.id).toEqual('modified');
});

it('main form => dataformat', async () => {
const camelRoute = {
from: {
Expand All @@ -354,11 +357,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const marshalNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: marshalNode,
},
};

Expand Down Expand Up @@ -405,11 +409,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const loadBalanceNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: loadBalanceNode,
},
};

Expand Down Expand Up @@ -438,6 +443,7 @@ describe('CanvasForm', () => {
expect(camelRoute.from.steps[0].loadBalance!.weighted).toBeDefined();
expect(camelRoute.from.steps[0].loadBalance!.id).toEqual('modified');
});

it('main form => loadbalancer', async () => {
const camelRoute = {
from: {
Expand All @@ -453,11 +459,12 @@ describe('CanvasForm', () => {
} as RouteDefinition;
const entity = new CamelRouteVisualEntity(camelRoute);
const rootNode: IVisualizationNode = entity.toVizNode();
const loadBalanceNode = rootNode.getChildren()![0].getChildren()![0];
const selectedNode = {
id: '1',
type: 'node',
data: {
vizNode: rootNode.getChildren()![0],
vizNode: loadBalanceNode,
},
};

Expand Down Expand Up @@ -503,7 +510,7 @@ describe('CanvasForm', () => {
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={schema!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={omitFields} />
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
Expand All @@ -526,7 +533,7 @@ describe('CanvasForm', () => {
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={bridge!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={omitFields} />
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
Expand All @@ -549,7 +556,7 @@ describe('CanvasForm', () => {
render(
<AutoField.componentDetectorContext.Provider value={CustomAutoFieldDetector}>
<AutoForm schema={bridge!} model={{}} onChangeModel={() => {}}>
<AutoFields omitFields={omitFields} />
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
</AutoForm>
</AutoField.componentDetectorContext.Provider>,
);
Expand Down
15 changes: 1 addition & 14 deletions packages/ui/src/components/Visualization/Canvas/CanvasForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,6 @@ interface CanvasFormProps {
selectedNode: CanvasNode;
}

const omitFields = [
'from',
'expression',
'dataFormatType',
'outputs',
'steps',
'when',
'otherwise',
'doCatch',
'doFinally',
'uri',
];

export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
const entitiesContext = useContext(EntitiesContext);
const formRef = useRef<typeof AutoForm>();
Expand Down Expand Up @@ -103,7 +90,7 @@ export const CanvasForm: FunctionComponent<CanvasFormProps> = (props) => {
onChange={handleOnChangeIndividualProp}
data-testid="autoform"
>
<AutoFields omitFields={omitFields} />
<AutoFields omitFields={SchemaService.OMIT_FORM_FIELDS} />
<ErrorsField />
</AutoForm>
</AutoField.componentDetectorContext.Provider>
Expand Down
Loading
Loading