Skip to content

Commit 7f379ad

Browse files
authored
fix: incorrect referenceList value in refresh payload on opening dialog (#291)
* fix: incorrect referenceList value in refresh api payload on opening dialog * refactor: streamline ReferenceComponent methods and improve null handling
1 parent 5a4a6e4 commit 7f379ad

File tree

4 files changed

+79
-94
lines changed

4 files changed

+79
-94
lines changed

packages/angular-sdk-components/src/lib/_components/infra/assignment-card/assignment-card.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<div class="psdk-case-view-divider"></div>
1919

2020
<component-mapper
21+
*ngIf="arMainButtons$ && arSecondaryButtons$"
2122
name="ActionButtons"
2223
[props]="{ arMainButtons$, arSecondaryButtons$ }"
2324
[parent]="this"

packages/angular-sdk-components/src/lib/_components/infra/reference/reference.component.ts

Lines changed: 69 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,42 @@ import { Component } from '@angular/core';
1313
standalone: true
1414
})
1515
export 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
}

packages/angular-sdk-components/src/lib/_components/template/default-form/default-form.component.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,8 @@ export class DefaultFormComponent extends FormTemplateBase implements OnInit {
8686
// normalize them
8787
const children = ReferenceComponent.normalizePConnArray(kids[0].getPConnect().getChildren());
8888

89-
const visibleChildren = children.filter(child => child !== undefined);
90-
91-
if (areViewsChanged(this.arChildren$, visibleChildren)) {
92-
this.arChildren$ = visibleChildren;
89+
if (areViewsChanged(this.arChildren$, children)) {
90+
this.arChildren$ = children;
9391
}
9492
}
9593
}

packages/angular-sdk-components/src/lib/_components/template/simple-table-manual/helpers.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,20 @@ function getFieldWidth(field, label) {
4444
export const getContext = thePConn => {
4545
const contextName = thePConn.getContextName();
4646
const pageReference = thePConn.getPageReference();
47-
// 8.7 change = referenceList may now be in top-level of state props,
48-
// not always in config of state props
49-
let { referenceList } = thePConn.getStateProps()?.config || thePConn.getStateProps();
47+
const { readonlyContextList, referenceList = readonlyContextList } = thePConn.getStateProps()?.config || thePConn.getStateProps();
48+
5049
const pageReferenceForRows = referenceList.startsWith('.') ? `${pageReference}.${referenceList.substring(1)}` : referenceList;
50+
const viewName = thePConn.viewName;
5151

5252
// removing "caseInfo.content" prefix to avoid setting it as a target while preparing pageInstructions
53-
referenceList = pageReferenceForRows.replace(PCore.getConstants().CASE_INFO.CASE_INFO_CONTENT, '');
53+
// skipping the removal as StateMachine itself is removing this case info prefix while preparing pageInstructions
54+
// referenceList = pageReferenceForRows.replace(PCore.getConstants().CASE_INFO.CASE_INFO_CONTENT, '');
5455

5556
return {
5657
contextName,
5758
referenceListStr: referenceList,
58-
pageReferenceForRows
59+
pageReferenceForRows,
60+
viewName
5961
};
6062
};
6163

0 commit comments

Comments
 (0)