-
Notifications
You must be signed in to change notification settings - Fork 391
feat(core): Add validate function based rule condition #2441
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
base: master
Are you sure you want to change the base?
Conversation
Add a new rule condition `ValidateFunctionCondition` using a given `validate` function to evaluate the condition result. This allows using arbitrary custom logic to evaluate condition results. This facilitates not using schema-conditions to be able to only use one pre-compiled AJV for the data schema at a later stage.
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
packages/core/src/models/uischema.ts
Outdated
* | ||
* @param data The data as resolved via the scope. | ||
* @returns `true` if the condition is fulfilled */ | ||
validate: (data: unknown) => boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should hand in much more data here, i.e. whatever we have available at call time.
For example
validate: (data: unknown) => boolean; | |
validate: (rule: { | |
data: unknown; | |
fullData: unknown; | |
schema: JSONSchema, | |
rootSchema: JSONSchema, | |
uischema: UISchemaElement, | |
path: string; // or string[] | |
// etc. | |
}) => boolean; |
Not sure about the naming, just as an idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, I agree with your sentiment. However, we do not have that much available without breaking the public API:
The evaluateCondition
method has these parameters:
data: any, // This is the full data
condition: Condition,
path: string,
ajv: Ajv
Tracing upwards in the call history to the first publicly exposed methods using this - evalVisibility
and evalEnablement
- they have these parameters available (the same is true for isVisible
and isEnabled
):
uischema: UISchemaElement, // ui schema element containing the rule
data: any, // full data
path: string = undefined, // Optional instance path for nested controls
ajv: Ajv
Thus, without breaking the API of there we could additionally hand in:
- the UISchemaElement containing the condition
- the full data
- the optional instance path for nested controls
I omitted handing in the full data because this can be covered by using the root scope #
. Thinking about it again, this is then only the nested root data.
Thus, I suggest handing in the three listed properties in addition to the scoped data. I'd like to avoid breaking the API. WDYT?
@sdirix I now added the additional context information being available without breaking API as described here: #2441 (comment) |
Add a new rule condition
ValidateFunctionCondition
using a givenvalidate
function to evaluate the condition result. This allows using arbitrary custom logic to evaluate condition results.This facilitates not using schema-conditions to be able to only use one pre-compiled AJV for the data schema at a later stage.