Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
defaultJsonFormsI18nState,
deriveLabelForUISchemaElement,
getAjv,
getConfig,
isVisible,
JsonFormsState,
Labelable,
Expand Down Expand Up @@ -87,7 +88,13 @@ export class CategorizationTabLayoutRenderer
this.hidden = !props.visible;
this.visibleCategories = this.uischema.elements.filter(
(category: Category | Categorization) =>
isVisible(category, props.data, undefined, getAjv(state))
isVisible(
category,
props.data,
undefined,
getAjv(state),
getConfig(state)
)
);
this.categoryLabels = this.visibleCategories.map((element) =>
deriveLabelForUISchemaElement(
Expand Down
9 changes: 8 additions & 1 deletion packages/angular-material/src/library/other/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import {
ControlElement,
getAjv,
getConfig,
getData,
isVisible,
JsonFormsState,
Expand All @@ -44,7 +45,13 @@ export const mapStateToVisible = (
const visible =
ownProps.visible !== undefined
? ownProps.visible
: isVisible(ownProps.uischema, getData(state), undefined, getAjv(state));
: isVisible(
ownProps.uischema,
getData(state),
undefined,
getAjv(state),
getConfig(state)
);

return {
visible,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/mappers/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ export const mapStateToCellProps = (
): StatePropsOfCell => {
const { id, schema, path, uischema, renderers, cells } = ownProps;
const rootData = getData(state);
const config = getConfig(state);
const visible =
ownProps.visible !== undefined
? ownProps.visible
: isVisible(uischema, rootData, undefined, getAjv(state));
: isVisible(uischema, rootData, undefined, getAjv(state), config);

const rootSchema = getSchema(state);
const config = getConfig(state);

/* When determining the enabled state of cells we take a shortcut: At the
* moment it's only possible to configure enablement and disablement at the
Expand Down
21 changes: 17 additions & 4 deletions packages/core/src/mappers/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,11 @@ export const mapStateToControlProps = (
const { uischema } = ownProps;
const rootData = getData(state);
const path = composeWithUi(uischema, ownProps.path);
const config = getConfig(state);

const visible: boolean =
ownProps.visible === undefined || hasShowRule(uischema)
? isVisible(uischema, rootData, ownProps.path, getAjv(state))
? isVisible(uischema, rootData, ownProps.path, getAjv(state), config)
: ownProps.visible;
const controlElement = uischema as ControlElement;
const id = ownProps.id;
Expand All @@ -604,7 +606,6 @@ export const mapStateToControlProps = (
const data = Resolve.data(rootData, path);
const labelDesc = createLabelDescriptionFrom(uischema, resolvedSchema);
const label = labelDesc.show ? labelDesc.text : '';
const config = getConfig(state);
const enabled: boolean = isInherentlyEnabled(
state,
ownProps,
Expand Down Expand Up @@ -1042,7 +1043,13 @@ export const mapStateToLayoutProps = (
const { uischema } = ownProps;
const visible: boolean =
ownProps.visible === undefined || hasShowRule(uischema)
? isVisible(ownProps.uischema, rootData, ownProps.path, getAjv(state))
? isVisible(
ownProps.uischema,
rootData,
ownProps.path,
getAjv(state),
getConfig(state)
)
: ownProps.visible;

const data = Resolve.data(rootData, ownProps.path);
Expand Down Expand Up @@ -1280,7 +1287,13 @@ export const mapStateToLabelProps = (

const visible: boolean =
props.visible === undefined || hasShowRule(uischema)
? isVisible(props.uischema, getData(state), props.path, getAjv(state))
? isVisible(
props.uischema,
getData(state),
props.path,
getAjv(state),
getConfig(state)
)
: props.visible;

const text = uischema.text;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/mappers/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const isInherentlyEnabled = (
return false;
}
if (uischema && hasEnableRule(uischema)) {
return isEnabled(uischema, rootData, ownProps?.path, getAjv(state));
return isEnabled(uischema, rootData, ownProps?.path, getAjv(state), config);
}
if (typeof uischema?.options?.readonly === 'boolean') {
return !uischema.options.readonly;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/models/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ export interface ValidateFunctionContext {
path: string | undefined;
/** The `UISchemaElement` containing the rule that uses the ValidateFunctionCondition, e.g. a `ControlElement` */
uischemaElement: UISchemaElement;
/** The form config */
config: any;
}

/**
Expand Down
35 changes: 22 additions & 13 deletions packages/core/src/util/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,19 @@ const evaluateCondition = (
uischema: UISchemaElement,
condition: Condition,
path: string,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
if (isAndCondition(condition)) {
return condition.conditions.reduce(
(acc, cur) => acc && evaluateCondition(data, uischema, cur, path, ajv),
(acc, cur) =>
acc && evaluateCondition(data, uischema, cur, path, ajv, config),
true
);
} else if (isOrCondition(condition)) {
return condition.conditions.reduce(
(acc, cur) => acc || evaluateCondition(data, uischema, cur, path, ajv),
(acc, cur) =>
acc || evaluateCondition(data, uischema, cur, path, ajv, config),
false
);
} else if (isLeafCondition(condition)) {
Expand All @@ -95,6 +98,7 @@ const evaluateCondition = (
fullData: data,
path,
uischemaElement: uischema,
config,
};
return condition.validate(context);
} else {
Expand All @@ -107,19 +111,21 @@ const isRuleFulfilled = (
uischema: UISchemaElement,
data: any,
path: string,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
const condition = uischema.rule.condition;
return evaluateCondition(data, uischema, condition, path, ajv);
return evaluateCondition(data, uischema, condition, path, ajv, config);
};

export const evalVisibility = (
uischema: UISchemaElement,
data: any,
path: string = undefined,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
const fulfilled = isRuleFulfilled(uischema, data, path, ajv, config);

switch (uischema.rule.effect) {
case RuleEffect.HIDE:
Expand All @@ -136,9 +142,10 @@ export const evalEnablement = (
uischema: UISchemaElement,
data: any,
path: string = undefined,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
const fulfilled = isRuleFulfilled(uischema, data, path, ajv);
const fulfilled = isRuleFulfilled(uischema, data, path, ajv, config);

switch (uischema.rule.effect) {
case RuleEffect.DISABLE:
Expand Down Expand Up @@ -177,10 +184,11 @@ export const isVisible = (
uischema: UISchemaElement,
data: any,
path: string = undefined,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
if (uischema.rule) {
return evalVisibility(uischema, data, path, ajv);
return evalVisibility(uischema, data, path, ajv, config);
}

return true;
Expand All @@ -190,10 +198,11 @@ export const isEnabled = (
uischema: UISchemaElement,
data: any,
path: string = undefined,
ajv: Ajv
ajv: Ajv,
config: any
): boolean => {
if (uischema.rule) {
return evalEnablement(uischema, data, path, ajv);
return evalEnablement(uischema, data, path, ajv, config);
}

return true;
Expand Down
18 changes: 14 additions & 4 deletions packages/core/src/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,20 @@ export const Paths = {

// Runtime --
export const Runtime = {
isEnabled(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
return isEnabled(uischema, data, undefined, ajv);
isEnabled(
uischema: UISchemaElement,
data: any,
ajv: Ajv,
config: any
): boolean {
return isEnabled(uischema, data, undefined, ajv, config);
},
isVisible(uischema: UISchemaElement, data: any, ajv: Ajv): boolean {
return isVisible(uischema, data, undefined, ajv);
isVisible(
uischema: UISchemaElement,
data: any,
ajv: Ajv,
config: any
): boolean {
return isVisible(uischema, data, undefined, ajv, config);
},
};
Loading