mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
add module validator
This commit is contained in:
parent
c56de04500
commit
50614ab04a
@ -42,4 +42,33 @@ class ComponentPropertyValidatorRule implements ComponentValidatorRule {
|
||||
return results;
|
||||
}
|
||||
}
|
||||
export const ComponentRules = [new ComponentPropertyValidatorRule()];
|
||||
|
||||
class ModuleValidatorRule implements ComponentValidatorRule {
|
||||
kind: 'component' = 'component';
|
||||
|
||||
validate({ component, registry }: ComponentValidateContext): ValidateErrorResult[] {
|
||||
if (component.type !== 'core/v1/moduleContainer') {
|
||||
return [];
|
||||
}
|
||||
|
||||
const results: ValidateErrorResult[] = [];
|
||||
let moduleSpec
|
||||
try {
|
||||
moduleSpec = registry.getModuleByType(component.properties.type as string);
|
||||
} catch (err) {
|
||||
moduleSpec = undefined
|
||||
}
|
||||
if (!moduleSpec) {
|
||||
results.push({
|
||||
message: `Module is not registered: ${component.properties.type}.`,
|
||||
componentId: component.id,
|
||||
property: '/type',
|
||||
});
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
export const ComponentRules = [
|
||||
new ComponentPropertyValidatorRule(),
|
||||
new ModuleValidatorRule(),
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user