Skip to content

Commit c74bef9

Browse files
ISSUE-139957: fixing when rules in views inside embedded data
1 parent 146d46f commit c74bef9

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

scripts/dxcomponents/components/containers/view.component.js

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,19 @@ export class ViewComponent extends ContainerBaseComponent {
123123
#evaluateVisibility(pConn, referenceContext) {
124124
const visibilityExpression = pConn.meta.config.visibility;
125125
if (!visibilityExpression || visibilityExpression.length === 0) return true;
126+
const contextName = pConn.getContextName();
127+
if (visibilityExpression.startsWith("@E ")) {
128+
return this.#evaluateExpressionVisibility(contextName, referenceContext, visibilityExpression);
129+
} else if(visibilityExpression.startsWith("@W ")) {
130+
return this.#evaluateWhenVisibility(contextName, visibilityExpression);
131+
} else {
132+
console.warn(TAG, `Unsupported visibility expression: ${visibilityExpression}. Defaulting to visible.`);
133+
return true;
134+
}
135+
}
126136

127-
let dataPage = this.#getDataPage(pConn.getContextName(), referenceContext);
137+
#evaluateExpressionVisibility(contextName, referenceContext, visibilityExpression) {
138+
let dataPage = this.#getDataPage(contextName, referenceContext);
128139
if (!dataPage) return false;
129140

130141
const visibilityConditions = visibilityExpression.replace("@E ", "");
@@ -137,6 +148,38 @@ export class ViewComponent extends ContainerBaseComponent {
137148
});
138149
}
139150

151+
#evaluateWhenVisibility(contextName, visibilityExpression) {
152+
let bVisibility = true;
153+
// e.g. "@E .EmbeddedData_SelectedTestName == 'Readonly' && .EmbeddedData_SelectedSubCategory == 'Mode'"
154+
const aVisibility = visibilityExpression.split('&&');
155+
// e.g. ["EmbeddedData_SelectedTestName": "Readonly", "EmbeddedData_SelectedSubCategory": "Mode"]
156+
// Reading values from the Store to evaluate the visibility expressions
157+
const storeData = PCore.getStore().getState()?.data[contextName].caseInfo.content;
158+
159+
const initialVal = {};
160+
const oProperties = aVisibility.reduce((properties, property) => {
161+
const keyStartIndex = property.indexOf('.');
162+
const keyEndIndex = property.indexOf('=') - 1;
163+
const valueStartIndex = property.indexOf("'");
164+
const valueEndIndex = property.lastIndexOf("'") - 1;
165+
return {
166+
...properties,
167+
[property.substr(keyStartIndex + 1, keyEndIndex - keyStartIndex - 1)]: property.substr(valueStartIndex + 1, valueEndIndex - valueStartIndex)
168+
};
169+
}, initialVal);
170+
171+
const propertyKeys = Object.keys(oProperties);
172+
const propertyValues = Object.values(oProperties);
173+
174+
for (let propertyIndex = 0; propertyIndex < propertyKeys.length; propertyIndex++) {
175+
if (storeData[propertyKeys[propertyIndex]] !== propertyValues[propertyIndex]) {
176+
bVisibility = false;
177+
}
178+
}
179+
180+
return bVisibility;
181+
}
182+
140183
#getDataPage(context, referenceContext) {
141184
let pageReferenceKeys = referenceContext.replace("caseInfo.content.", "").split(".");
142185
let page = PCore.getStore().getState()?.data[context].caseInfo.content;

0 commit comments

Comments
 (0)