Skip to content

Commit 4b87949

Browse files
Show properties of a component only if allowed by schema condition (fix #762) (#798)
1 parent 278dfcd commit 4b87949

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/components/components/Component.js

+24
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,30 @@ export default class Component extends React.Component {
9494

9595
return Object.keys(componentData.schema)
9696
.sort()
97+
.filter((propertyName) => {
98+
if (!componentData.schema[propertyName].if) {
99+
return true;
100+
}
101+
let showProperty = true;
102+
for (const [conditionKey, conditionValue] of Object.entries(
103+
componentData.schema[propertyName].if
104+
)) {
105+
if (Array.isArray(conditionValue)) {
106+
if (
107+
conditionValue.indexOf(componentData.data[conditionKey]) === -1
108+
) {
109+
showProperty = false;
110+
break;
111+
}
112+
} else {
113+
if (conditionValue !== componentData.data[conditionKey]) {
114+
showProperty = false;
115+
break;
116+
}
117+
}
118+
}
119+
return showProperty;
120+
})
97121
.map((propertyName) => (
98122
<PropertyRow
99123
key={propertyName}

0 commit comments

Comments
 (0)