-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Indication that some of the connectors mandatory properties are…
… not yet configured Fixes: #126
- Loading branch information
1 parent
4cecbe2
commit be82583
Showing
15 changed files
with
221 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
packages/ui/src/components/Visualization/Canvas/canvas.defaults.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { NodeShape } from '@patternfly/react-topology'; | ||
import { NodeShape, NodeStatus } from '@patternfly/react-topology'; | ||
import { LayoutType } from './canvas.models'; | ||
|
||
export class CanvasDefaults { | ||
static readonly DEFAULT_LAYOUT = LayoutType.DagreVertical; | ||
static readonly DEFAULT_NODE_SHAPE = NodeShape.rect; | ||
static readonly DEFAULT_NODE_DIAMETER = 75; | ||
static readonly DEFAULT_GROUP_PADDING = 50; | ||
static DEFAULT_NODE_STATUS = NodeStatus.default; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
packages/ui/src/models/visualization/flows/support/model-validation.service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { ModelValidationService } from './model-validation.service'; | ||
import * as componentCatalogMap from '@kaoto-next/camel-catalog/camel-catalog-aggregate-components.json'; | ||
import * as modelCatalogMap from '@kaoto-next/camel-catalog/camel-catalog-aggregate-models.json'; | ||
import * as patternCatalogMap from '@kaoto-next/camel-catalog/camel-catalog-aggregate-patterns.json'; | ||
import { createVisualizationNode } from '../../visualization-node'; | ||
import { NodeStatus } from '@patternfly/react-topology'; | ||
import { CamelComponentSchemaService } from './camel-component-schema.service'; | ||
import { CamelCatalogService } from '../camel-catalog.service'; | ||
import { CatalogKind } from '../../../catalog-kind'; | ||
import { ICamelComponentDefinition } from '../../../camel-components-catalog'; | ||
import { ICamelProcessorDefinition } from '../../../camel-processors-catalog'; | ||
describe('ModelValidationService', () => { | ||
const camelRoute = { | ||
route: { | ||
id: 'route-8888', | ||
from: { | ||
uri: 'timer:tutorial', | ||
steps: [ | ||
{ | ||
to: { | ||
uri: 'activemq', | ||
parameters: {}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}; | ||
|
||
beforeAll(() => { | ||
CamelCatalogService.setCatalogKey( | ||
CatalogKind.Component, | ||
componentCatalogMap as unknown as Record<string, ICamelComponentDefinition>, | ||
); | ||
CamelCatalogService.setCatalogKey( | ||
CatalogKind.Processor, | ||
modelCatalogMap as unknown as Record<string, ICamelProcessorDefinition>, | ||
); | ||
CamelCatalogService.setCatalogKey( | ||
CatalogKind.Pattern, | ||
patternCatalogMap as unknown as Record<string, ICamelProcessorDefinition>, | ||
); | ||
}); | ||
|
||
describe('validateNodeStatus()', () => { | ||
it('should set warning status if required parameter is missing', () => { | ||
const model = camelRoute.route.from.steps[0].to; | ||
const path = 'route.from.steps[0].to'; | ||
const schema = CamelComponentSchemaService.getVisualComponentSchema(path, model); | ||
const vizNode = createVisualizationNode('dummy', {}); | ||
ModelValidationService.validateNodeStatus(schema, model, vizNode); | ||
expect(vizNode.getNodeStatus()).toEqual(NodeStatus.warning); | ||
expect(vizNode.getNodeStatusMessage()).toContain('destinationName'); | ||
}); | ||
|
||
it('should set default status if required parameter is set', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const model = { ...camelRoute.route.from.steps[0].to } as any; | ||
model.parameters['destinationName'] = 'myQueue'; | ||
const path = 'route.from.steps[0].to'; | ||
const schema = CamelComponentSchemaService.getVisualComponentSchema(path, model); | ||
const vizNode = createVisualizationNode('dummy', {}); | ||
ModelValidationService.validateNodeStatus(schema, model, vizNode); | ||
expect(vizNode.getNodeStatus()).toEqual(NodeStatus.default); | ||
expect(vizNode.getNodeStatusMessage()).toBeUndefined(); | ||
}); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
packages/ui/src/models/visualization/flows/support/model-validation.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { IVisualizationNode, VisualComponentSchema } from '../../base-visual-entity'; | ||
import { NodeStatus } from '@patternfly/react-topology'; | ||
import { JSONSchemaType } from 'ajv'; | ||
|
||
export interface IValidationResult { | ||
level: 'error' | 'warning' | 'info'; | ||
type: 'missingRequired'; | ||
parentPath: string; | ||
propertyName: string; | ||
message: string; | ||
} | ||
|
||
export class ModelValidationService { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
private static validateModel(schema: JSONSchemaType<unknown>, model: any, parentPath: string): IValidationResult[] { | ||
const answer = [] as IValidationResult[]; | ||
if (schema.properties) { | ||
Object.entries(schema.properties).forEach(([propertyName, propertyValue]) => { | ||
const propertySchema = propertyValue as JSONSchemaType<unknown>; | ||
// TODO | ||
if (propertySchema.type === 'array') return; | ||
if (propertySchema.type === 'object') { | ||
const path = parentPath ? `${parentPath}.${propertyName}` : propertyName; | ||
if (model) { | ||
answer.push(...ModelValidationService.validateModel(propertySchema, model[propertyName], path)); | ||
} | ||
return; | ||
} | ||
// check missing required parameter | ||
if ( | ||
schema.required?.includes(propertyName) && | ||
propertySchema.default === undefined && | ||
(!model || !model[propertyName]) | ||
) { | ||
answer.push({ | ||
level: 'error', | ||
type: 'missingRequired', | ||
parentPath: parentPath, | ||
propertyName: propertyName, | ||
message: `Missing required property ${propertyName}`, | ||
}); | ||
} | ||
}); | ||
} | ||
return answer; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
static validateNodeStatus(schema: VisualComponentSchema | undefined, model: any, vizNode: IVisualizationNode): void { | ||
if (!schema?.schema) return; | ||
|
||
const validationResult = ModelValidationService.validateModel(schema.schema, model, ''); | ||
const missingProperties = validationResult | ||
.filter((result) => result.type === 'missingRequired') | ||
.map((result) => result.propertyName); | ||
if (missingProperties.length > 0) { | ||
const message = | ||
missingProperties.length > 1 | ||
? `${missingProperties.length} required properties are not yet configured: [ ${missingProperties} ]` | ||
: `1 required property is not yet configured: [ ${missingProperties} ]`; | ||
vizNode.setNodeStatus(NodeStatus.warning, message); | ||
} else { | ||
vizNode.setNodeStatus(NodeStatus.default, undefined); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.