@@ -13,49 +13,42 @@ import { Component } from '@angular/core';
1313 standalone : true
1414} )
1515export class ReferenceComponent {
16- referencedComponent : any = null ;
17-
1816 /* Used to toggle some class-wide logging */
1917 private static bLogging = false ;
2018
21- constructor ( ) {
22- // With new static method approach, this shouldn't be called any more
23- window . alert ( `in ReferenceComponent constructor!` ) ;
24-
25- console . error ( `in ReferenceComponent constructor!` ) ;
26- }
27-
28- // onStateChange and updateSelf methods removed from original implementation
29- // when we moved to the static method implementation.
30-
31- // STATIC method to create a normalized PConn (a fully realized View that the 'reference'
32- // component refers to) from the given pConn. Has to add in some stuff as in the constructor
33- static createFullReferencedViewFromRef ( inPConn : any ) {
34- // BAIL and ERROR if inPConn is NOT a reference!
19+ /**
20+ * Creates a normalized PConn from a reference component.
21+ * Resolves the reference to its fully realized View with proper configuration.
22+ *
23+ * @param inPConn - The PConn object that represents a reference component
24+ * @returns The dereferenced PConnect object, or null if reference can't be resolved
25+ */
26+ static createFullReferencedViewFromRef ( inPConn : any ) : any {
27+ // Validate that inPConn is a reference component
3528 if ( inPConn . getComponentName ( ) !== 'reference' ) {
3629 console . error ( `Reference component: createFullReferencedViewFromRef inPConn is NOT a reference! ${ inPConn . getComponentName ( ) } ` ) ;
30+ return null ;
3731 }
3832
33+ // Get reference configuration and make a copy
3934 const referenceConfig = { ...inPConn . getComponentConfig ( ) } ;
4035
41- // Since SDK-A implements Reference as static methods and we don't rely on
42- // the Reference component's handling of the visibility prop, we leave it in
43- // (and also leaving the others in for now) so the referenced View can act on
44- // the visibility prop. (The following 3 lines were carried over from React SDK)
36+ // Remove properties that should not be inherited by the referenced view
37+ // (Maintained from React SDK implementation)
4538 delete referenceConfig ?. name ;
4639 delete referenceConfig ?. type ;
4740 delete referenceConfig ?. visibility ;
4841
42+ // Get the metadata for the referenced view
4943 const viewMetadata = inPConn . getReferencedView ( ) ;
5044
45+ // Return null if view metadata is not found
5146 if ( ! viewMetadata ) {
5247 console . log ( 'View not found ' , inPConn . getComponentConfig ( ) ) ;
5348 return null ;
5449 }
5550
56- // If we get here, we have metadata for a View component...
57- // const referencedComponentName = viewMetadata.type;
58-
51+ // Create the view object by merging metadata with reference config
5952 const viewObject = {
6053 ...viewMetadata ,
6154 config : {
@@ -64,26 +57,31 @@ export class ReferenceComponent {
6457 }
6558 } ;
6659
67- const theResolvedConfigProps = inPConn . resolveConfigProps ( inPConn . getConfigProps ( ) ) ;
68- const { visibility = true , context, readOnly = false , displayMode = '' } = theResolvedConfigProps ;
60+ // Resolve configuration properties
61+ const resolvedConfigProps = inPConn . resolveConfigProps ( inPConn . getConfigProps ( ) ) ;
62+ const { visibility = true , context, readOnly = false , displayMode = '' } = resolvedConfigProps ;
6963
64+ // Log debug information if logging is enabled
7065 if ( ReferenceComponent . bLogging ) {
7166 console . log ( `Reference: about to call createComponent with pageReference: context: ${ inPConn . getContextName ( ) } ` ) ;
7267 }
7368
69+ // Create the component with the right context
7470 const viewComponent = inPConn . createComponent ( viewObject , null , null , {
7571 pageReference : context && context . startsWith ( '@CLASS' ) ? '' : context
7672 } ) ;
7773
78- // updating the referencedComponent should trigger a render
74+ // Get the PConnect object from the created component
7975 const newCompPConnect = viewComponent . getPConnect ( ) ;
8076
77+ // Set inherited configuration on the new component
8178 newCompPConnect . setInheritedConfig ( {
8279 ...referenceConfig ,
8380 readOnly,
8481 displayMode
8582 } ) ;
8683
84+ // Log debug information if logging is enabled
8785 if ( ReferenceComponent . bLogging ) {
8886 console . log (
8987 `Angular Reference component: createFullReferencedViewFromRef -> newCompPConnect configProps: ${ JSON . stringify (
@@ -92,77 +90,63 @@ export class ReferenceComponent {
9290 ) ;
9391 }
9492
95- if ( visibility !== false ) {
96- return newCompPConnect ;
97- }
98-
99- return null ;
93+ // Return the component if it should be visible, otherwise null
94+ return visibility !== false ? newCompPConnect : null ;
10095 }
10196
102- // STATIC method that other components can call to normalize
103- // a pConn object that might be a 'reference'. If the incoming
104- // pConn is a reference, return its dereferenced View PConnect's
105- // getPConnect. Otherwise, return the passed in pConn unchanged
106- // inPConn = a PConn object (ex: { getPConnect()} )
107- static normalizePConn ( inPConn : any ) {
108- // debugger;
109-
110- let returnObj = false ;
111- let thePConnType = '' ;
112-
113- if ( inPConn . getPConnect ) {
114- // inPConn is an object (ex: { getPConnect()} ), so we want to return
115- // any referenced view as the object containing the
116- // the getPConnect function
117- returnObj = true ;
118- thePConnType = inPConn . getPConnect ( ) . getComponentName ( ) ;
119- } else {
120- // inPConn is an object with the PConnect function, so we want
121- // to return any referenced view as the object containing the
122- // the c11n function
123- returnObj = false ;
124- thePConnType = inPConn . getComponentName ( ) ;
97+ /**
98+ * Normalizes a PConn object that might be a 'reference'.
99+ * If the incoming PConn is a reference, returns its dereferenced View.
100+ * Otherwise, returns the passed in PConn unchanged.
101+ *
102+ * @param inPConn - A PConn object (ex: { getPConnect() } or direct PConnect)
103+ * @returns The normalized PConn object with references resolved
104+ */
105+ static normalizePConn ( inPConn : any ) : any {
106+ // Early return for null or undefined input
107+ if ( ! inPConn ) {
108+ return inPConn ;
125109 }
126110
127- if ( thePConnType === 'reference' ) {
128- if ( returnObj ) {
129- // WAS...
130- // const theRefViewPConn = inPConn.getPConnect().getReferencedViewPConnect(true);
131- // Now: ALWAYS calling createFullReferencedViewFromRef to have options, PageReference, etc.
132- // set correctly in the C11nEnv (PConnect) object
133- // debugger;
134- let theRefViewPConn = this . createFullReferencedViewFromRef ( inPConn . getPConnect ( ) ) ;
135- // now return its PConnect
136- theRefViewPConn = theRefViewPConn ?. getComponent ( ) ;
137-
138- // const theFullReference = theRefViewPConn.getPConnect().getFullReference();
139- // console.log(`theFullReference: ${theFullReference}`);
140-
141- return theRefViewPConn ;
111+ // Determine if we have an object with getPConnect method or direct PConnect
112+ const hasGetPConnectMethod = ! ! inPConn . getPConnect ;
113+
114+ // Get the component name in the appropriate way based on the object type
115+ const componentName = hasGetPConnectMethod ? inPConn . getPConnect ( ) . getComponentName ( ) : inPConn . getComponentName ( ) ;
116+
117+ // Only process if this is a reference component
118+ if ( componentName === 'reference' ) {
119+ if ( hasGetPConnectMethod ) {
120+ // For objects with getPConnect method, get the referenced view and its component
121+ const refViewPConn = this . createFullReferencedViewFromRef ( inPConn . getPConnect ( ) ) ;
122+ return refViewPConn ?. getComponent ( ) ;
142123 }
143- // console.log(`created theFullRefView full reference: ${theFullRefView.getFullReference()}`);
144- // debugger;
145124
125+ // For direct PConnect objects, just create the referenced view
146126 return this . createFullReferencedViewFromRef ( inPConn ) ;
147127 }
128+
129+ // Not a reference component, return unchanged
148130 return inPConn ;
149131 }
150132
151- // STATIC method that other components can call to normalize
152- // an array of pConn objects where any of the children might
153- // be a 'reference'. The array returns an array of children
154- // where any 'reference' is replaced with its ReferencedView
155- // inPConnArray is an array of PConn objects or functions.
156- // Its value is passed to normalizePConn
157-
158- static normalizePConnArray ( inPConnArray : any ) {
159- if ( ! ( inPConnArray ?. length > 0 ) ) {
160- // null or empty array, return what was passed in
161- return inPConnArray ;
133+ /**
134+ * Normalizes an array of PConn objects by replacing any 'reference' components
135+ * with their referenced views.
136+ *
137+ * @param inPConnArray - Array of PConn objects to normalize
138+ * @returns Normalized array with references resolved, or empty array if input is invalid
139+ */
140+ static normalizePConnArray ( inPConnArray : any [ ] ) : any [ ] {
141+ // Handle null, undefined, or empty array case
142+ if ( ! inPConnArray ?. length ) {
143+ return inPConnArray || [ ] ;
162144 }
163145
164- return inPConnArray . map ( child => {
165- return ReferenceComponent . normalizePConn ( child ) ;
166- } ) ;
146+ // Process array: normalize each item and filter out any null/undefined results
147+ const normalizedArray = inPConnArray . map ( child => ReferenceComponent . normalizePConn ( child ) ) . filter ( Boolean ) ;
148+
149+ // Ensure we always return an array (even if filter removes all items)
150+ return normalizedArray || [ ] ;
167151 }
168152}
0 commit comments