@@ -97,7 +97,7 @@ export class ViewComponent extends ContainerBaseComponent {
9797 * component is able to handle it.
9898 */
9999 if ( ! configProps . visibility && this . pConn . getPageReference ( ) . length > "caseInfo.content" . length ) {
100- this . props . visible = this . #evaluateVisibility( this . pConn , configProps . referenceContext ) ;
100+ this . props . visible = this . #evaluateVisibility( this . pConn , configProps ) ;
101101 }
102102
103103 if ( this . SUPPORTED_TEMPLATES . includes ( template ) ) {
@@ -124,21 +124,22 @@ export class ViewComponent extends ContainerBaseComponent {
124124 }
125125 }
126126
127- #evaluateVisibility( pConn , referenceContext ) {
127+ #evaluateVisibility( pConn , configProps ) {
128128 const visibilityExpression = pConn . meta . config . visibility ;
129129 if ( ! visibilityExpression || visibilityExpression . length === 0 ) return true ;
130130 const contextName = pConn . getContextName ( ) ;
131131 if ( visibilityExpression . startsWith ( "@E " ) ) {
132- return this . #evaluateExpressionVisibility( contextName , referenceContext , visibilityExpression ) ;
133- } else if ( visibilityExpression . startsWith ( "@W " ) ) {
134- return this . #evaluateWhenVisibility( contextName , visibilityExpression ) ;
132+ return this . #evaluateVisibilityExpression( contextName , configProps . referenceContext , visibilityExpression ) ;
133+ } else if ( visibilityExpression . startsWith ( "@W " ) ) {
134+ // when rules does not need special handling
135+ return configProps . visibility
135136 } else {
136137 console . warn ( TAG , `Unsupported visibility expression: ${ visibilityExpression } . Defaulting to visible.` ) ;
137138 return true ;
138139 }
139140 }
140141
141- #evaluateExpressionVisibility ( contextName , referenceContext , visibilityExpression ) {
142+ #evaluateVisibilityExpression ( contextName , referenceContext , visibilityExpression ) {
142143 let dataPage = this . #getDataPage( contextName , referenceContext ) ;
143144 if ( ! dataPage ) return false ;
144145
@@ -152,38 +153,6 @@ export class ViewComponent extends ContainerBaseComponent {
152153 } ) ;
153154 }
154155
155- #evaluateWhenVisibility( contextName , visibilityExpression ) {
156- let bVisibility = true ;
157- // e.g. "@E .EmbeddedData_SelectedTestName == 'Readonly' && .EmbeddedData_SelectedSubCategory == 'Mode'"
158- const aVisibility = visibilityExpression . split ( '&&' ) ;
159- // e.g. ["EmbeddedData_SelectedTestName": "Readonly", "EmbeddedData_SelectedSubCategory": "Mode"]
160- // Reading values from the Store to evaluate the visibility expressions
161- const storeData = PCore . getStore ( ) . getState ( ) ?. data [ contextName ] . caseInfo . content ;
162-
163- const initialVal = { } ;
164- const oProperties = aVisibility . reduce ( ( properties , property ) => {
165- const keyStartIndex = property . indexOf ( '.' ) ;
166- const keyEndIndex = property . indexOf ( '=' ) - 1 ;
167- const valueStartIndex = property . indexOf ( "'" ) ;
168- const valueEndIndex = property . lastIndexOf ( "'" ) - 1 ;
169- return {
170- ...properties ,
171- [ property . substr ( keyStartIndex + 1 , keyEndIndex - keyStartIndex - 1 ) ] : property . substr ( valueStartIndex + 1 , valueEndIndex - valueStartIndex )
172- } ;
173- } , initialVal ) ;
174-
175- const propertyKeys = Object . keys ( oProperties ) ;
176- const propertyValues = Object . values ( oProperties ) ;
177-
178- for ( let propertyIndex = 0 ; propertyIndex < propertyKeys . length ; propertyIndex ++ ) {
179- if ( storeData [ propertyKeys [ propertyIndex ] ] !== propertyValues [ propertyIndex ] ) {
180- bVisibility = false ;
181- }
182- }
183-
184- return bVisibility ;
185- }
186-
187156 #getDataPage( context , referenceContext ) {
188157 let pageReferenceKeys = referenceContext . replace ( "caseInfo.content." , "" ) . split ( "." ) ;
189158 let page = PCore . getStore ( ) . getState ( ) ?. data [ context ] . caseInfo . content ;
0 commit comments