-
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
1d2998c
commit f03624e
Showing
12 changed files
with
136 additions
and
12 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
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
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; | ||
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.status = NodeStatus.warning; | ||
vizNode.statusDecoratorTooltip = message; | ||
} else { | ||
vizNode.status = NodeStatus.success; | ||
vizNode.statusDecoratorTooltip = 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
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