Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
aahei committed Jun 16, 2023
1 parent 6a5c466 commit c0d933e
Showing 1 changed file with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,11 @@ export class OperatorPropertyEditFrameComponent implements OnInit, OnChanges, On
mappedField.validators.checkAttributeType = {
expression: (control: AbstractControl, field: FormlyFieldConfig) => {
if (
!(isDefined(this.currentOperatorId) && isDefined(mapSource.attributeTypeRules) && isDefined(mapSource.properties))
!(
isDefined(this.currentOperatorId) &&
isDefined(mapSource.attributeTypeRules) &&
isDefined(mapSource.properties)
)
) {
return true;
}
Expand Down Expand Up @@ -523,7 +527,10 @@ export class OperatorPropertyEditFrameComponent implements OnInit, OnChanges, On
}
};

const checkConstConstraint = (inputAttributeType: AttributeType, constConstraint: AttributeTypeConstRule) => {
const checkConstConstraint = (
inputAttributeType: AttributeType,
constConstraint: AttributeTypeConstRule
) => {
const data = constConstraint?.$data;
if (!isDefined(data)) {
return;
Expand All @@ -540,7 +547,10 @@ export class OperatorPropertyEditFrameComponent implements OnInit, OnChanges, On
}
};

const checkAllOfConstraint = (inputAttributeType: AttributeType, allOfConstraint: AttributeTypeAllOfRule) => {
const checkAllOfConstraint = (
inputAttributeType: AttributeType,
allOfConstraint: AttributeTypeAllOfRule
) => {
// traverse through all "if-then" sets in "allOf" constraint
for (const allOf of allOfConstraint) {
// Only return false when "if" condition is satisfied but "then" condition is not satisfied
Expand All @@ -558,13 +568,13 @@ export class OperatorPropertyEditFrameComponent implements OnInit, OnChanges, On
// add more to the condition if needed
if (ifCondSatisfied && isDefined(allOf.then.enum)) {
try {
checkEnumConstraint(inputAttributeType, allOf.then.enum);
checkEnumConstraint(inputAttributeType, allOf.then.enum);
} catch {
// parse if condition to readable string
const ifCondStr = Object.entries(allOf.if)
.map(([ifProp]) => `'${ifProp}' is ${control.value[ifProp]}`)
.join(" and ");
throw TypeError(`it's expected to be ${allOf.then.enum?.join(" or ")}, given that ${ifCondStr}`);
// parse if condition to readable string
const ifCondStr = Object.entries(allOf.if)
.map(([ifProp]) => `'${ifProp}' is ${control.value[ifProp]}`)
.join(" and ");
throw TypeError(`it's expected to be ${allOf.then.enum?.join(" or ")}, given that ${ifCondStr}`);
}
}
}
Expand Down

0 comments on commit c0d933e

Please sign in to comment.